diff --git a/buildtrigger/bitbuckethandler.py b/buildtrigger/bitbuckethandler.py index b1bad253c..213ba27ad 100644 --- a/buildtrigger/bitbuckethandler.py +++ b/buildtrigger/bitbuckethandler.py @@ -12,6 +12,7 @@ from buildtrigger.basehandler import BuildTriggerHandler from buildtrigger.triggerutil import (RepositoryReadException, TriggerActivationException, TriggerDeactivationException, TriggerStartException, InvalidPayloadException, TriggerProviderException, + SkipRequestException, determine_build_ref, raise_if_skipped_build, find_matching_branches) from util.dict_wrappers import JSONPathDict, SafeDictSetter @@ -226,7 +227,7 @@ def get_transformed_webhook_payload(bb_payload, default_branch=None): payload = JSONPathDict(bb_payload) change = payload['push.changes[-1].new'] if not change: - return None + raise SkipRequestException is_branch = change['type'] == 'branch' ref = 'refs/heads/' + change['name'] if is_branch else 'refs/tags/' + change['name'] diff --git a/test/test_prepare_trigger.py b/test/test_prepare_trigger.py index f572f4d32..975847533 100644 --- a/test/test_prepare_trigger.py +++ b/test/test_prepare_trigger.py @@ -511,5 +511,9 @@ class TestPrepareTrigger(unittest.TestCase): self.assertSkipped('github_webhook_knownissue', gh_webhook, lookup_user=lookup_user) + + def test_bitbucket_webhook_known_issue(self): + self.assertSkipped('bitbucket_knownissue', bb_webhook) + if __name__ == '__main__': unittest.main() diff --git a/test/triggerjson/bitbucket_knownissue.json b/test/triggerjson/bitbucket_knownissue.json new file mode 100644 index 000000000..77573777f --- /dev/null +++ b/test/triggerjson/bitbucket_knownissue.json @@ -0,0 +1,78 @@ +{ + "push": { + "changes": [ + + ] + }, + "actor": { + "username": "SL_jwilds", + "display_name": "Jim Wilds", + "type": "user", + "uuid": "{61f851e9-afbc-4bc6-bb9b-99e23c0e765a}", + "links": { + "self": { + "href": "https:\/\/api.bitbucket.org\/2.0\/users\/SL_jwilds" + }, + "html": { + "href": "https:\/\/bitbucket.org\/SL_jwilds\/" + }, + "avatar": { + "href": "https:\/\/bitbucket.org\/account\/SL_jwilds\/avatar\/32\/" + } + } + }, + "repository": { + "website": "", + "scm": "git", + "name": "slip-api", + "links": { + "self": { + "href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/silverlinkinc\/slip-api" + }, + "html": { + "href": "https:\/\/bitbucket.org\/silverlinkinc\/slip-api" + }, + "avatar": { + "href": "https:\/\/bitbucket.org\/silverlinkinc\/slip-api\/avatar\/32\/" + } + }, + "project": { + "links": { + "self": { + "href": "https:\/\/api.bitbucket.org\/2.0\/teams\/silverlinkinc\/projects\/SLIP" + }, + "html": { + "href": "https:\/\/bitbucket.org\/account\/user\/silverlinkinc\/projects\/SLIP" + }, + "avatar": { + "href": "https:\/\/bitbucket.org\/account\/user\/silverlinkinc\/projects\/SLIP\/avatar\/32" + } + }, + "type": "project", + "name": "SLIP", + "key": "SLIP", + "uuid": "{f5ba67c5-3585-453b-9412-77e4dc15be29}" + }, + "full_name": "silverlinkinc\/slip-api", + "owner": { + "username": "silverlinkinc", + "display_name": "Silverlink", + "type": "team", + "uuid": "{9c4ce5f2-79fe-4906-9451-41fcac6bb293}", + "links": { + "self": { + "href": "https:\/\/api.bitbucket.org\/2.0\/teams\/silverlinkinc" + }, + "html": { + "href": "https:\/\/bitbucket.org\/silverlinkinc\/" + }, + "avatar": { + "href": "https:\/\/bitbucket.org\/account\/silverlinkinc\/avatar\/32\/" + } + } + }, + "type": "repository", + "is_private": true, + "uuid": "{59183493-0e4a-47aa-b069-be60adce4092}" + } +} \ No newline at end of file diff --git a/util/dict_wrappers.py b/util/dict_wrappers.py index f840f2c36..87f7d9bc1 100644 --- a/util/dict_wrappers.py +++ b/util/dict_wrappers.py @@ -62,7 +62,12 @@ class JSONPathDict(object): def get(self, path, not_found_handler=None): """ Returns the value found at the given path. Path is a json-path expression. """ jsonpath_expr = parse(path) - matches = jsonpath_expr.find(self._object) + + try: + matches = jsonpath_expr.find(self._object) + except IndexError: + return None + if not matches: return not_found_handler() if not_found_handler else None