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:
commit
7bed404302
2 changed files with 35 additions and 0 deletions
|
@ -488,30 +488,36 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
||||||
# Parse the JSON payload.
|
# Parse the JSON payload.
|
||||||
payload_json = request.form.get('payload')
|
payload_json = request.form.get('payload')
|
||||||
if not payload_json:
|
if not payload_json:
|
||||||
|
logger.debug('Skipping BitBucket request due to missing payload')
|
||||||
raise SkipRequestException()
|
raise SkipRequestException()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = json.loads(payload_json)
|
payload = json.loads(payload_json)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
logger.debug('Skipping BitBucket request due to invalid payload')
|
||||||
raise SkipRequestException()
|
raise SkipRequestException()
|
||||||
|
|
||||||
logger.debug('BitBucket trigger payload %s', payload)
|
logger.debug('BitBucket trigger payload %s', payload)
|
||||||
|
|
||||||
# Make sure we have a commit in the payload.
|
# Make sure we have a commit in the payload.
|
||||||
if not payload.get('commits'):
|
if not payload.get('commits'):
|
||||||
|
logger.debug('Skipping BitBucket request due to missing commits block')
|
||||||
raise SkipRequestException()
|
raise SkipRequestException()
|
||||||
|
|
||||||
# Check if this build should be skipped by commit message.
|
# Check if this build should be skipped by commit message.
|
||||||
commit = payload['commits'][0]
|
commit = payload['commits'][0]
|
||||||
commit_message = commit['message']
|
commit_message = commit['message']
|
||||||
if should_skip_commit(commit_message):
|
if should_skip_commit(commit_message):
|
||||||
|
logger.debug('Skipping BitBucket request due to commit message request')
|
||||||
raise SkipRequestException()
|
raise SkipRequestException()
|
||||||
|
|
||||||
# Check to see if this build should be skipped by ref.
|
# Check to see if this build should be skipped by ref.
|
||||||
if not commit.get('branch') and not commit.get('tag'):
|
if not commit.get('branch') and not commit.get('tag'):
|
||||||
|
logger.debug('Skipping BitBucket request due to missing branch and tag')
|
||||||
raise SkipRequestException()
|
raise SkipRequestException()
|
||||||
|
|
||||||
ref = 'refs/heads/' + commit['branch'] if commit.get('branch') else 'refs/tags/' + commit['tag']
|
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)
|
raise_if_skipped(self.config, ref)
|
||||||
|
|
||||||
commit_sha = commit['node']
|
commit_sha = commit['node']
|
||||||
|
|
29
test/test_trigger.py
Normal file
29
test/test_trigger.py
Normal 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()
|
Reference in a new issue