diff options
author | Oliver Poignant <oliver@poignant.se> | 2016-03-13 23:07:50 +0100 |
---|---|---|
committer | Oliver Poignant <oliver@poignant.se> | 2016-03-13 23:07:50 +0100 |
commit | 2465cfc4a3669282523daf168e8c408880f3dd4d (patch) | |
tree | 18abeadf13559334abe17044f80dea3fa6f3ccbe /gitautodeploy/parsers/github.py | |
parent | 5a8caf8b9c9f4f283dffac33b461b5c43ad64eed (diff) | |
parent | 86ff375bf4c4b6c04ab44ea4be7dd90730f824c1 (diff) | |
download | Git-Auto-Deploy-2465cfc4a3669282523daf168e8c408880f3dd4d.zip Git-Auto-Deploy-2465cfc4a3669282523daf168e8c408880f3dd4d.tar.gz Git-Auto-Deploy-2465cfc4a3669282523daf168e8c408880f3dd4d.tar.bz2 |
Merge pull request #77 from olipo186/developmentv0.2.0
Development
Diffstat (limited to 'gitautodeploy/parsers/github.py')
-rw-r--r-- | gitautodeploy/parsers/github.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gitautodeploy/parsers/github.py b/gitautodeploy/parsers/github.py new file mode 100644 index 0000000..028663d --- /dev/null +++ b/gitautodeploy/parsers/github.py @@ -0,0 +1,45 @@ +from common import WebhookRequestParser + +class GitHubRequestParser(WebhookRequestParser): + + def get_repo_params_from_request(self, request_headers, request_body): + 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.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 + + # 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.info("Pull request to branch '%s' was fired" % ref) + elif 'ref' in data: + ref = data['ref'] + logger.info("Push to branch '%s' was fired" % ref) + + if 'action' in data: + action = data['action'] + logger.info("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
\ No newline at end of file |