Merge pull request #33 from coreos-inc/branchregex

Add some more debug logging around bitbucket triggers and add some te…
This commit is contained in:
Jimmy Zelinskie 2015-05-20 14:22:33 -04:00
commit 7bed404302
2 changed files with 35 additions and 0 deletions

View file

@ -488,30 +488,36 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
# Parse the JSON payload.
payload_json = request.form.get('payload')
if not payload_json:
logger.debug('Skipping BitBucket request due to missing payload')
raise SkipRequestException()
try:
payload = json.loads(payload_json)
except ValueError:
logger.debug('Skipping BitBucket request due to invalid payload')
raise SkipRequestException()
logger.debug('BitBucket trigger payload %s', payload)
# Make sure we have a commit in the payload.
if not payload.get('commits'):
logger.debug('Skipping BitBucket request due to missing commits block')
raise SkipRequestException()
# Check if this build should be skipped by commit message.
commit = payload['commits'][0]
commit_message = commit['message']
if should_skip_commit(commit_message):
logger.debug('Skipping BitBucket request due to commit message request')
raise SkipRequestException()
# Check to see if this build should be skipped by ref.
if not commit.get('branch') and not commit.get('tag'):
logger.debug('Skipping BitBucket request due to missing branch and tag')
raise SkipRequestException()
ref = 'refs/heads/' + commit['branch'] if commit.get('branch') else 'refs/tags/' + commit['tag']
logger.debug('Checking BitBucket request: %s', ref)
raise_if_skipped(self.config, ref)
commit_sha = commit['node']

29
test/test_trigger.py Normal file
View file

@ -0,0 +1,29 @@
import unittest
import re
from endpoints.trigger import matches_ref
class TestRegex(unittest.TestCase):
def assertDoesNotMatch(self, ref, filt):
self.assertFalse(matches_ref(ref, re.compile(filt)))
def assertMatches(self, ref, filt):
self.assertTrue(matches_ref(ref, re.compile(filt)))
def test_matches_ref(self):
self.assertMatches('ref/heads/master', '.+')
self.assertMatches('ref/heads/master', 'heads/.+')
self.assertMatches('ref/heads/master', 'heads/master')
self.assertDoesNotMatch('ref/heads/foobar', 'heads/master')
self.assertDoesNotMatch('ref/heads/master', 'tags/master')
self.assertMatches('ref/heads/master', '(((heads/alpha)|(heads/beta))|(heads/gamma))|(heads/master)')
self.assertMatches('ref/heads/alpha', '(((heads/alpha)|(heads/beta))|(heads/gamma))|(heads/master)')
self.assertMatches('ref/heads/beta', '(((heads/alpha)|(heads/beta))|(heads/gamma))|(heads/master)')
self.assertMatches('ref/heads/gamma', '(((heads/alpha)|(heads/beta))|(heads/gamma))|(heads/master)')
self.assertDoesNotMatch('ref/heads/delta', '(((heads/alpha)|(heads/beta))|(heads/gamma))|(heads/master)')
if __name__ == '__main__':
unittest.main()