Skip to content

Commit

Permalink
Merge branch '2.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Jun 18, 2019
2 parents d85a69a + ffbb23b commit eddbfb3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions git/hooks/forward-merge
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,35 @@ def find_forward_merge(message_file)
message.each_line do |line|
match = /^(?:Fixes|Closes) gh-(\d+) in ([\d\.]+(?:(?:M|RC)\d)?)$/.match(line)
if match then
issue = match[1]
milestone = match[2]
return ForwardMerge.new(issue, milestone, message, line)
issue = match[1]
milestone = match[2]
return ForwardMerge.new(issue, milestone, message, line)
end
end
return nil
end

def find_milestone(repository, title)
milestones = JSON.parse(Net::HTTP.get(URI("https://api.github.com/repos/#{repository}/milestones")))
def find_milestone(username, password, repository, title)
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|
return milestone['number'] if milestone['title'] == title
end
puts "Milestone #{title} not found"
exit 1
end

def get_issue(repository, number)
def get_issue(username, password, repository, number)
uri = URI("https://api.github.com/repos/#{repository}/issues/#{number}")
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)
return JSON.parse(response.body) unless response.code != '200'
puts "Failed to retrieve issue #{number}: #{response.message}"
Expand Down Expand Up @@ -72,16 +79,16 @@ end
message_file=ARGV[0]
forward_merge = find_forward_merge(message_file)
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'))
username = config['github']['credentials']['username']
password = config['github']['credentials']['password']
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)
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")
Expand Down

0 comments on commit eddbfb3

Please sign in to comment.