[FIX] runbot_merge: incorrect processing of rebased commit messages

5cf3617eef intended to create merge
messages with only the content of PR descriptions before the first
thematic break. However this processing was incorrectly applied
to all messages being processed (meaning rebased / squashed commit
messages as well).

Properly apply thematic break processing to only commit messages
created from PR descriptions.
This commit is contained in:
Xavier Morel 2021-01-21 13:15:32 +01:00
parent 08b8da08df
commit 21077c690a
2 changed files with 38 additions and 3 deletions

View File

@ -1343,7 +1343,7 @@ class PullRequests(models.Model):
return head
def _stage_rebase_merge(self, gh, target, commits, related_prs=()):
msg = self._build_merge_message(self.message, related_prs=related_prs)
msg = self._build_merge_message(self, related_prs=related_prs)
h, mapping = gh.rebase(self.number, target, reset=True, commits=commits)
merge_head = gh.merge(h, target, str(msg))['sha']
self.commits_map = json.dumps({**mapping, '': merge_head})
@ -1384,7 +1384,7 @@ class PullRequests(models.Model):
return copy['sha']
else:
# otherwise do a regular merge
msg = self._build_merge_message(self.message)
msg = self._build_merge_message(self)
merge_head = gh.merge(self.head, target, str(msg))['sha']
# and the merge commit is the normal merge head
commits_map[''] = merge_head
@ -2081,6 +2081,8 @@ class Message:
def from_message(cls, msg):
in_headers = True
maybe_setex = None
# creating from PR message -> remove content following break
msg, handle_break = (msg, False) if isinstance(msg, str) else (msg.message, True)
headers = []
body = []
for line in reversed(msg.splitlines()):
@ -2102,7 +2104,7 @@ class Message:
body.append(line)
continue
if BREAK.match(line):
if handle_break and BREAK.match(line):
if SETEX_UNDERLINE.match(line):
maybe_setex = line
else:

View File

@ -1718,6 +1718,39 @@ removed
Signed-off-by: {reviewer}
""").strip(), "should not break the SETEX titles"
def test_rebase_no_edit(self, repo, env, users, config):
""" Only the merge messages should be de-breaked
"""
reviewer = get_partner(env, users["reviewer"]).formatted_email
with repo:
root = repo.make_commits(None, Commit("root", tree={'a': 'a'}), ref='heads/master')
repo.make_commits(root, Commit('Commit\n\nfirst\n***\nsecond', tree={'a': 'b'}), ref=f'heads/change')
pr = repo.make_pr(title="PR", body=f'first\n***\nsecond',
target='master', head=f'change')
repo.post_status(pr.head, 'success', 'legal/cla')
repo.post_status(pr.head, 'success', 'ci/runbot')
pr.post_comment('hansen r+', config['role_reviewer']['token'])
env.run_crons()
with repo:
repo.post_status('heads/staging.master', 'success', 'ci/runbot')
repo.post_status('heads/staging.master', 'success', 'legal/cla')
env.run_crons()
head = repo.commit('heads/master')
assert head.message == textwrap.dedent(f"""\
Commit
first
***
second
closes {repo.name}#{pr.number}
Signed-off-by: {reviewer}
""").strip(), "squashed / rebased messages should not be stripped"
def test_pr_mergehead(self, repo, env, config):
""" if the head of the PR is a merge commit and one of the parents is
in the target, replicate the merge commit instead of merging