summaryrefslogtreecommitdiffstats
path: root/gitautodeploy/parsers/gitlabci.py
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2016-12-12 18:35:03 +0100
committerOliver Poignant <oliver@poignant.se>2016-12-12 18:35:03 +0100
commit8c406865ce388c1856f8dab495df4aa11f64f9cd (patch)
treed85ca148d33d9fd7e3fa37f564546e687a17c276 /gitautodeploy/parsers/gitlabci.py
parent30b8b34af911c3b3661f57366f0eeb56bfb5e3ed (diff)
downloadGit-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/gitlabci.py')
-rw-r--r--gitautodeploy/parsers/gitlabci.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/gitautodeploy/parsers/gitlabci.py b/gitautodeploy/parsers/gitlabci.py
index 6b5e3ca..30a8b5f 100644
--- a/gitautodeploy/parsers/gitlabci.py
+++ b/gitautodeploy/parsers/gitlabci.py
@@ -1 +1,29 @@
from common import WebhookRequestParser
+
+class GitLabCIRequestParser(WebhookRequestParser):
+
+ def get_repo_configs(self, request_headers, request_body, action):
+ import json
+
+ data = json.loads(request_body)
+
+ repo_urls = []
+
+ action.log_info('Received event from Gitlab CI')
+
+ if 'repository' not in data:
+ action.log_error("Unable to recognize data format")
+ return []
+
+ # 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['repository']:
+ repo_urls.append(data['repository'][k])
+ else:
+ action.log_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, action)
+
+ return repo_configs