blob: eebf2bd2a3428ffa584ca9d303f3886184ce8e93 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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']:
for n in ['repository', 'project']:
if n in data and k in data[n]:
repo_urls.append(data[n][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
|