Class: CommitStatus

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

Direct Known Subclasses

Ci::Processable, GenericCommitStatus

Constant Summary

Constants included from TaggableQueries

TaggableQueries::MAX_TAGS_IDS, TaggableQueries::TooManyTagsError

Constants included from Ci::HasStatus

Ci::HasStatus::ACTIVE_STATUSES, Ci::HasStatus::ALIVE_STATUSES, Ci::HasStatus::AVAILABLE_STATUSES, Ci::HasStatus::BLOCKED_STATUS, Ci::HasStatus::CANCELABLE_STATUSES, Ci::HasStatus::COMPLETED_STATUSES, Ci::HasStatus::DEFAULT_STATUS, Ci::HasStatus::IGNORED_STATUSES, Ci::HasStatus::ORDERED_STATUSES, Ci::HasStatus::PASSED_WITH_WARNINGS_STATUSES, Ci::HasStatus::STARTED_STATUSES, Ci::HasStatus::STATUSES_ENUM, Ci::HasStatus::STOPPED_STATUSES, Ci::HasStatus::UnknownStatusError

Constants included from Ci::Partitionable

Ci::Partitionable::MUTEX

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TaggableQueries

#tags_ids

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?, #incomplete?, #started?

Methods inherited from Ci::ApplicationRecord

model_name, table_name_prefix

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.locking_enabled?Boolean

Returns:

  • (Boolean)


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

def self.locking_enabled?
  false
end

.namesObject



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

def self.names
  select(:name)
end

.switch_table_namesObject



12
13
14
15
16
17
18
# File 'app/models/commit_status.rb', line 12

def self.switch_table_names
  if Gitlab::Utils.to_boolean(ENV['USE_CI_BUILDS_ROUTING_TABLE'])
    :p_ci_builds
  else
    :ci_builds
  end
end

.update_as_processed!Object



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

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)


284
285
286
# File 'app/models/commit_status.rb', line 284

def all_met_to_become_pending?
  true
end

#archived?Boolean

Returns:

  • (Boolean)


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

def archived?
  false
end

#auto_canceled?Boolean

Returns:

  • (Boolean)


288
289
290
# File 'app/models/commit_status.rb', line 288

def auto_canceled?
  canceled? && auto_canceled_by_id?
end

#cancelable?Boolean

Returns:

  • (Boolean)


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

def cancelable?
  false
end

#detailed_status(current_user) ⇒ Object



292
293
294
295
296
# File 'app/models/commit_status.rb', line 292

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

#durationObject

Time spent running.



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

def duration
  calculate_duration(started_at, finished_at)
end

#expire_etag_cache!Object



317
318
319
320
321
# File 'app/models/commit_status.rb', line 317

def expire_etag_cache!
  job_path = Gitlab::Routing.url_helpers.project_build_path(project, id, format: :json)

  Gitlab::EtagCaching::Store.new.touch(job_path)
end

#group_nameObject



236
237
238
239
240
241
242
243
244
# File 'app/models/commit_status.rb', line 236

def group_name
  # [\b\s:] -> whitespace or column
  # (\[.*\])|(\d+[\s:\/\\]+\d+) -> variables/matrix or parallel-jobs numbers
  # {1,3} -> number of times that matches the variables/matrix or parallel-jobs numbers
  #          we limit this to 3 because of possible abuse
  regex = %r{([\b\s:]+((\[.*\])|(\d+[\s:\/\\]+\d+))){1,3}\s*\z}

  name.to_s.sub(regex, '').strip
end

#has_trace?Boolean

Returns:

  • (Boolean)


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

def has_trace?
  false
end

#importing?Object

We still create some CommitStatuses outside of CreatePipelineService.

These are pages deployments and external statuses.



114
115
116
117
118
119
120
121
122
# File 'app/models/commit_status.rb', line 114

before_create unless: :importing? do
  next if Feature.enabled?(:ci_remove_ensure_stage_service, project)

  # 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)


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

def latest?
  !retried?
end

#locking_enabled?Boolean

Returns:

  • (Boolean)


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

def locking_enabled?
  will_save_change_to_status?
end

#playable?Boolean

Returns:

  • (Boolean)


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

def playable?
  false
end

#queued_durationObject

Time spent in the pending state.



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

def queued_duration
  calculate_duration(queued_at, started_at)
end

#recoverable?Boolean

Returns:

  • (Boolean)


304
305
306
# File 'app/models/commit_status.rb', line 304

def recoverable?
  failed? && !unrecoverable_failure?
end

#resource_parentObject

For AiAction



333
334
335
# File 'app/models/commit_status.rb', line 333

def resource_parent
  project
end

#retryable?Boolean

Returns:

  • (Boolean)


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

def retryable?
  false
end

#sortable_nameObject



298
299
300
301
302
# File 'app/models/commit_status.rb', line 298

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

#stage_nameObject



323
324
325
# File 'app/models/commit_status.rb', line 323

def stage_name
  ci_stage&.name
end

#stuck?Boolean

Returns:

  • (Boolean)


276
277
278
# File 'app/models/commit_status.rb', line 276

def stuck?
  false
end

#to_ability_nameObject

For AiAction



328
329
330
# File 'app/models/commit_status.rb', line 328

def to_ability_name
  'build'
end

#update_older_statuses_retried!Object



308
309
310
311
312
313
314
315
# File 'app/models/commit_status.rb', line 308

def update_older_statuses_retried!
  pipeline
    .statuses
    .latest
    .where(name: name)
    .where.not(id: id)
    .update_all(retried: true, processed: true)
end