diff --git a/runbot_merge/controllers/__init__.py b/runbot_merge/controllers/__init__.py index 6dad2666..ecee99f3 100644 --- a/runbot_merge/controllers/__init__.py +++ b/runbot_merge/controllers/__init__.py @@ -126,6 +126,7 @@ def handle_pr(env, event): updates['squash'] = pr['commits'] == 1 if event['changes'].keys() & {'title', 'body'}: updates['message'] = "{}\n\n{}".format(pr['title'].strip(), pr['body'].strip()) + _logger.info("update: %s#%d = %s (by %s)", repo.name, pr['number'], updates, event['sender']['login']) if updates: pr_obj = find(source_branch) pr_obj.write(updates) @@ -145,16 +146,13 @@ def handle_pr(env, event): if not branch: return "Not set up to care about {}:{}".format(r, b) - author_name = pr['user']['login'] - author = env['res.partner'].search([('github_login', '=', author_name)], limit=1) - if not author: - author = env['res.partner'].create({ - 'name': author_name, - 'github_login': author_name, - }) - _logger.info("%s: %s#%s (%s) (%s)", event['action'], repo.name, pr['number'], pr['title'].strip(), author.github_login) + _logger.info("%s: %s#%s (%s) (by %s)", event['action'], repo.name, pr['number'], pr['title'].strip(), event['sender']['login']) if event['action'] == 'opened': + author_name = pr['user']['login'] + author = env['res.partner'].search([('github_login', '=', author_name)], limit=1) + if not author: + env['res.partner'].create({'name': author_name, 'github_login': author_name}) pr_obj = env['runbot_merge.pull_requests']._from_gh(pr) return "Tracking PR as {}".format(pr_obj.id) diff --git a/runbot_merge/models/pull_requests.py b/runbot_merge/models/pull_requests.py index 2b189a38..135a845d 100644 --- a/runbot_merge/models/pull_requests.py +++ b/runbot_merge/models/pull_requests.py @@ -147,6 +147,7 @@ All substitutions are tentatively applied sequentially to the input. "its information, you may have to re-approve it as " "I didn't see previous commands." % pr_id.ping() }) + sender = {'login': self.project_id.github_prefix} # init the PR to the null commit so we can later synchronise it back # back to the "proper" head while resetting reviews controllers.handle_pr(self.env, { @@ -156,6 +157,7 @@ All substitutions are tentatively applied sequentially to the input. 'head': {**pr['head'], 'sha': '0'*40}, 'state': 'open', }, + 'sender': sender, }) # fetch & set up actual head for st in gh.statuses(pr['head']['sha']): @@ -177,20 +179,21 @@ All substitutions are tentatively applied sequentially to the input. 'review': item, 'pull_request': pr, 'repository': {'full_name': self.name}, + 'sender': sender, }) else: controllers.handle_comment(self.env, { 'action': 'created', 'issue': issue, - 'sender': item['user'], 'comment': item, 'repository': {'full_name': self.name}, + 'sender': sender, }) # sync to real head controllers.handle_pr(self.env, { 'action': 'synchronize', 'pull_request': pr, - 'sender': {'login': self.project_id.github_prefix} + 'sender': sender, }) if pr['state'] == 'closed': # don't go through controller because try_closing does weird things diff --git a/runbot_merge/tests/test_multirepo.py b/runbot_merge/tests/test_multirepo.py index 96c61423..461ed0cb 100644 --- a/runbot_merge/tests/test_multirepo.py +++ b/runbot_merge/tests/test_multirepo.py @@ -930,7 +930,8 @@ class TestSubstitutions: 'label': original, 'sha': format(pr_number, 'x')*40, } - } + }, + 'sender': {'login': 'pytest'} } ) pr = env['runbot_merge.pull_requests'].search([