mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[FIX] runbot_merge: correctly handle emptying PR body
The previous version of the code assumed `pr['body']` is always a
string, which is not correct, when the PR body is emptied the body
itself is removed (its value is `None`).
Add a case for this in the PR edition test, and avoid blowing up (or
adding empty newlines) when the PR body is empty. For PR creation this
issue was fixed in c2db5659d8
but
apparently I missed that the exact same issue occurs just a few lines
above.
Also turns out github does *not* send change information when the body
is updated from (or to?) `None`, so don't even bother with that, just
check every time if the overall message has been updated.
Fixes #629
This commit is contained in:
parent
b86092de83
commit
3da1874196
22
conftest.py
22
conftest.py
@ -826,6 +826,12 @@ mutation setDraft($pid: ID!) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
def state_prop(name: str) -> property:
|
||||||
|
@property
|
||||||
|
def _prop(self):
|
||||||
|
return self._pr[name]
|
||||||
|
return _prop.setter(lambda self, v: self._set_prop(name, v))
|
||||||
|
|
||||||
class PR:
|
class PR:
|
||||||
def __init__(self, repo, number):
|
def __init__(self, repo, number):
|
||||||
self.repo = repo
|
self.repo = repo
|
||||||
@ -850,15 +856,9 @@ class PR:
|
|||||||
caching['If-Modified-Since']= r.headers['Last-Modified']
|
caching['If-Modified-Since']= r.headers['Last-Modified']
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
@property
|
title = state_prop('title')
|
||||||
def title(self):
|
body = state_prop('body')
|
||||||
return self._pr['title']
|
base = state_prop('base')
|
||||||
title = title.setter(lambda self, v: self._set_prop('title', v))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def base(self):
|
|
||||||
return self._pr['base']
|
|
||||||
base = base.setter(lambda self, v: self._set_prop('base', v))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def draft(self):
|
def draft(self):
|
||||||
@ -888,10 +888,6 @@ class PR:
|
|||||||
def state(self):
|
def state(self):
|
||||||
return self._pr['state']
|
return self._pr['state']
|
||||||
|
|
||||||
@property
|
|
||||||
def body(self):
|
|
||||||
return self._pr['body']
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def comments(self):
|
def comments(self):
|
||||||
r = self.repo._session.get('https://api.github.com/repos/{}/issues/{}/comments'.format(self.repo.name, self.number))
|
r = self.repo._session.get('https://api.github.com/repos/{}/issues/{}/comments'.format(self.repo.name, self.number))
|
||||||
|
4
runbot_merge/changelog/2022-06/empty-body.md
Normal file
4
runbot_merge/changelog/2022-06/empty-body.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
FIX: correctly handle PR empty PR descriptions
|
||||||
|
|
||||||
|
Github's webhook for this case are weird, and weren't handled correctly,
|
||||||
|
updating a PR's description to *or from* empty might be mishandled.
|
@ -120,15 +120,25 @@ def handle_pr(env, event):
|
|||||||
if not source_branch:
|
if not source_branch:
|
||||||
return handle_pr(env, dict(event, action='opened'))
|
return handle_pr(env, dict(event, action='opened'))
|
||||||
|
|
||||||
|
pr_obj = find(source_branch)
|
||||||
updates = {}
|
updates = {}
|
||||||
if source_branch != branch:
|
if source_branch != branch:
|
||||||
updates['target'] = branch.id
|
if branch != pr_obj.target:
|
||||||
updates['squash'] = pr['commits'] == 1
|
updates['target'] = branch.id
|
||||||
if event['changes'].keys() & {'title', 'body'}:
|
updates['squash'] = pr['commits'] == 1
|
||||||
updates['message'] = "{}\n\n{}".format(pr['title'].strip(), pr['body'].strip())
|
|
||||||
|
# turns out github doesn't bother sending a change key if the body is
|
||||||
|
# changing from empty (None), therefore ignore that entirely, just
|
||||||
|
# generate the message and check if it changed
|
||||||
|
message = pr['title'].strip()
|
||||||
|
body = (pr['body'] or '').strip()
|
||||||
|
if body:
|
||||||
|
message += f"\n\n{body}"
|
||||||
|
if message != pr_obj.message:
|
||||||
|
updates['message'] = message
|
||||||
|
|
||||||
_logger.info("update: %s#%d = %s (by %s)", repo.name, pr['number'], updates, event['sender']['login'])
|
_logger.info("update: %s#%d = %s (by %s)", repo.name, pr['number'], updates, event['sender']['login'])
|
||||||
if updates:
|
if updates:
|
||||||
pr_obj = find(source_branch)
|
|
||||||
pr_obj.write(updates)
|
pr_obj.write(updates)
|
||||||
return 'Updated {}'.format(pr_obj.id)
|
return 'Updated {}'.format(pr_obj.id)
|
||||||
return "Nothing to update ({})".format(event['changes'].keys())
|
return "Nothing to update ({})".format(event['changes'].keys())
|
||||||
|
@ -728,6 +728,8 @@ class TestPREdition:
|
|||||||
assert pr.message == 'title\n\nbody'
|
assert pr.message == 'title\n\nbody'
|
||||||
with repo: prx.title = "title 2"
|
with repo: prx.title = "title 2"
|
||||||
assert pr.message == 'title 2\n\nbody'
|
assert pr.message == 'title 2\n\nbody'
|
||||||
|
with repo: prx.body = None
|
||||||
|
assert pr.message == "title 2"
|
||||||
assert pr.staging_id, \
|
assert pr.staging_id, \
|
||||||
"message edition does not affect staging of rebased PRs"
|
"message edition does not affect staging of rebased PRs"
|
||||||
with repo: prx.base = '1.0'
|
with repo: prx.base = '1.0'
|
||||||
|
Loading…
Reference in New Issue
Block a user