From ffbb23bc6ded6d95fced0c0ca8ee5232770da464 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 18 Jun 2019 15:08:09 -0700 Subject: [PATCH] Always use credentials in forward merge script Closes gh-17257 --- git/hooks/forward-merge | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/git/hooks/forward-merge b/git/hooks/forward-merge index 764511f983f4..2d0a3b199b6d 100755 --- a/git/hooks/forward-merge +++ b/git/hooks/forward-merge @@ -20,16 +20,22 @@ 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 @@ -37,11 +43,12 @@ def find_milestone(repository, title) 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}" @@ -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")