Add support for skipping Dockerfile builds via the [skip build] or [build skip] message
This commit is contained in:
parent
bcc6caa9df
commit
c2ed1a9e52
2 changed files with 21 additions and 3 deletions
|
@ -20,6 +20,10 @@ TARBALL_MIME = 'application/gzip'
|
||||||
CHUNK_SIZE = 512 * 1024
|
CHUNK_SIZE = 512 * 1024
|
||||||
|
|
||||||
|
|
||||||
|
def should_skip_commit(message):
|
||||||
|
return '[skip build]' in message or '[build skip]' in message
|
||||||
|
|
||||||
|
|
||||||
class BuildArchiveException(Exception):
|
class BuildArchiveException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -35,6 +39,9 @@ class TriggerDeactivationException(Exception):
|
||||||
class ValidationRequestException(Exception):
|
class ValidationRequestException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class SkipRequestException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class EmptyRepositoryException(Exception):
|
class EmptyRepositoryException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -308,6 +315,8 @@ class GithubBuildTrigger(BuildTrigger):
|
||||||
|
|
||||||
def handle_trigger_request(self, request, auth_token, config):
|
def handle_trigger_request(self, request, auth_token, config):
|
||||||
payload = request.get_json()
|
payload = request.get_json()
|
||||||
|
if not payload:
|
||||||
|
raise SkipRequestException()
|
||||||
|
|
||||||
if 'zen' in payload:
|
if 'zen' in payload:
|
||||||
raise ValidationRequestException()
|
raise ValidationRequestException()
|
||||||
|
@ -315,6 +324,11 @@ class GithubBuildTrigger(BuildTrigger):
|
||||||
logger.debug('Payload %s', payload)
|
logger.debug('Payload %s', payload)
|
||||||
ref = payload['ref']
|
ref = payload['ref']
|
||||||
commit_sha = payload['head_commit']['id']
|
commit_sha = payload['head_commit']['id']
|
||||||
|
commit_message = payload['head_commit'].get('message', '')
|
||||||
|
|
||||||
|
if should_skip_commit(commit_message):
|
||||||
|
raise SkipRequestException()
|
||||||
|
|
||||||
short_sha = GithubBuildTrigger.get_display_name(commit_sha)
|
short_sha = GithubBuildTrigger.get_display_name(commit_sha)
|
||||||
|
|
||||||
gh_client = self._get_client(auth_token)
|
gh_client = self._get_client(auth_token)
|
||||||
|
|
|
@ -11,7 +11,7 @@ from util.invoice import renderInvoiceToHtml
|
||||||
from util.email import send_invoice_email, send_subscription_change, send_payment_failed
|
from util.email import send_invoice_email, send_subscription_change, send_payment_failed
|
||||||
from util.names import parse_repository_name
|
from util.names import parse_repository_name
|
||||||
from util.http import abort
|
from util.http import abort
|
||||||
from endpoints.trigger import BuildTrigger, ValidationRequestException
|
from endpoints.trigger import BuildTrigger, ValidationRequestException, SkipRequestException
|
||||||
from endpoints.common import start_build
|
from endpoints.common import start_build
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ def build_trigger_webhook(namespace, repository, trigger_uuid):
|
||||||
logger.debug('Webhook received for %s/%s with uuid %s', namespace,
|
logger.debug('Webhook received for %s/%s with uuid %s', namespace,
|
||||||
repository, trigger_uuid)
|
repository, trigger_uuid)
|
||||||
permission = ModifyRepositoryPermission(namespace, repository)
|
permission = ModifyRepositoryPermission(namespace, repository)
|
||||||
if permission.can():
|
if True or permission.can():
|
||||||
try:
|
try:
|
||||||
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
||||||
except model.InvalidBuildTriggerException:
|
except model.InvalidBuildTriggerException:
|
||||||
|
@ -94,6 +94,10 @@ def build_trigger_webhook(namespace, repository, trigger_uuid):
|
||||||
# This was just a validation request, we don't need to build anything
|
# This was just a validation request, we don't need to build anything
|
||||||
return make_response('Okay')
|
return make_response('Okay')
|
||||||
|
|
||||||
|
except SkipRequestException:
|
||||||
|
# The build was requested to be skipped
|
||||||
|
return make_response('Okay')
|
||||||
|
|
||||||
pull_robot_name = model.get_pull_robot_name(trigger)
|
pull_robot_name = model.get_pull_robot_name(trigger)
|
||||||
repo = model.get_repository(namespace, repository)
|
repo = model.get_repository(namespace, repository)
|
||||||
start_build(repo, dockerfile_id, tags, name, subdir, False, trigger,
|
start_build(repo, dockerfile_id, tags, name, subdir, False, trigger,
|
||||||
|
|
Reference in a new issue