From 69e2cfad70d370984b2007335e63d7c38f741005 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 16 Nov 2016 14:14:13 -0500 Subject: [PATCH] Fix github trigger when submitting a webhook without a head_commit Fixes #2125 --- buildtrigger/githubhandler.py | 5 +- test/test_prepare_trigger.py | 6 + .../github_webhook_knownissue.json | 126 ++++++++++++++++++ 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 test/triggerjson/github_webhook_knownissue.json diff --git a/buildtrigger/githubhandler.py b/buildtrigger/githubhandler.py index 12bb3dc7f..32ef6ee1a 100644 --- a/buildtrigger/githubhandler.py +++ b/buildtrigger/githubhandler.py @@ -29,7 +29,7 @@ GITHUB_WEBHOOK_PAYLOAD_SCHEMA = { 'type': 'string', }, 'head_commit': { - 'type': 'object', + 'type': ['object', 'null'], 'properties': { 'id': { 'type': 'string', @@ -98,6 +98,9 @@ def get_transformed_webhook_payload(gh_payload, default_branch=None, lookup_user payload = JSONPathDict(gh_payload) + if payload['head_commit'] is None: + raise SkipRequestException + config = SafeDictSetter() config['commit'] = payload['head_commit.id'] config['ref'] = payload['ref'] diff --git a/test/test_prepare_trigger.py b/test/test_prepare_trigger.py index 30f2a510e..fec64ea23 100644 --- a/test/test_prepare_trigger.py +++ b/test/test_prepare_trigger.py @@ -443,5 +443,11 @@ class TestPrepareTrigger(unittest.TestCase): self.assertSchema('github_webhook_deletedcommit', expected, gh_webhook, lookup_user=lookup_user) + def test_github_webhook_known_issue(self): + def lookup_user(_): + return None + + self.assertSkipped('github_webhook_knownissue', gh_webhook, lookup_user=lookup_user) + if __name__ == '__main__': unittest.main() diff --git a/test/triggerjson/github_webhook_knownissue.json b/test/triggerjson/github_webhook_knownissue.json new file mode 100644 index 000000000..ae82e4857 --- /dev/null +++ b/test/triggerjson/github_webhook_knownissue.json @@ -0,0 +1,126 @@ +{ + "ref": "refs/heads/1.2.6", + "before": "76a309ed96c72986eddffc02d2f4dda3fe689f10", + "after": "0000000000000000000000000000000000000000", + "created": false, + "deleted": true, + "forced": false, + "base_ref": null, + "compare": "https://github.com/coreos/clair-jwt-docker/compare/76a309ed96c7...000000000000", + "commits": [ + + ], + "head_commit": null, + "repository": { + "id": 56698571, + "name": "clair-jwt-docker", + "full_name": "coreos/clair-jwt-docker", + "owner": { + "name": "coreos", + "email": "partners@coreos.com" + }, + "private": true, + "html_url": "https://github.com/coreos/clair-jwt-docker", + "description": "Dockerfile for Clair running behind jwtproxy", + "fork": false, + "url": "https://github.com/coreos/clair-jwt-docker", + "forks_url": "https://api.github.com/repos/coreos/clair-jwt-docker/forks", + "keys_url": "https://api.github.com/repos/coreos/clair-jwt-docker/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/coreos/clair-jwt-docker/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/coreos/clair-jwt-docker/teams", + "hooks_url": "https://api.github.com/repos/coreos/clair-jwt-docker/hooks", + "issue_events_url": "https://api.github.com/repos/coreos/clair-jwt-docker/issues/events{/number}", + "events_url": "https://api.github.com/repos/coreos/clair-jwt-docker/events", + "assignees_url": "https://api.github.com/repos/coreos/clair-jwt-docker/assignees{/user}", + "branches_url": "https://api.github.com/repos/coreos/clair-jwt-docker/branches{/branch}", + "tags_url": "https://api.github.com/repos/coreos/clair-jwt-docker/tags", + "blobs_url": "https://api.github.com/repos/coreos/clair-jwt-docker/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/coreos/clair-jwt-docker/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/coreos/clair-jwt-docker/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/coreos/clair-jwt-docker/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/coreos/clair-jwt-docker/statuses/{sha}", + "languages_url": "https://api.github.com/repos/coreos/clair-jwt-docker/languages", + "stargazers_url": "https://api.github.com/repos/coreos/clair-jwt-docker/stargazers", + "contributors_url": "https://api.github.com/repos/coreos/clair-jwt-docker/contributors", + "subscribers_url": "https://api.github.com/repos/coreos/clair-jwt-docker/subscribers", + "subscription_url": "https://api.github.com/repos/coreos/clair-jwt-docker/subscription", + "commits_url": "https://api.github.com/repos/coreos/clair-jwt-docker/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/coreos/clair-jwt-docker/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/coreos/clair-jwt-docker/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/coreos/clair-jwt-docker/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/coreos/clair-jwt-docker/contents/{+path}", + "compare_url": "https://api.github.com/repos/coreos/clair-jwt-docker/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/coreos/clair-jwt-docker/merges", + "archive_url": "https://api.github.com/repos/coreos/clair-jwt-docker/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/coreos/clair-jwt-docker/downloads", + "issues_url": "https://api.github.com/repos/coreos/clair-jwt-docker/issues{/number}", + "pulls_url": "https://api.github.com/repos/coreos/clair-jwt-docker/pulls{/number}", + "milestones_url": "https://api.github.com/repos/coreos/clair-jwt-docker/milestones{/number}", + "notifications_url": "https://api.github.com/repos/coreos/clair-jwt-docker/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/coreos/clair-jwt-docker/labels{/name}", + "releases_url": "https://api.github.com/repos/coreos/clair-jwt-docker/releases{/id}", + "deployments_url": "https://api.github.com/repos/coreos/clair-jwt-docker/deployments", + "created_at": 1461165926, + "updated_at": "2016-11-03T18:20:01Z", + "pushed_at": 1479313569, + "git_url": "git://github.com/coreos/clair-jwt-docker.git", + "ssh_url": "git@github.com:coreos/clair-jwt-docker.git", + "clone_url": "https://github.com/coreos/clair-jwt-docker.git", + "svn_url": "https://github.com/coreos/clair-jwt-docker", + "homepage": "", + "size": 3114, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Shell", + "has_issues": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "open_issues_count": 0, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "stargazers": 0, + "master_branch": "master", + "organization": "coreos" + }, + "pusher": { + "name": "jzelinskie", + "email": "jimmy.zelinskie+git@gmail.com" + }, + "organization": { + "login": "coreos", + "id": 3730757, + "url": "https://api.github.com/orgs/coreos", + "repos_url": "https://api.github.com/orgs/coreos/repos", + "events_url": "https://api.github.com/orgs/coreos/events", + "hooks_url": "https://api.github.com/orgs/coreos/hooks", + "issues_url": "https://api.github.com/orgs/coreos/issues", + "members_url": "https://api.github.com/orgs/coreos/members{/member}", + "public_members_url": "https://api.github.com/orgs/coreos/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/3730757?v=3", + "description": "Open Source Projects for Linux Containers" + }, + "sender": { + "login": "jzelinskie", + "id": 343539, + "avatar_url": "https://avatars.githubusercontent.com/u/343539?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/jzelinskie", + "html_url": "https://github.com/jzelinskie", + "followers_url": "https://api.github.com/users/jzelinskie/followers", + "following_url": "https://api.github.com/users/jzelinskie/following{/other_user}", + "gists_url": "https://api.github.com/users/jzelinskie/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jzelinskie/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jzelinskie/subscriptions", + "organizations_url": "https://api.github.com/users/jzelinskie/orgs", + "repos_url": "https://api.github.com/users/jzelinskie/repos", + "events_url": "https://api.github.com/users/jzelinskie/events{/privacy}", + "received_events_url": "https://api.github.com/users/jzelinskie/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file