diff --git a/buildtrigger/githubhandler.py b/buildtrigger/githubhandler.py index d92d9530d..d60c802fb 100644 --- a/buildtrigger/githubhandler.py +++ b/buildtrigger/githubhandler.py @@ -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'] diff --git a/test/test_prepare_trigger.py b/test/test_prepare_trigger.py index b2ca6d7e8..54c00454d 100644 --- a/test/test_prepare_trigger.py +++ b/test/test_prepare_trigger.py @@ -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',