2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
module Gitlab
|
|
|
|
module DataBuilder
|
|
|
|
module Pipeline
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def build(pipeline)
|
|
|
|
{
|
|
|
|
object_kind: 'pipeline',
|
|
|
|
object_attributes: hook_attrs(pipeline),
|
|
|
|
user: pipeline.user.try(:hook_attrs),
|
|
|
|
project: pipeline.project.hook_attrs(backward: false),
|
|
|
|
commit: pipeline.commit.try(:hook_attrs),
|
|
|
|
builds: pipeline.builds.map(&method(:build_hook_attrs))
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def hook_attrs(pipeline)
|
|
|
|
{
|
|
|
|
id: pipeline.id,
|
2019-07-07 11:18:12 +05:30
|
|
|
ref: pipeline.source_ref,
|
2016-09-13 17:45:13 +05:30
|
|
|
tag: pipeline.tag,
|
|
|
|
sha: pipeline.sha,
|
|
|
|
before_sha: pipeline.before_sha,
|
|
|
|
status: pipeline.status,
|
2018-03-27 19:54:05 +05:30
|
|
|
detailed_status: pipeline.detailed_status(nil).label,
|
2017-09-10 17:25:29 +05:30
|
|
|
stages: pipeline.stages_names,
|
2016-09-13 17:45:13 +05:30
|
|
|
created_at: pipeline.created_at,
|
|
|
|
finished_at: pipeline.finished_at,
|
2018-12-05 23:21:45 +05:30
|
|
|
duration: pipeline.duration,
|
|
|
|
variables: pipeline.variables.map(&:hook_attrs)
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_hook_attrs(build)
|
|
|
|
{
|
|
|
|
id: build.id,
|
|
|
|
stage: build.stage,
|
|
|
|
name: build.name,
|
|
|
|
status: build.status,
|
|
|
|
created_at: build.created_at,
|
|
|
|
started_at: build.started_at,
|
|
|
|
finished_at: build.finished_at,
|
|
|
|
when: build.when,
|
2017-08-17 22:00:37 +05:30
|
|
|
manual: build.action?,
|
2016-09-13 17:45:13 +05:30
|
|
|
user: build.user.try(:hook_attrs),
|
|
|
|
runner: build.runner && runner_hook_attrs(build.runner),
|
|
|
|
artifacts_file: {
|
2019-07-07 11:18:12 +05:30
|
|
|
filename: build.artifacts_file&.filename,
|
2016-09-13 17:45:13 +05:30
|
|
|
size: build.artifacts_size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def runner_hook_attrs(runner)
|
|
|
|
{
|
|
|
|
id: runner.id,
|
|
|
|
description: runner.description,
|
|
|
|
active: runner.active?,
|
2018-11-08 19:23:39 +05:30
|
|
|
is_shared: runner.instance_type?
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|