2018-11-05 23:45:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-02 06:06:31 -04:00
|
|
|
module Gitlab
|
|
|
|
module DataBuilder
|
2016-08-12 04:09:29 -04:00
|
|
|
module Pipeline
|
2016-08-12 03:33:28 -04:00
|
|
|
extend self
|
2016-08-02 06:06:31 -04:00
|
|
|
|
|
|
|
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-05-27 02:44:39 -04:00
|
|
|
ref: pipeline.source_ref,
|
2016-08-02 06:06:31 -04:00
|
|
|
tag: pipeline.tag,
|
|
|
|
sha: pipeline.sha,
|
|
|
|
before_sha: pipeline.before_sha,
|
|
|
|
status: pipeline.status,
|
2018-02-18 18:47:37 -05:00
|
|
|
detailed_status: pipeline.detailed_status(nil).label,
|
2017-06-01 05:55:18 -04:00
|
|
|
stages: pipeline.stages_names,
|
2016-08-02 06:06:31 -04:00
|
|
|
created_at: pipeline.created_at,
|
|
|
|
finished_at: pipeline.finished_at,
|
2018-10-01 13:22:41 -04:00
|
|
|
duration: pipeline.duration,
|
|
|
|
variables: pipeline.variables.map(&:hook_attrs)
|
2016-08-02 06:06:31 -04:00
|
|
|
}
|
|
|
|
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-03-03 08:35:19 -05:00
|
|
|
manual: build.action?,
|
2016-08-02 06:06:31 -04:00
|
|
|
user: build.user.try(:hook_attrs),
|
|
|
|
runner: build.runner && runner_hook_attrs(build.runner),
|
|
|
|
artifacts_file: {
|
2019-01-10 04:32:12 -05:00
|
|
|
filename: build.artifacts_file&.filename,
|
2016-08-02 06:06:31 -04:00
|
|
|
size: build.artifacts_size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def runner_hook_attrs(runner)
|
|
|
|
{
|
|
|
|
id: runner.id,
|
|
|
|
description: runner.description,
|
|
|
|
active: runner.active?,
|
2018-06-26 05:36:54 -04:00
|
|
|
is_shared: runner.instance_type?
|
2016-08-02 06:06:31 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|