mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[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:
parent
64eeb6142e
commit
59e730f703
@ -126,6 +126,7 @@ def handle_pr(env, event):
|
|||||||
updates['squash'] = pr['commits'] == 1
|
updates['squash'] = pr['commits'] == 1
|
||||||
if event['changes'].keys() & {'title', 'body'}:
|
if event['changes'].keys() & {'title', 'body'}:
|
||||||
updates['message'] = "{}\n\n{}".format(pr['title'].strip(), pr['body'].strip())
|
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:
|
if updates:
|
||||||
pr_obj = find(source_branch)
|
pr_obj = find(source_branch)
|
||||||
pr_obj.write(updates)
|
pr_obj.write(updates)
|
||||||
@ -145,16 +146,13 @@ def handle_pr(env, event):
|
|||||||
if not branch:
|
if not branch:
|
||||||
return "Not set up to care about {}:{}".format(r, b)
|
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':
|
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)
|
pr_obj = env['runbot_merge.pull_requests']._from_gh(pr)
|
||||||
return "Tracking PR as {}".format(pr_obj.id)
|
return "Tracking PR as {}".format(pr_obj.id)
|
||||||
|
|
||||||
|
@ -147,6 +147,7 @@ All substitutions are tentatively applied sequentially to the input.
|
|||||||
"its information, you may have to re-approve it as "
|
"its information, you may have to re-approve it as "
|
||||||
"I didn't see previous commands." % pr_id.ping()
|
"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
|
# init the PR to the null commit so we can later synchronise it back
|
||||||
# back to the "proper" head while resetting reviews
|
# back to the "proper" head while resetting reviews
|
||||||
controllers.handle_pr(self.env, {
|
controllers.handle_pr(self.env, {
|
||||||
@ -156,6 +157,7 @@ All substitutions are tentatively applied sequentially to the input.
|
|||||||
'head': {**pr['head'], 'sha': '0'*40},
|
'head': {**pr['head'], 'sha': '0'*40},
|
||||||
'state': 'open',
|
'state': 'open',
|
||||||
},
|
},
|
||||||
|
'sender': sender,
|
||||||
})
|
})
|
||||||
# fetch & set up actual head
|
# fetch & set up actual head
|
||||||
for st in gh.statuses(pr['head']['sha']):
|
for st in gh.statuses(pr['head']['sha']):
|
||||||
@ -177,20 +179,21 @@ All substitutions are tentatively applied sequentially to the input.
|
|||||||
'review': item,
|
'review': item,
|
||||||
'pull_request': pr,
|
'pull_request': pr,
|
||||||
'repository': {'full_name': self.name},
|
'repository': {'full_name': self.name},
|
||||||
|
'sender': sender,
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
controllers.handle_comment(self.env, {
|
controllers.handle_comment(self.env, {
|
||||||
'action': 'created',
|
'action': 'created',
|
||||||
'issue': issue,
|
'issue': issue,
|
||||||
'sender': item['user'],
|
|
||||||
'comment': item,
|
'comment': item,
|
||||||
'repository': {'full_name': self.name},
|
'repository': {'full_name': self.name},
|
||||||
|
'sender': sender,
|
||||||
})
|
})
|
||||||
# sync to real head
|
# sync to real head
|
||||||
controllers.handle_pr(self.env, {
|
controllers.handle_pr(self.env, {
|
||||||
'action': 'synchronize',
|
'action': 'synchronize',
|
||||||
'pull_request': pr,
|
'pull_request': pr,
|
||||||
'sender': {'login': self.project_id.github_prefix}
|
'sender': sender,
|
||||||
})
|
})
|
||||||
if pr['state'] == 'closed':
|
if pr['state'] == 'closed':
|
||||||
# don't go through controller because try_closing does weird things
|
# don't go through controller because try_closing does weird things
|
||||||
|
@ -930,7 +930,8 @@ class TestSubstitutions:
|
|||||||
'label': original,
|
'label': original,
|
||||||
'sha': format(pr_number, 'x')*40,
|
'sha': format(pr_number, 'x')*40,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
'sender': {'login': 'pytest'}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
pr = env['runbot_merge.pull_requests'].search([
|
pr = env['runbot_merge.pull_requests'].search([
|
||||||
|
Loading…
Reference in New Issue
Block a user