Skip to content

Instantly share code, notes, and snippets.

@bitprophet
Created September 15, 2013 02:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitprophet/6567467 to your computer and use it in GitHub Desktop.
Save bitprophet/6567467 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Parse changelogs per branch
changelogs = {}
# Start at 1.2 because we don't have 1.1.0 in the new format. NBD, 1.1 is old
# as shit anyway.
releases = 2.upto(7).map {|x| "1.#{x}"}
target = /\* :(?<type>feature|bug|support|release):`((?<issue_no>\d+)|(?<release_no>\S+) <[^>]+>)`/
releases.each do |x|
changelogs[x] = `git show origin/#{x}:docs/changelog.rst`.split(/\n/).map do |line|
target.match(line)
end.compact
end
# Helper
def previous_number(number)
parts = number.split('.')
[parts[0], parts[1].to_i.pred.to_s].join('.')
end
# Capture for deduping & printing
backports = []
major_bugs = []
# Discover backports/major bugs
changelogs.each do |number, items|
release_i = items.find_index {|x| x[:release_no] == "#{number}.0"}
# Feature or Support items released in bugfix releases: 'backported'
# * Found in a branch's copy of the changelog, higher up than that branch's .0
# release
items[0..release_i].each do |item|
if !backports.include?(item) && %w(feature support).include?(item[:type])
backports << item
end
end
# Bugs released in feature releases: 'major'
# * Found in a branch's changelog in a .0 release, is type 'bug'
# * a .0 release for a branch is defined as items found in that branch prior
# to the .0 release _line_, and not found in the previous branch.
items[release_i..-1].each do |item|
is_candidate = !major_bugs.include?(item) && item[:type] == 'bug'
only_here = !changelogs.fetch(previous_number(number), []).include?(item)
major_bugs << item if is_candidate && only_here
end
end
# Print
backports.each do |item|
puts "[backported] #{item[:type]} #{item[:issue_no]}"
end
major_bugs.each do |item|
puts "[major] #{item[:type]} #{item[:issue_no]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment