Class: Types::Ci::JobType

Inherits:
BaseObject
  • Object
show all
Defined in:
app/graphql/types/ci/job_type.rb

Overview

rubocop: disable Graphql/AuthorizeTypes The permission is presented through `StageType` that has its own authorization

Instance Method Summary collapse

Methods inherited from BaseObject

accepts, assignable?, authorization, authorize, authorized?, #current_user

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Instance Method Details

#artifactsObject


114
115
116
117
118
# File 'app/graphql/types/ci/job_type.rb', line 114

def artifacts
  if object.is_a?(::Ci::Build)
    object.job_artifacts
  end
end

#commit_pathObject


168
169
170
# File 'app/graphql/types/ci/job_type.rb', line 168

def commit_path
  ::Gitlab::Routing.url_helpers.project_commit_path(object.project, object.sha)
end

#coverageObject


180
181
182
# File 'app/graphql/types/ci/job_type.rb', line 180

def coverage
  object&.coverage
end

#detailed_statusObject


110
111
112
# File 'app/graphql/types/ci/job_type.rb', line 110

def detailed_status
  object.detailed_status(context[:current_user])
end

#downstream_pipelineObject


102
103
104
# File 'app/graphql/types/ci/job_type.rb', line 102

def downstream_pipeline
  object.downstream_pipeline if object.respond_to?(:downstream_pipeline)
end

#idObject

This class is a secret union! TODO: turn this into an actual union, so that fields can be referenced safely!


160
161
162
163
164
165
166
# File 'app/graphql/types/ci/job_type.rb', line 160

def id
  return unless object.id.present?

  model_name = object.type || ::CommitStatus.name
  id = object.id
  Gitlab::GlobalId.build(model_name: model_name, id: id)
end

#kindObject


92
93
94
95
96
# File 'app/graphql/types/ci/job_type.rb', line 92

def kind
  return ::Ci::Build unless [::Ci::Build, ::Ci::Bridge].include?(object.class)

  object.class
end

#manual_jobObject


184
185
186
# File 'app/graphql/types/ci/job_type.rb', line 184

def manual_job
  object.try(:action?)
end

#pipelineObject


98
99
100
# File 'app/graphql/types/ci/job_type.rb', line 98

def pipeline
  Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Pipeline, object.pipeline_id).find
end

#previous_stage_jobsObject


130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/graphql/types/ci/job_type.rb', line 130

def previous_stage_jobs
  BatchLoader::GraphQL.for([object.pipeline, object.stage_idx - 1]).batch(default_value: []) do |tuples, loader|
    tuples.group_by(&:first).each do |pipeline, keys|
      positions = keys.map(&:second)

      stages = pipeline.stages.by_position(positions)

      stages.each do |stage|
        loader.call([pipeline, stage.position], stage.latest_statuses)
      end
    end
  end
end

#previous_stage_jobs_or_needsObject


120
121
122
123
124
125
126
127
128
# File 'app/graphql/types/ci/job_type.rb', line 120

def previous_stage_jobs_or_needs
  if object.scheduling_type == 'stage'
    Gitlab::Graphql::Lazy.with_value(previous_stage_jobs) do |jobs|
      jobs
    end
  else
    object.needs
  end
end

#ref_nameObject


172
173
174
# File 'app/graphql/types/ci/job_type.rb', line 172

def ref_name
  object&.ref
end

#ref_pathObject


176
177
178
# File 'app/graphql/types/ci/job_type.rb', line 176

def ref_path
  ::Gitlab::Routing.url_helpers.project_commits_path(object.project, ref_name)
end

#stageObject


144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/graphql/types/ci/job_type.rb', line 144

def stage
  ::Gitlab::Graphql::Lazy.with_value(pipeline) do |pl|
    BatchLoader::GraphQL.for([pl, object.stage]).batch do |ids, loader|
      by_pipeline = ids
        .group_by(&:first)
        .transform_values { |grp| grp.map(&:second) }

      by_pipeline.each do |p, names|
        p.stages.by_name(names).each { |s| loader.call([p, s.name], s) }
      end
    end
  end
end

#tagsObject


106
107
108
# File 'app/graphql/types/ci/job_type.rb', line 106

def tags
  object.tags.map(&:name) if object.is_a?(::Ci::Build)
end

#triggeredObject


188
189
190
# File 'app/graphql/types/ci/job_type.rb', line 188

def triggered
  object.try(:trigger_request)
end