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, without_order

Class Method Details

.locking_enabled?Boolean

Returns:

  • (Boolean)

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

def self.locking_enabled?
  false
end

.namesObject


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

def self.names
  select(:name)
end

.update_as_processed!Object


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

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)

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

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

#any_unmet_prerequisites?Boolean

Returns:

  • (Boolean)

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

def any_unmet_prerequisites?
  false
end

#archived?Boolean

Returns:

  • (Boolean)

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

def archived?
  false
end

#auto_canceled?Boolean

Returns:

  • (Boolean)

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

def auto_canceled?
  canceled? && auto_canceled_by_id?
end

#cancelable?Boolean

Returns:

  • (Boolean)

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

def cancelable?
  false
end

#detailed_status(current_user) ⇒ Object


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

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

#durationObject


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

def duration
  calculate_duration
end

#failed_but_allowed?Boolean

Returns:

  • (Boolean)

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

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

#group_nameObject


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

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'
  common_name.gsub!(%r{: \[.*, .*\]\s*\z}, '')

  common_name.strip!
  common_name
end

#has_trace?Boolean

Returns:

  • (Boolean)

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

def has_trace?
  false
end

#importing?Object

We still create some CommitStatuses outside of CreatePipelineService.

These are pages deployments and external statuses.


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

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)

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

def latest?
  !retried?
end

#locking_enabled?Boolean

Returns:

  • (Boolean)

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

def locking_enabled?
  will_save_change_to_status?
end

#playable?Boolean

Returns:

  • (Boolean)

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

def playable?
  false
end

#recoverable?Boolean

Returns:

  • (Boolean)

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

def recoverable?
  failed? && !unrecoverable_failure?
end

#requires_resource?Boolean

Returns:

  • (Boolean)

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

def requires_resource?
  false
end

#retryable?Boolean

Returns:

  • (Boolean)

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

def retryable?
  false
end

#sortable_nameObject


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

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

#stuck?Boolean

Returns:

  • (Boolean)

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

def stuck?
  false
end