Write triggers are successfully installing on GitHub, noice!
This commit is contained in:
parent
a6400171b3
commit
86e93a2c0f
7 changed files with 76 additions and 32 deletions
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
import io
|
||||
|
||||
from github import Github
|
||||
from github import Github, UnknownObjectException, GithubException
|
||||
from tempfile import SpooledTemporaryFile
|
||||
|
||||
from app import app
|
||||
|
@ -27,6 +27,9 @@ class InvalidServiceException(Exception):
|
|||
class TriggerActivationException(Exception):
|
||||
pass
|
||||
|
||||
class ValidationRequestException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BuildTrigger(object):
|
||||
def __init__(self):
|
||||
|
@ -97,17 +100,20 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
try:
|
||||
to_add_webhook = gh_client.get_repo(new_build_source)
|
||||
except UnknownObjectException:
|
||||
msg = 'Unable to find GitHub repository for source: %s'
|
||||
raise TriggerActivationException(msg % new_build_source)
|
||||
|
||||
webhook_config = {
|
||||
'url': standard_webhook_url,
|
||||
'content_type': 'json',
|
||||
}
|
||||
webhook_config = {
|
||||
'url': standard_webhook_url,
|
||||
'content_type': 'json',
|
||||
}
|
||||
|
||||
try:
|
||||
to_add_webhook.create_hook('web', webhook_config)
|
||||
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
except GithubException:
|
||||
msg = 'Unable to create webhook on repository: %s'
|
||||
raise TriggerActivationException(msg % new_build_source)
|
||||
|
||||
def list_build_sources(self, auth_token):
|
||||
gh_client = self._get_client(auth_token)
|
||||
|
@ -142,6 +148,10 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
def handle_trigger_request(self, request, auth_token, config):
|
||||
payload = request.get_json()
|
||||
|
||||
if 'zen' in payload:
|
||||
raise ValidationRequestException()
|
||||
|
||||
logger.debug('Payload %s', payload)
|
||||
ref = payload['ref']
|
||||
commit_id = payload['head_commit']['id'][0:7]
|
||||
|
|
Reference in a new issue