Merge branch '2.1.x'

Closes gh-17258
pull/17271/head
Phillip Webb 5 years ago
commit eddbfb34f7

@ -20,16 +20,22 @@ def find_forward_merge(message_file)
message.each_line do |line| message.each_line do |line|
match = /^(?:Fixes|Closes) gh-(\d+) in ([\d\.]+(?:(?:M|RC)\d)?)$/.match(line) match = /^(?:Fixes|Closes) gh-(\d+) in ([\d\.]+(?:(?:M|RC)\d)?)$/.match(line)
if match then if match then
issue = match[1] issue = match[1]
milestone = match[2] milestone = match[2]
return ForwardMerge.new(issue, milestone, message, line) return ForwardMerge.new(issue, milestone, message, line)
end end
end end
return nil return nil
end end
def find_milestone(repository, title) def find_milestone(username, password, repository, title)
milestones = JSON.parse(Net::HTTP.get(URI("https://api.github.com/repos/#{repository}/milestones"))) uri = URI("https://api.github.com/repos/#{repository}/milestones")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl=true
request = Net::HTTP::Get.new(uri.path)
request.basic_auth(username, password)
response = http.request(request)
milestones = JSON.parse(response.body)
milestones.each do |milestone| milestones.each do |milestone|
return milestone['number'] if milestone['title'] == title return milestone['number'] if milestone['title'] == title
end end
@ -37,11 +43,12 @@ def find_milestone(repository, title)
exit 1 exit 1
end end
def get_issue(repository, number) def get_issue(username, password, repository, number)
uri = URI("https://api.github.com/repos/#{repository}/issues/#{number}") uri = URI("https://api.github.com/repos/#{repository}/issues/#{number}")
http = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl=true http.use_ssl=true
request = Net::HTTP::Get.new(uri.path) request = Net::HTTP::Get.new(uri.path)
request.basic_auth(username, password)
response = http.request(request) response = http.request(request)
return JSON.parse(response.body) unless response.code != '200' return JSON.parse(response.body) unless response.code != '200'
puts "Failed to retrieve issue #{number}: #{response.message}" puts "Failed to retrieve issue #{number}: #{response.message}"
@ -72,16 +79,16 @@ end
message_file=ARGV[0] message_file=ARGV[0]
forward_merge = find_forward_merge(message_file) forward_merge = find_forward_merge(message_file)
exit 0 unless forward_merge exit 0 unless forward_merge
repository = 'spring-projects/spring-boot'
existing_issue = get_issue(repository, forward_merge.issue)
title = existing_issue['title']
labels = existing_issue['labels'].map { |label| label['name'] }
labels << "status: forward-port"
milestone = find_milestone(repository, forward_merge.milestone)
config = YAML.load_file(File.join(Dir.home, '.spring-boot', 'forward-merge.yml')) config = YAML.load_file(File.join(Dir.home, '.spring-boot', 'forward-merge.yml'))
username = config['github']['credentials']['username'] username = config['github']['credentials']['username']
password = config['github']['credentials']['password'] password = config['github']['credentials']['password']
dry_run = config['dry_run'] dry_run = config['dry_run']
repository = 'spring-projects/spring-boot'
existing_issue = get_issue(username, password, repository, forward_merge.issue)
title = existing_issue['title']
labels = existing_issue['labels'].map { |label| label['name'] }
labels << "status: forward-port"
milestone = find_milestone(username, password, repository, forward_merge.milestone)
new_issue_number = create_issue(username, password, repository, forward_merge.issue, title, labels, milestone, forward_merge.milestone, dry_run) new_issue_number = create_issue(username, password, repository, forward_merge.issue, title, labels, milestone, forward_merge.milestone, dry_run)
puts "Created gh-#{new_issue_number} for forward port of gh-#{forward_merge.issue} into #{forward_merge.milestone}" puts "Created gh-#{new_issue_number} for forward port of gh-#{forward_merge.issue} into #{forward_merge.milestone}"
rewritten_message = forward_merge.message.sub(forward_merge.line, "Closes gh-#{new_issue_number}\n") rewritten_message = forward_merge.message.sub(forward_merge.line, "Closes gh-#{new_issue_number}\n")

Loading…
Cancel
Save