Class: CommitStatus

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, BulkInsertableAssociations, Ci::HasStatus, EnumWithNil, Importable, Presentable
Defined in:
app/models/commit_status.rb

Direct Known Subclasses

Ci::Processable, GenericCommitStatus

Constant Summary

Constants included from Ci::HasStatus

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

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BulkInsertableAssociations

#bulk_insert_associations!, bulk_inserts_enabled?, with_bulk_insert

Methods included from Presentable

#present

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods included from Ci::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, where_exists, with_fast_statement_timeout, without_order

Class Method Details

.locking_enabled?Boolean

Returns:

  • (Boolean)

196
197
198
# File 'app/models/commit_status.rb', line 196

def self.locking_enabled?
  false
end

.namesObject


185
186
187
# File 'app/models/commit_status.rb', line 185

def self.names
  select(:name)
end

.update_as_processed!Object


189
190
191
192
193
194
# File 'app/models/commit_status.rb', line 189

def self.update_as_processed!
  # Marks items as processed
  # we do not increase `lock_version`, as we are the one
  # holding given lock_version (Optimisitc Locking)
  update_all(processed: true)
end

Instance Method Details

#all_met_to_become_pending?Boolean

Returns:

  • (Boolean)

251
252
253
# File 'app/models/commit_status.rb', line 251

def all_met_to_become_pending?
  !any_unmet_prerequisites? && !requires_resource?
end

#any_unmet_prerequisites?Boolean

Returns:

  • (Boolean)

255
256
257
# File 'app/models/commit_status.rb', line 255

def any_unmet_prerequisites?
  false
end

#archived?Boolean

Returns:

  • (Boolean)

239
240
241
# File 'app/models/commit_status.rb', line 239

def archived?
  false
end

#auto_canceled?Boolean

Returns:

  • (Boolean)

263
264
265
# File 'app/models/commit_status.rb', line 263

def auto_canceled?
  canceled? && auto_canceled_by_id?
end

#cancelable?Boolean

Returns:

  • (Boolean)

235
236
237
# File 'app/models/commit_status.rb', line 235

def cancelable?
  false
end

#detailed_status(current_user) ⇒ Object


267
268
269
270
271
# File 'app/models/commit_status.rb', line 267

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

#durationObject


219
220
221
# File 'app/models/commit_status.rb', line 219

def duration
  calculate_duration
end

#failed_but_allowed?Boolean

Returns:

  • (Boolean)

215
216
217
# File 'app/models/commit_status.rb', line 215

def failed_but_allowed?
  allow_failure? && (failed? || canceled?)
end

#group_nameObject


204
205
206
207
208
209
210
211
212
213
# File 'app/models/commit_status.rb', line 204

def group_name
  # 'rspec:linux: 1/10' => 'rspec:linux'
  common_name = name.to_s.gsub(%r{\d+[\s:\/\\]+\d+\s*}, '')

  # 'rspec:linux: [aws, max memory]' => 'rspec:linux', 'rspec:linux: [aws]' => 'rspec:linux'
  common_name.gsub!(%r{: \[.*\]\s*\z}, '')

  common_name.strip!
  common_name
end

#has_trace?Boolean

Returns:

  • (Boolean)

247
248
249
# File 'app/models/commit_status.rb', line 247

def has_trace?
  false
end

#importing?Object

We still create some CommitStatuses outside of CreatePipelineService.

These are pages deployments and external statuses.


92
93
94
95
96
97
98
# File 'app/models/commit_status.rb', line 92

before_create unless: :importing? do
  # rubocop: disable CodeReuse/ServiceClass
  Ci::EnsureStageService.new(project, user).execute(self) do |stage|
    self.run_after_commit { StageUpdateWorker.perform_async(stage.id) }
  end
  # rubocop: enable CodeReuse/ServiceClass
end

#latest?Boolean

Returns:

  • (Boolean)

223
224
225
# File 'app/models/commit_status.rb', line 223

def latest?
  !retried?
end

#locking_enabled?Boolean

Returns:

  • (Boolean)

200
201
202
# File 'app/models/commit_status.rb', line 200

def locking_enabled?
  will_save_change_to_status?
end

#playable?Boolean

Returns:

  • (Boolean)

227
228
229
# File 'app/models/commit_status.rb', line 227

def playable?
  false
end

#recoverable?Boolean

Returns:

  • (Boolean)

279
280
281
# File 'app/models/commit_status.rb', line 279

def recoverable?
  failed? && !unrecoverable_failure?
end

#requires_resource?Boolean

Returns:

  • (Boolean)

259
260
261
# File 'app/models/commit_status.rb', line 259

def requires_resource?
  false
end

#retryable?Boolean

Returns:

  • (Boolean)

231
232
233
# File 'app/models/commit_status.rb', line 231

def retryable?
  false
end

#sortable_nameObject


273
274
275
276
277
# File 'app/models/commit_status.rb', line 273

def sortable_name
  name.to_s.split(/(\d+)/).map do |v|
    v =~ /\d+/ ? v.to_i : v
  end
end

#stuck?Boolean

Returns:

  • (Boolean)

243
244
245
# File 'app/models/commit_status.rb', line 243

def stuck?
  false
end