Module: Gitlab::DataBuilder::Pipeline

Extended by:
Pipeline
Included in:
Pipeline
Defined in:
lib/gitlab/data_builder/pipeline.rb

Instance Method Summary collapse

Instance Method Details

#build(pipeline) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gitlab/data_builder/pipeline.rb', line 8

def build(pipeline)
  {
    object_kind: 'pipeline',
    object_attributes: hook_attrs(pipeline),
    merge_request: pipeline.merge_request && merge_request_attrs(pipeline.merge_request),
    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

#build_hook_attrs(build) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gitlab/data_builder/pipeline.rb', line 53

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,
    manual: build.action?,
    allow_failure: build.allow_failure,
    user: build.user.try(:hook_attrs),
    runner: build.runner && runner_hook_attrs(build.runner),
    artifacts_file: {
      filename: build.artifacts_file&.filename,
      size: build.artifacts_size
    }
  }
end

#hook_attrs(pipeline) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gitlab/data_builder/pipeline.rb', line 20

def hook_attrs(pipeline)
  {
    id: pipeline.id,
    ref: pipeline.source_ref,
    tag: pipeline.tag,
    sha: pipeline.sha,
    before_sha: pipeline.before_sha,
    source: pipeline.source,
    status: pipeline.status,
    detailed_status: pipeline.detailed_status(nil).label,
    stages: pipeline.stages_names,
    created_at: pipeline.created_at,
    finished_at: pipeline.finished_at,
    duration: pipeline.duration,
    variables: pipeline.variables.map(&:hook_attrs)
  }
end

#merge_request_attrs(merge_request) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitlab/data_builder/pipeline.rb', line 38

def merge_request_attrs(merge_request)
  {
    id: merge_request.id,
    iid: merge_request.iid,
    title: merge_request.title,
    source_branch: merge_request.source_branch,
    source_project_id: merge_request.source_project_id,
    target_branch: merge_request.target_branch,
    target_project_id: merge_request.target_project_id,
    state: merge_request.state,
    merge_status: merge_request.public_merge_status,
    url: Gitlab::UrlBuilder.build(merge_request)
  }
end

#runner_hook_attrs(runner) ⇒ Object


74
75
76
77
78
79
80
81
# File 'lib/gitlab/data_builder/pipeline.rb', line 74

def runner_hook_attrs(runner)
  {
    id: runner.id,
    description: runner.description,
    active: runner.active?,
    is_shared: runner.instance_type?
  }
end