2750d9406e9f9abf58c44f2f7e139bbd906cedcb
1 from flask
import abort
4 from ui
.gitlab
import api
5 from ui
.models
import Build
, Runner
, db
8 if request
.headers
.get('X-Gitlab-Token', None) != config
.GITLAB_WEBHOOK_TOKEN
:
10 webhook_type
= request
.headers
.get('X-Gitlab-Event')
11 data
= request
.get_json()
12 if webhook_type
== 'Pipeline Hook':
13 pipeline
= data
.get('object_attributes')
14 stages
= data
.get('builds')
15 build
= Build
.get_or_create_by_id(pipeline
.get('id'))
16 build
.build_status
= pipeline
.get('status')
17 build
.build_duration
= pipeline
.get('duration')
18 for variable
in pipeline
.get("variables"):
19 if variable
.get('key') == "VERSION":
20 build
.build_version
= variable
.get("value")
21 elif variable
.get("key") == "DEVICE":
22 build
.build_device
= variable
.get("value")
23 elif variable
.get("key") == "TYPE":
24 build
.build_type
= variable
.get("value")
27 if stage
.get('name') == 'build':
29 runner
= build_stage
.get("runner")
32 build
.build_runner
= Runner
.get_or_create_by_id(runner
.get('id'))
33 if not build
.build_runner
.runner_name
:
34 build
.build_runner
.runner_name
= runner
.get("description")