assert response.status_code == 200
build = Build.query.filter_by(build_id=1).first()
assert build.build_id == 1
- assert build.build_runner_id == "foobar"
+ assert build.build_runner_id == None
+
+ def test_success(self):
+ with open("tests/pipeline_success.json") as f:
+ response = self.client.post("/webhook", headers={'X-Gitlab-Event': 'Pipeline Hook', 'X-Gitlab-Token': 'secret'}, data=f.read(), content_type='application/json')
+ assert response.status_code == 200
+ runner = Runner.query.filter_by(runner_id="530365").first()
+ build = Build.query.filter_by(build_id=34618162).first()
+ assert build.build_runner.runner_name == "phenom-test"
+ assert build.build_version == "lineage-15.1"
+ assert build.build_device == "FAKE_TEST"
+ print(build.build_status)
+ assert build.build_status == "success"
+ assert build.build_duration == 81
+
+
+ def test_start(self):
+ with open("tests/pipeline_start.json") as f:
+ response = self.client.post("/webhook", headers={'X-Gitlab-Event': 'Pipeline Hook', 'X-Gitlab-Token': 'secret'}, data=f.read(), content_type='application/json')
+ assert response.status_code == 200
+
class TestWeb(UsesModels):
--- /dev/null
+{
+ "object_kind": "pipeline",
+ "object_attributes": {
+ "id": 34618162,
+ "ref": "master",
+ "tag": false,
+ "sha": "e36217f9fbf04f7ac7024a7909332c0e0e2c1599",
+ "before_sha": "0000000000000000000000000000000000000000",
+ "status": "running",
+ "detailed_status": "running",
+ "stages": [
+ "build",
+ "sign"
+ ],
+ "created_at": "2018-10-29 00:01:33 UTC",
+ "finished_at": "2018-10-29 00:04:42 UTC",
+ "duration": 81,
+ "variables": [
+ {
+ "key": "DEVICE",
+ "value": "FAKE_TEST"
+ },
+ {
+ "key": "TYPE",
+ "value": "userdebug"
+ },
+ {
+ "key": "VERSION",
+ "value": "lineage-15.1"
+ }
+ ]
+ },
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "project": {
+ "id": 9081391,
+ "name": "android",
+ "description": "",
+ "web_url": "https://gitlab.com/LineageOS/builder/android",
+ "avatar_url": null,
+ "git_ssh_url": "git@gitlab.com:LineageOS/builder/android.git",
+ "git_http_url": "https://gitlab.com/LineageOS/builder/android.git",
+ "namespace": "LineageOS Builder",
+ "visibility_level": 20,
+ "path_with_namespace": "LineageOS/builder/android",
+ "default_branch": "master",
+ "ci_config_path": ""
+ },
+ "commit": {
+ "id": "e36217f9fbf04f7ac7024a7909332c0e0e2c1599",
+ "message": "sleep is for the weak\\n",
+ "timestamp": "2018-10-27T07:26:39Z",
+ "url": "https://gitlab.com/LineageOS/builder/android/commit/e36217f9fbf04f7ac7024a7909332c0e0e2c1599",
+ "author": {
+ "name": "Tom Powell",
+ "email": "tom@powell.io"
+ }
+ },
+ "builds": [
+ {
+ "id": 113643062,
+ "stage": "build",
+ "name": "build",
+ "status": "pending",
+ "created_at": "2018-10-29 00:11:14 UTC",
+ "started_at": null,
+ "finished_at": null,
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": null,
+ "artifacts_file": {
+ "filename": null,
+ "size": 0
+ }
+ },
+ {
+ "id": 113642275,
+ "stage": "build",
+ "name": "build",
+ "status": "success",
+ "created_at": "2018-10-29 00:03:41 UTC",
+ "started_at": "2018-10-29 00:03:41 UTC",
+ "finished_at": "2018-10-29 00:04:42 UTC",
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": {
+ "id": 530365,
+ "description": "phenom-test",
+ "active": true,
+ "is_shared": false
+ },
+ "artifacts_file": {
+ "filename": null,
+ "size": 1075
+ }
+ },
+ {
+ "id": 113642098,
+ "stage": "build",
+ "name": "build",
+ "status": "success",
+ "created_at": "2018-10-29 00:01:33 UTC",
+ "started_at": "2018-10-29 00:01:33 UTC",
+ "finished_at": "2018-10-29 00:02:35 UTC",
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": {
+ "id": 530365,
+ "description": "phenom-test",
+ "active": true,
+ "is_shared": false
+ },
+ "artifacts_file": {
+ "filename": null,
+ "size": 1075
+ }
+ },
+ {
+ "id": 113642099,
+ "stage": "sign",
+ "name": "sign",
+ "status": "success",
+ "created_at": "2018-10-29 00:01:33 UTC",
+ "started_at": "2018-10-29 00:02:35 UTC",
+ "finished_at": "2018-10-29 00:02:55 UTC",
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": {
+ "id": 380987,
+ "description": "shared-runners-manager-6.gitlab.com",
+ "active": true,
+ "is_shared": true
+ },
+ "artifacts_file": {
+ "filename": null,
+ "size": 1345
+ }
+ }
+ ]
+}
--- /dev/null
+{
+ "object_kind": "pipeline",
+ "object_attributes": {
+ "id": 34618162,
+ "ref": "master",
+ "tag": false,
+ "sha": "e36217f9fbf04f7ac7024a7909332c0e0e2c1599",
+ "before_sha": "0000000000000000000000000000000000000000",
+ "status": "success",
+ "detailed_status": "passed",
+ "stages": [
+ "build",
+ "sign"
+ ],
+ "created_at": "2018-10-29 00:01:33 UTC",
+ "finished_at": "2018-10-29 00:12:16 UTC",
+ "duration": 81,
+ "variables": [
+ {
+ "key": "DEVICE",
+ "value": "FAKE_TEST"
+ },
+ {
+ "key": "TYPE",
+ "value": "userdebug"
+ },
+ {
+ "key": "VERSION",
+ "value": "lineage-15.1"
+ }
+ ]
+ },
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "project": {
+ "id": 9081391,
+ "name": "android",
+ "description": "",
+ "web_url": "https://gitlab.com/LineageOS/builder/android",
+ "avatar_url": null,
+ "git_ssh_url": "git@gitlab.com:LineageOS/builder/android.git",
+ "git_http_url": "https://gitlab.com/LineageOS/builder/android.git",
+ "namespace": "LineageOS Builder",
+ "visibility_level": 20,
+ "path_with_namespace": "LineageOS/builder/android",
+ "default_branch": "master",
+ "ci_config_path": ""
+ },
+ "commit": {
+ "id": "e36217f9fbf04f7ac7024a7909332c0e0e2c1599",
+ "message": "sleep is for the weak\\n",
+ "timestamp": "2018-10-27T07:26:39Z",
+ "url": "https://gitlab.com/LineageOS/builder/android/commit/e36217f9fbf04f7ac7024a7909332c0e0e2c1599",
+ "author": {
+ "name": "Tom Powell",
+ "email": "tom@powell.io"
+ }
+ },
+ "builds": [
+ {
+ "id": 113643062,
+ "stage": "build",
+ "name": "build",
+ "status": "success",
+ "created_at": "2018-10-29 00:11:14 UTC",
+ "started_at": "2018-10-29 00:11:15 UTC",
+ "finished_at": "2018-10-29 00:12:16 UTC",
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": {
+ "id": 530365,
+ "description": "phenom-test",
+ "active": true,
+ "is_shared": false
+ },
+ "artifacts_file": {
+ "filename": null,
+ "size": 0
+ }
+ },
+ {
+ "id": 113642275,
+ "stage": "build",
+ "name": "build",
+ "status": "success",
+ "created_at": "2018-10-29 00:03:41 UTC",
+ "started_at": "2018-10-29 00:03:41 UTC",
+ "finished_at": "2018-10-29 00:04:42 UTC",
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": {
+ "id": 530365,
+ "description": "phenom-test",
+ "active": true,
+ "is_shared": false
+ },
+ "artifacts_file": {
+ "filename": null,
+ "size": 1075
+ }
+ },
+ {
+ "id": 113642098,
+ "stage": "build",
+ "name": "build",
+ "status": "success",
+ "created_at": "2018-10-29 00:01:33 UTC",
+ "started_at": "2018-10-29 00:01:33 UTC",
+ "finished_at": "2018-10-29 00:02:35 UTC",
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": {
+ "id": 530365,
+ "description": "phenom-test",
+ "active": true,
+ "is_shared": false
+ },
+ "artifacts_file": {
+ "filename": null,
+ "size": 1075
+ }
+ },
+ {
+ "id": 113642099,
+ "stage": "sign",
+ "name": "sign",
+ "status": "success",
+ "created_at": "2018-10-29 00:01:33 UTC",
+ "started_at": "2018-10-29 00:02:35 UTC",
+ "finished_at": "2018-10-29 00:02:55 UTC",
+ "when": "on_success",
+ "manual": false,
+ "user": {
+ "name": "Tom Powell",
+ "username": "zifnab06",
+ "avatar_url": "https://secure.gravatar.com/avatar/40b74a6668897c1bbc7849defa0559ce?s=80&d=identicon"
+ },
+ "runner": {
+ "id": 380987,
+ "description": "shared-runners-manager-6.gitlab.com",
+ "active": true,
+ "is_shared": true
+ },
+ "artifacts_file": {
+ "filename": null,
+ "size": 1345
+ }
+ }
+ ]
+}
"username": "root",
"avatar_url": ""
},
- "runner": "foobar"
+ "runner": null
},
{
"id": 377,
"name": "sign",
"status": "success",
"created_at": "2016-08-12 15:23:28 UTC",
- "runner": "foobar"
+ "runner": null
}
]
}
pipeline = data.get('object_attributes')
stages = data.get('builds')
build = Build.get_or_create_by_id(pipeline.get('id'))
- build.status = pipeline.get('status')
- build.duration = pipeline.get('duration')
+ build.build_status = pipeline.get('status')
+ build.build_duration = pipeline.get('duration')
for variable in pipeline.get("variables"):
if variable.get('key') == "VERSION":
build.build_version = variable.get("value")
for stage in stages:
if stage.get('name') == 'build':
build_stage = stage
- if build_stage.get("runner"):
- build.build_runner = Runner.get_or_create_by_id(build_stage['runner'])
+ runner = build_stage.get("runner")
+ print(type(runner))
+ if runner:
+ build.build_runner = Runner.get_or_create_by_id(runner.get('id'))
+ if not build.build_runner.runner_name:
+ build.build_runner.runner_name = runner.get("description")
db.session.add(build)
db.session.commit()
--- /dev/null
+"""add duration
+
+Revision ID: 448614888e24
+Revises: c3a5cacf3bff
+Create Date: 2018-10-28 17:34:59.818607
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '448614888e24'
+down_revision = 'c3a5cacf3bff'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('build', sa.Column('build_duration', sa.Integer(), nullable=True))
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table('build') as batch_op:
+ batch_op.drop_column('build_duration')
+# op.drop_column('build', 'build_duration')
+ # ### end Alembic commands ###
build_version = db.Column(db.String)
build_type = db.Column(db.String)
build_date = db.Column(db.Date)
+ build_duration = db.Column(db.Integer)
build_runner_id = db.Column(db.String, db.ForeignKey('runner.runner_id'))
build_runner = db.relationship('Runner', backref=db.backref('builds', lazy=True))