summaryrefslogtreecommitdiffstats
path: root/gitautodeploy/parsers/gitlab.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/gitlab.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/gitlab.py')
-rw-r--r--gitautodeploy/parsers/gitlab.py73
1 files changed, 8 insertions, 65 deletions
diff --git a/gitautodeploy/parsers/gitlab.py b/gitautodeploy/parsers/gitlab.py
index 68a1982..5d0d348 100644
--- a/gitautodeploy/parsers/gitlab.py
+++ b/gitautodeploy/parsers/gitlab.py
@@ -2,47 +2,32 @@ from common import WebhookRequestParser
class GitLabRequestParser(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 = ""
gitlab_event = 'x-gitlab-event' in request_headers and request_headers['x-gitlab-event']
- logger.debug("Received '%s' event from GitLab" % gitlab_event)
+ action.log_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
+ action.log_error("Unable to recognize data format")
+ return []
# 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])
- # extract the branch
- if 'ref' in data:
- ref = data['ref']
-
- # set the action
- if 'object_kind' in data:
- action = data['object_kind']
-
# 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:
@@ -50,49 +35,7 @@ class GitLabRequestParser(WebhookRequestParser):
if 'secret-token' in repo_config and 'x-gitlab-token' in request_headers:
if repo_config['secret-token'] != request_headers['x-gitlab-token']:
- logger.info("Request token does not match the 'secret-token' configured for repository %s." % repo_config['url'])
+ action.log_info("Request token does not match the 'secret-token' configured for repository %s." % repo_config['url'])
return False
return True
-
-
-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.debug('Received event from Gitlab CI')
-
- if 'repository' 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['repository']:
- repo_urls.append(data['repository'][k])
- else:
- logger.warning("Gitlab CI build '%d' has status '%s'. Not pull will be done" % (
- data['build_id'], data['build_status']))
-
- # extract the branch
- if 'ref' in data:
- ref = data['ref']
-
- # set the action
- if 'object_kind' in data:
- action = data['object_kind']
-
- # 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