Skip to content

Commit

Permalink
Merge pull request #1 from shirakia/feature/update_merge_pr_body
Browse files Browse the repository at this point in the history
Update merge_pr_body to handle new PR merges
  • Loading branch information
shirakia authored Jul 24, 2018
2 parents 4fd17a4 + 77ce0ea commit cb5c3fb
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions bin/git-pr-release
Original file line number Diff line number Diff line change
Expand Up @@ -152,36 +152,13 @@ end
def merge_pr_body(old_body, new_body)
# Try to take over checklist statuses
pr_body_lines = []
old_body_lines = old_body.split(/\r?\n/)
new_body_lines = new_body.split(/\r?\n/)

Diff::LCS.traverse_balanced(old_body.split(/\r?\n/), new_body.split(/\r?\n/)) do |event|
say "diff: #{event.inspect}", :trace
action, old, new = *event
old_nr, old_line = *old
new_nr, new_line = *new

case action
when '=', '+'
say "Use line as is: #{new_line}", :trace
pr_body_lines << new_line
when '-'
say "Use old line: #{old_line}", :trace
pr_body_lines << old_line
when '!'
if [ old_line, new_line ].all? { |line| /^- \[[ x]\]/ === line }
say "Found checklist diff; use old one: #{old_line}", :trace
pr_body_lines << old_line
else
# not a checklist diff, use both line
say "Use line as is: #{old_line}", :trace
pr_body_lines << old_line
additional_body_lines = new_body_lines - old_body_lines

say "Use line as is: #{new_line}", :trace
pr_body_lines << new_line
end
else
say "Unknown diff event: #{event}", :warn
end
end
sepalator = ['', '## Additional PRs', '']
pr_body_lines = old_body_lines + sepalator + additional_body_lines

pr_body_lines.join("\n")
end
Expand Down

0 comments on commit cb5c3fb

Please sign in to comment.