Class: Ci::Bridge

Inherits:
Processable show all
Includes:
AfterCommitQueue, Contextable, HasRef, Metadatable, Importable
Defined in:
app/models/ci/bridge.rb

Constant Summary collapse

InvalidBridgeTypeError =
Class.new(StandardError)
InvalidTransitionError =
Class.new(StandardError)

Constants included from HasStatus

HasStatus::ACTIVE_STATUSES, HasStatus::AVAILABLE_STATUSES, HasStatus::BLOCKED_STATUS, HasStatus::COMPLETED_STATUSES, HasStatus::DEFAULT_STATUS, HasStatus::EXCLUDE_IGNORED_STATUSES, HasStatus::ORDERED_STATUSES, HasStatus::PASSED_WITH_WARNINGS_STATUSES, HasStatus::STARTED_STATUSES, HasStatus::STATUSES_ENUM, HasStatus::UnknownStatusError

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasRef

#branch?, #git_ref, #ref_slug

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods included from Metadatable

#degenerate!, #degenerated?, #ensure_metadata, #interruptible, #interruptible=, #options, #options=, #yaml_variables, #yaml_variables=

Methods included from Contextable

#deployment_variables, #predefined_variables, #scoped_variables, #scoped_variables_hash, #secret_group_variables, #secret_instance_variables, #secret_project_variables, #simple_variables, #simple_variables_without_dependencies, #user_variables

Methods inherited from Processable

#aggregated_needs_names, #ensure_scheduling_type!, #find_legacy_scheduling_type, #needs_attributes, populate_scheduling_type!, #scheduling_type_dag?, #scoped_variables_hash, select_with_aggregated_needs, #when

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from CommitStatus

#all_met_to_become_pending?, #any_unmet_prerequisites?, #archived?, #auto_canceled?, #cancelable?, #duration, #failed_but_allowed?, #group_name, #has_trace?, #importing?, #latest?, #locking_enabled?, locking_enabled?, names, #playable?, #recoverable?, #requires_resource?, #retryable?, #sortable_name, #stuck?, update_as_processed!

Methods included from BulkInsertableAssociations

#bulk_insert_associations!, bulk_inserts_enabled?, with_bulk_insert

Methods included from Presentable

#present

Methods included from HasStatus

#active?, #blocked?, #complete?, #started?

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.retry(bridge, current_user) ⇒ Object

Raises:

  • (NotImplementedError)

47
48
49
# File 'app/models/ci/bridge.rb', line 47

def self.retry(bridge, current_user)
  raise NotImplementedError
end

.with_preloadsObject


51
52
53
54
55
56
57
# File 'app/models/ci/bridge.rb', line 51

def self.with_preloads
  preload(
    :metadata,
    downstream_pipeline: [project: [:route, { namespace: :route }]],
    project: [:namespace]
  )
end

Instance Method Details

#action?Boolean

Returns:

  • (Boolean)

125
126
127
# File 'app/models/ci/bridge.rb', line 125

def action?
  false
end

#artifacts?Boolean

Returns:

  • (Boolean)

129
130
131
# File 'app/models/ci/bridge.rb', line 129

def artifacts?
  false
end

#dependency_variablesObject


180
181
182
# File 'app/models/ci/bridge.rb', line 180

def dependency_variables
  []
end

#dependent?Boolean

Returns:

  • (Boolean)

164
165
166
167
168
# File 'app/models/ci/bridge.rb', line 164

def dependent?
  strong_memoize(:dependent) do
    options&.dig(:trigger, :strategy) == 'depend'
  end
end

#detailed_status(current_user) ⇒ Object


115
116
117
118
119
# File 'app/models/ci/bridge.rb', line 115

def detailed_status(current_user)
  Gitlab::Ci::Status::Bridge::Factory
    .new(self, current_user)
    .fabricate!
end

#downstream_pipeline_paramsObject


80
81
82
83
84
85
# File 'app/models/ci/bridge.rb', line 80

def downstream_pipeline_params
  return child_params if triggers_child_pipeline?
  return cross_project_params if downstream_project.present?

  {}
end

#downstream_projectObject


87
88
89
90
91
92
93
94
95
# File 'app/models/ci/bridge.rb', line 87

def downstream_project
  strong_memoize(:downstream_project) do
    if downstream_project_path
      ::Project.find_by_full_path(downstream_project_path)
    elsif triggers_child_pipeline?
      project
    end
  end
end

#downstream_project_pathObject


97
98
99
100
101
# File 'app/models/ci/bridge.rb', line 97

def downstream_project_path
  strong_memoize(:downstream_project_path) do
    options&.dig(:trigger, :project)
  end
end

#downstream_variablesObject


170
171
172
173
174
175
176
177
178
# File 'app/models/ci/bridge.rb', line 170

def downstream_variables
  variables = scoped_variables.concat(pipeline.persisted_variables)

  variables.to_runner_variables.yield_self do |all_variables|
    yaml_variables.to_a.map do |hash|
      { key: hash[:key], value: ::ExpandVariables.expand(hash[:value], all_variables) }
    end
  end
end

#execute_hooksObject

Raises:

  • (NotImplementedError)

140
141
142
# File 'app/models/ci/bridge.rb', line 140

def execute_hooks
  raise NotImplementedError
end

#expanded_environment_nameObject


137
138
# File 'app/models/ci/bridge.rb', line 137

def expanded_environment_name
end

#has_downstream_pipeline?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'app/models/ci/bridge.rb', line 76

def has_downstream_pipeline?
  sourced_pipelines.exists?
end

#inherit_status_from_downstream!(pipeline) ⇒ Object


65
66
67
68
69
70
71
72
73
74
# File 'app/models/ci/bridge.rb', line 65

def inherit_status_from_downstream!(pipeline)
  case pipeline.status
  when 'success'
    self.success!
  when 'failed', 'canceled', 'skipped'
    self.drop!
  else
    false
  end
end

#parent_pipelineObject


103
104
105
# File 'app/models/ci/bridge.rb', line 103

def parent_pipeline
  pipeline if triggers_child_pipeline?
end

#runnable?Boolean

Returns:

  • (Boolean)

133
134
135
# File 'app/models/ci/bridge.rb', line 133

def runnable?
  false
end

#schedulable?Boolean

Returns:

  • (Boolean)

121
122
123
# File 'app/models/ci/bridge.rb', line 121

def schedulable?
  false
end

#schedule_downstream_pipeline!Object


59
60
61
62
63
# File 'app/models/ci/bridge.rb', line 59

def schedule_downstream_pipeline!
  raise InvalidBridgeTypeError unless downstream_project

  ::Ci::CreateCrossProjectPipelineWorker.perform_async(self.id)
end

#tagsObject


111
112
113
# File 'app/models/ci/bridge.rb', line 111

def tags
  [:bridge]
end

#target_refObject


155
156
157
158
159
160
161
162
# File 'app/models/ci/bridge.rb', line 155

def target_ref
  branch = options&.dig(:trigger, :branch)
  return unless branch

  scoped_variables.to_runner_variables.yield_self do |all_variables|
    ::ExpandVariables.expand(branch, all_variables)
  end
end

#to_partial_pathObject


144
145
146
# File 'app/models/ci/bridge.rb', line 144

def to_partial_path
  'projects/generic_commit_statuses/generic_commit_status'
end

#triggers_child_pipeline?Boolean

Returns:

  • (Boolean)

107
108
109
# File 'app/models/ci/bridge.rb', line 107

def triggers_child_pipeline?
  yaml_for_downstream.present?
end

#yaml_for_downstreamObject


148
149
150
151
152
153
# File 'app/models/ci/bridge.rb', line 148

def yaml_for_downstream
  strong_memoize(:yaml_for_downstream) do
    includes = options&.dig(:trigger, :include)
    YAML.dump('include' => includes) if includes
  end
end