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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#queue_depthObject (readonly)

Returns the value of attribute queue_depth.



10
11
12
# File 'app/presenters/ci/build_runner_presenter.rb', line 10

def queue_depth
  @queue_depth
end

#queue_sizeObject (readonly)

Returns the value of attribute queue_size.



10
11
12
# File 'app/presenters/ci/build_runner_presenter.rb', line 10

def queue_size
  @queue_size
end

Instance Method Details

#all_dependenciesObject



81
82
83
84
85
# File 'app/presenters/ci/build_runner_presenter.rb', line 81

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

#artifactsObject



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

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



34
35
36
# File 'app/presenters/ci/build_runner_presenter.rb', line 34

def git_depth
  (git_depth_value || project.ci_default_git_depth).to_i
end

#project_jobs_running_on_instance_runners_countObject



87
88
89
90
91
92
93
94
# File 'app/presenters/ci/build_runner_presenter.rb', line 87

def project_jobs_running_on_instance_runners_count
  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



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

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

#refspecsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/presenters/ci/build_runner_presenter.rb', line 66

def refspecs
  specs = []
  specs << refspec_for_persistent_ref

  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

#repo_object_formatObject



38
39
40
# File 'app/presenters/ci/build_runner_presenter.rb', line 38

def repo_object_format
  project.repository_object_format.to_s
end

#runner_inputsObject



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

def runner_inputs
  return [] unless options&.key?(:inputs)

  input_values = inputs.index_by(&:name)

  options.fetch(:inputs, {}).map do |name, spec|
    input_value = input_values[name.to_s]&.value || spec[:default]

    {
      key: name,
      value: {
        content: input_value,
        type: spec[:type]
      }
    }
  end
end

#runner_variablesObject



60
61
62
63
64
# File 'app/presenters/ci/build_runner_presenter.rb', line 60

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

#set_queue_metrics(size:, depth:) ⇒ Object



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

def set_queue_metrics(size:, depth:)
  @queue_size = [0, size.to_i].max
  @queue_depth = [0, depth.to_i].max
end