Skip to content

Commit

Permalink
Prevent accidental removal of headers when amending a commit (ros-inf…
Browse files Browse the repository at this point in the history
…rastructure#228)

superflore currently generates commit messages that contain lines
starting with the markdown header indicator "#". However, commit message
lines that start with "#" are considered comments when amending a commit
and are removed unless the user remembers to quote them. Prevent these
lines from accidentally being removed by using the alternate form of
header indication: a line starting with "="-s or "-"-s underneath the
header text.
  • Loading branch information
herb-kuta-lge committed Nov 15, 2019
1 parent 9e525c7 commit 53fc43c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 8 additions & 4 deletions superflore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,18 @@ def gen_delta_msg(total_changes, markup='*'):
"""Return string of changes for the PR message."""
delta = ''
is_single_distro = len(total_changes) == 1
distro_header = '#'
distro_header = '='
if not is_single_distro:
delta += "# Changes:\n"
distro_header *= 2
delta += "Changes:\n"
delta += "========\n"
distro_header = '-'
for distro in sorted(total_changes):
if not total_changes[distro]:
continue
delta += "{} {} Changes:\n".format(distro_header, distro.title())
heading = "{} Changes:\n".format(distro.title())
delta += heading
delta += distro_header * (len(heading) - 1)
delta += "\n"
for d in sorted(total_changes[distro]):
delta += '* {1}{0}{1}\n'.format(d, markup)
delta += "\n"
Expand Down
9 changes: 6 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ def test_delta_msg(self):
total_changes['hydro'] = ['foo', 'bar']
total_changes['boxturtle'] = ['baz']
total_changes['C'] = []
expect = '# Changes:\n'\
'## Boxturtle Changes:\n'\
expect = 'Changes:\n'\
'========\n'\
'Boxturtle Changes:\n'\
'------------------\n'\
'* *baz*\n\n'\
'## Hydro Changes:\n'\
'Hydro Changes:\n'\
'--------------\n'\
'* *bar*\n'\
'* *foo*\n\n'
got = gen_delta_msg(total_changes)
Expand Down

0 comments on commit 53fc43c

Please sign in to comment.