summaryrefslogtreecommitdiffstats
path: root/gitautodeploy/parsers/gitlab.py
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2016-03-06 21:32:40 +0100
committerOliver Poignant <oliver@poignant.se>2016-03-06 21:32:40 +0100
commit92661088c7a61f3f53c4aa56bc5f7257a6487075 (patch)
treed7c4be5cca73ec48bafa9086f99fcd74e8976bba /gitautodeploy/parsers/gitlab.py
parent7b0379c66dc3c5268f60defce767e9a7893995b4 (diff)
parentedaec6df3c2b3b9c32b63b97c620b9ce204a21ed (diff)
downloadGit-Auto-Deploy-92661088c7a61f3f53c4aa56bc5f7257a6487075.zip
Git-Auto-Deploy-92661088c7a61f3f53c4aa56bc5f7257a6487075.tar.gz
Git-Auto-Deploy-92661088c7a61f3f53c4aa56bc5f7257a6487075.tar.bz2
Merge pull request #73 from olipo186/development-two
Moved files around into new project structure. Work in progress.
Diffstat (limited to 'gitautodeploy/parsers/gitlab.py')
-rw-r--r--gitautodeploy/parsers/gitlab.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/gitautodeploy/parsers/gitlab.py b/gitautodeploy/parsers/gitlab.py
new file mode 100644
index 0000000..7a8e374
--- /dev/null
+++ b/gitautodeploy/parsers/gitlab.py
@@ -0,0 +1,66 @@
+from WebhookRequestParser import WebhookRequestParser
+
+class GitLabRequestParser(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 = ""
+
+ gitlab_event = 'x-gitlab-event' in request_headers and request_headers['x-gitlab-event']
+
+ logger.info("Received '%s' event from GitLab" % gitlab_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_http_url', 'git_ssh_url']:
+ if k in data['repository']:
+ repo_urls.append(data['repository'][k])
+
+ # 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
+
+
+class GitLabCIRequestParser(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 = ""
+
+ logger.info('Received event from Gitlab CI')
+
+ if 'push_data' not in data:
+ logger.error("Unable to recognize data format")
+ return [], ref or "master", action
+
+ # Only add repositories if the build is successful. Ignore it in other case.
+ if data['build_status'] == "success":
+ for k in ['url', 'git_http_url', 'git_ssh_url']:
+ if k in data['push_data']['repository']:
+ repo_urls.append(data['push_data']['repository'][k])
+ else:
+ logger.warning("Gitlab CI build '%d' has status '%s'. Not pull will be done" % (
+ data['build_id'], data['build_status']))
+
+ # 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