Skip bitbucket pushes without any commits

Fixes https://sentry.io/coreos/backend-production/issues/178220183/
This commit is contained in:
Joseph Schorr 2017-03-20 18:23:21 -04:00
parent 4cb8412fd8
commit 6476488221
4 changed files with 90 additions and 2 deletions

View file

@ -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']

View file

@ -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()

View file

@ -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}"
}
}

View file

@ -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)
try:
matches = jsonpath_expr.find(self._object)
except IndexError:
return None
if not matches:
return not_found_handler() if not_found_handler else None