From e5ec6dfef024f51759be8724b6846cad0863adef Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Wed, 15 Jul 2020 17:04:34 -0500 Subject: [PATCH] Find nearest milestone for forward merge with .x pattern Fixes gh-22350 --- git/hooks/forward-merge | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/git/hooks/forward-merge b/git/hooks/forward-merge index c5f78c1b95..6877ff9d58 100755 --- a/git/hooks/forward-merge +++ b/git/hooks/forward-merge @@ -62,16 +62,17 @@ def find_milestone(username, password, repository, title) milestones = JSON.parse(response.body) if title.end_with?(".x") prefix = title.delete_suffix('.x') - $log.debug "Finding latest milestone from candidates starting with #{prefix}" + $log.debug "Finding nearest milestone from candidates starting with #{prefix}" titles = milestones.map { |milestone| milestone['title'] } titles = titles.select{ |title| title.start_with?(prefix) unless title.end_with?('.x')} - titles.sort_by { |v| Gem::Version.new(v) } + titles = titles.sort_by { |v| Gem::Version.new(v) } + $log.debug "Considering candidates #{titles}" if(titles.empty?) - puts "Cannot find latest for milestone #{title}" + puts "Cannot find nearest milestone for prefix #{title}" exit 1 end - title = titles.last - $log.debug "Found latest milestone #{title}" + title = titles.first + $log.debug "Found nearest milestone #{title}" end milestones.each do |milestone| $log.debug "Considering #{milestone['title']}"