Handle the case where we have lookup_user but no username
This commit is contained in:
parent
c4f938898a
commit
eaf81959f5
2 changed files with 26 additions and 1 deletions
|
@ -118,7 +118,8 @@ def get_transformed_webhook_payload(gh_payload, default_branch=None, lookup_user
|
|||
|
||||
# Note: GitHub doesn't always return the extra information for users, so we do the lookup
|
||||
# manually if possible.
|
||||
if lookup_user and not payload.get('head_commit.author.html_url'):
|
||||
if (lookup_user and not payload.get('head_commit.author.html_url') and
|
||||
payload.get('head_commit.author.username')):
|
||||
author_info = lookup_user(payload['head_commit.author.username'])
|
||||
if author_info:
|
||||
config['commit_info.author.url'] = author_info['html_url']
|
||||
|
|
|
@ -171,6 +171,30 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
self.assertSchema('github_webhook', expected, gh_webhook, lookup_user=lookup_user)
|
||||
|
||||
|
||||
def test_github_webhook_payload_missing_fields_with_lookup(self):
|
||||
expected = {
|
||||
'commit': u'410f4cdf8ff09b87f245b13845e8497f90b90a4c',
|
||||
'ref': u'refs/heads/master',
|
||||
'git_url': u'git@github.com:josephschorr/anothertest.git',
|
||||
'commit_info': {
|
||||
'url': u'https://github.com/josephschorr/anothertest/commit/410f4cdf8ff09b87f245b13845e8497f90b90a4c',
|
||||
'date': u'2015-09-11T14:26:16-04:00',
|
||||
'message': u'Update Dockerfile'
|
||||
},
|
||||
}
|
||||
|
||||
def lookup_user(username):
|
||||
if not username:
|
||||
raise Exception('Fail!')
|
||||
|
||||
return {
|
||||
'html_url': 'http://github.com/josephschorr',
|
||||
'avatar_url': 'http://some/avatar/url'
|
||||
}
|
||||
|
||||
self.assertSchema('github_webhook_missing', expected, gh_webhook, lookup_user=lookup_user)
|
||||
|
||||
|
||||
def test_gitlab_webhook_payload(self):
|
||||
expected = {
|
||||
'commit': u'fb88379ee45de28a0a4590fddcbd8eff8b36026e',
|
||||
|
|
Reference in a new issue