Class: Ci::BuildRunnerPresenter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/presenters/ci/build_runner_presenter.rb

Defined Under Namespace

Classes: BuildArtifact

Constant Summary collapse

RUNNER_REMOTE_TAG_PREFIX =
'refs/tags/'
RUNNER_REMOTE_BRANCH_PREFIX =
'refs/remotes/origin/'

Instance Method Summary collapse

Instance Method Details

#all_dependenciesObject

rubocop: disable CodeReuse/ActiveRecord



57
58
59
60
61
# File 'app/presenters/ci/build_runner_presenter.rb', line 57

def all_dependencies
  dependencies = super
  ActiveRecord::Associations::Preloader.new(records: dependencies, associations: :job_artifacts_archive).call
  dependencies
end

#artifactsObject



10
11
12
13
14
15
16
17
# File 'app/presenters/ci/build_runner_presenter.rb', line 10

def artifacts
  return unless options[:artifacts]

  list = []
  list << create_archive(options[:artifacts])
  list << create_reports(options[:artifacts][:reports], expire_in: options[:artifacts][:expire_in])
  list.flatten.compact
end

#git_depthObject



27
28
29
30
31
32
33
# File 'app/presenters/ci/build_runner_presenter.rb', line 27

def git_depth
  if git_depth_variable
    git_depth_variable[:value]
  else
    project.ci_default_git_depth
  end.to_i
end

#project_jobs_running_on_instance_runners_countObject

rubocop: enable CodeReuse/ActiveRecord



64
65
66
67
68
69
70
71
72
# File 'app/presenters/ci/build_runner_presenter.rb', line 64

def project_jobs_running_on_instance_runners_count
  # if not instance runner we don't care about that value and present `+Inf` as a placeholder for Prometheus
  return '+Inf' unless runner.instance_type?

  return project.instance_runner_running_jobs_count.to_s if
    project.instance_runner_running_jobs_count < Project::INSTANCE_RUNNER_RUNNING_JOBS_MAX_BUCKET

  "#{Project::INSTANCE_RUNNER_RUNNING_JOBS_MAX_BUCKET}+"
end

#ref_typeObject



19
20
21
22
23
24
25
# File 'app/presenters/ci/build_runner_presenter.rb', line 19

def ref_type
  if tag
    'tag'
  else
    'branch'
  end
end

#refspecsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/presenters/ci/build_runner_presenter.rb', line 41

def refspecs
  specs = []
  specs << refspec_for_persistent_ref if persistent_ref_exist?

  if git_depth > 0
    specs << refspec_for_branch(ref) if branch? || legacy_detached_merge_request_pipeline?
    specs << refspec_for_tag(ref) if tag?
  else
    specs << refspec_for_branch
    specs << refspec_for_tag
  end

  specs
end

#runner_variablesObject



35
36
37
38
39
# File 'app/presenters/ci/build_runner_presenter.rb', line 35

def runner_variables
  variables
    .sort_and_expand_all(keep_undefined: true, expand_file_refs: false, expand_raw_refs: false)
    .to_runner_variables
end