diff options
author | Oliver Poignant <oliver@poignant.se> | 2016-12-12 18:35:03 +0100 |
---|---|---|
committer | Oliver Poignant <oliver@poignant.se> | 2016-12-12 18:35:03 +0100 |
commit | 8c406865ce388c1856f8dab495df4aa11f64f9cd (patch) | |
tree | d85ca148d33d9fd7e3fa37f564546e687a17c276 /gitautodeploy/parsers/github.py | |
parent | 30b8b34af911c3b3661f57366f0eeb56bfb5e3ed (diff) | |
download | Git-Auto-Deploy-8c406865ce388c1856f8dab495df4aa11f64f9cd.zip Git-Auto-Deploy-8c406865ce388c1856f8dab495df4aa11f64f9cd.tar.gz Git-Auto-Deploy-8c406865ce388c1856f8dab495df4aa11f64f9cd.tar.bz2 |
Refactoring and preparations for JSON API
Diffstat (limited to 'gitautodeploy/parsers/github.py')
-rw-r--r-- | gitautodeploy/parsers/github.py | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/gitautodeploy/parsers/github.py b/gitautodeploy/parsers/github.py index 4d24648..bede7bb 100644 --- a/gitautodeploy/parsers/github.py +++ b/gitautodeploy/parsers/github.py @@ -2,59 +2,39 @@ from common import WebhookRequestParser class GitHubRequestParser(WebhookRequestParser): - def get_repo_params_from_request(self, request_headers, request_body): + def get_repo_configs(self, request_headers, request_body, action): import json - import logging - logger = logging.getLogger() data = json.loads(request_body) repo_urls = [] - ref = "" - action = "" github_event = 'x-github-event' in request_headers and request_headers['x-github-event'] - logger.debug("Received '%s' event from GitHub" % github_event) + action.log_info("Received '%s' event from GitHub" % github_event) if 'repository' not in data: - logger.error("Unable to recognize data format") - return [], ref or "master", action + action.log_error("Unable to recognize data format") + return [] # One repository may posses multiple URLs for different protocols for k in ['url', 'git_url', 'clone_url', 'ssh_url']: if k in data['repository']: repo_urls.append(data['repository'][k]) - if 'pull_request' in data: - if 'base' in data['pull_request']: - if 'ref' in data['pull_request']['base']: - ref = data['pull_request']['base']['ref'] - logger.debug("Pull request to branch '%s' was fired" % ref) - elif 'ref' in data: - ref = data['ref'] - logger.debug("Push to branch '%s' was fired" % ref) - - if 'action' in data: - action = data['action'] - logger.debug("Action '%s' was fired" % action) - # Get a list of configured repositories that matches the incoming web hook reqeust - repo_configs = self.get_matching_repo_configs(repo_urls) - - return repo_configs, ref or "master", action, repo_urls + repo_configs = self.get_matching_repo_configs(repo_urls, action) - def validate_request(self, request_headers, repo_configs): - import logging + return repo_configs - logger = logging.getLogger() + def validate_request(self, request_headers, repo_configs, action): for repo_config in repo_configs: # Validate secret token if present if 'secret-token' in repo_config and 'x-hub-signature' in request_headers: if not self.verify_signature(repo_config['secret-token'], request_body, request_headers['x-hub-signature']): - logger.info("Request signature does not match the 'secret-token' configured for repository %s." % repo_config['url']) + action.log_info("Request signature does not match the 'secret-token' configured for repository %s." % repo_config['url']) return False return True |