diff options
-rw-r--r-- | gitautodeploy/httpserver.py | 13 | ||||
-rw-r--r-- | gitautodeploy/parsers/gitlab.py | 16 |
2 files changed, 18 insertions, 11 deletions
diff --git a/gitautodeploy/httpserver.py b/gitautodeploy/httpserver.py index 8032556..d9310d1 100644 --- a/gitautodeploy/httpserver.py +++ b/gitautodeploy/httpserver.py @@ -131,7 +131,11 @@ class WebhookRequestHandler(BaseHTTPRequestHandler): # Assume GitLab if the X-Gitlab-Event HTTP header is set if 'x-gitlab-event' in request_headers: - return parsers.GitLabRequestParser + # Special Case for Gitlab CI + if content_type == "application/json" and "build_status" in data: + return parsers.GitLabCIRequestParser + else: + return parsers.GitLabRequestParser # Assume GitHub if the X-GitHub-Event HTTP header is set elif 'x-github-event' in request_headers: @@ -144,11 +148,6 @@ class WebhookRequestHandler(BaseHTTPRequestHandler): return parsers.BitBucketRequestParser - # Special Case for Gitlab CI - elif content_type == "application/json" and "build_status" in data: - - return parsers.GitLabCIRequestParser - # This handles old GitLab requests and Gogs requests for example. elif content_type == "application/json": @@ -305,4 +304,4 @@ class WebhookRequestHandler(BaseHTTPRequestHandler): file = open(target, 'w') file.write(json.dumps(test_case, sort_keys=True, indent=4)) - file.close()
\ No newline at end of file + file.close() diff --git a/gitautodeploy/parsers/gitlab.py b/gitautodeploy/parsers/gitlab.py index 3551dc6..86c05fa 100644 --- a/gitautodeploy/parsers/gitlab.py +++ b/gitautodeploy/parsers/gitlab.py @@ -55,20 +55,28 @@ class GitLabCIRequestParser(WebhookRequestParser): logger.debug('Received event from Gitlab CI') - if 'push_data' not in data: + 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['push_data']['repository']: - repo_urls.append(data['push_data']['repository'][k]) + 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
\ No newline at end of file + return repo_configs, ref or "master", action, repo_urls |