[IMP] runbot_merge: controllers logging

- add a logging entry for PR updates
- change the generic log entry to log the sender (of the event) rather
  than the PR author
- fix the post-facto PR loader to more systematically and reliably set
  a `sender`
This commit is contained in:
Xavier Morel 2022-07-04 09:44:11 +02:00
parent 64eeb6142e
commit 59e730f703
3 changed files with 13 additions and 11 deletions

View File

@ -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)

View File

@ -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

View File

@ -930,7 +930,8 @@ class TestSubstitutions:
'label': original,
'sha': format(pr_number, 'x')*40,
}
}
},
'sender': {'login': 'pytest'}
}
)
pr = env['runbot_merge.pull_requests'].search([