Skip to content

Commit

Permalink
Merge pull request ericduran#53 from nlisgo/hotfix/improve-targeting-…
Browse files Browse the repository at this point in the history
…reverts

Improve targeting of reverted commits
  • Loading branch information
lewisnyman committed Mar 20, 2015
2 parents 0a4d2b4 + a70896f commit 41ee6f3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/bin/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@
contributors = Hash.new(0)
commits = Array.new
reverts = Array.new
issue_regexp = Regexp.new '#[0-9]+'
reverts_regexp = Regexp.new '^Revert \"(?<credits>.+#[0-9]+.* by [^:]+:).*'
reverts_regexp_loose = Regexp.new '^Revert .*(?<issue>#[0-9]+).*'

%x[#{git_command}].split("\n").each do |c|
if c.index('Revert') == 0 then
reverts.push(c.scan(/#([0-9]+)/))
if c =~ reverts_regexp then
reverts.push(c[reverts_regexp, "credits"])
elsif c =~ reverts_regexp_loose then
reverts.push(c[reverts_regexp_loose, "issue"])
else
commits.push(c)
end
end

commits.each_with_index do |c, i|
if r = reverts.index{ |item| item == c.scan(/#([0-9]+)/) }
if r = reverts.index{ |item| c.index(item) == 0 }
commits.delete_at(i)
reverts.delete_at(r)
end
end

commits.to_enum.with_index.reverse_each do |c, i|
if r = reverts.index{ |item| item[issue_regexp] == c[issue_regexp] }
commits.delete_at(i)
reverts.delete_at(r)
end
Expand Down

0 comments on commit 41ee6f3

Please sign in to comment.