diff options
author | Oliver Poignant <oliver@poignant.se> | 2016-03-06 21:05:20 +0100 |
---|---|---|
committer | Oliver Poignant <oliver@poignant.se> | 2016-03-06 21:05:20 +0100 |
commit | 3f7a830cdadc82f10bad26b060f2701ed08b34a9 (patch) | |
tree | e62af59711f37b88e64b6155aaa57904c3f3e7c7 /gitautodeploy/parsers/github.py | |
parent | ec1f2a28c902855aa470f8523eea33f8aed6a2b5 (diff) | |
download | Git-Auto-Deploy-3f7a830cdadc82f10bad26b060f2701ed08b34a9.zip Git-Auto-Deploy-3f7a830cdadc82f10bad26b060f2701ed08b34a9.tar.gz Git-Auto-Deploy-3f7a830cdadc82f10bad26b060f2701ed08b34a9.tar.bz2 |
Moved files around into new project structure
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..bd20b98 --- /dev/null +++ b/gitautodeploy/parsers/github.py @@ -0,0 +1,45 @@ +from WebhookRequestParser 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 |