Class: CommitStatus

Inherits:
Ci::ApplicationRecord show all
Includes:
AfterCommitQueue, BulkInsertableAssociations, Ci::HasStatus, EnumWithNil, 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::EXCLUDE_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 inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

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?, #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!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.bulk_insert_tags!(statuses) ⇒ Object


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

def self.bulk_insert_tags!(statuses)
  Gitlab::Ci::Tags::BulkInsert.new(statuses).insert!
end

.locking_enabled?Boolean

Returns:

  • (Boolean)

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

def self.locking_enabled?
  false
end

.namesObject


208
209
210
# File 'app/models/commit_status.rb', line 208

def self.names
  select(:name)
end

.update_as_processed!Object


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

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)

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

def all_met_to_become_pending?
  true
end

#archived?Boolean

Returns:

  • (Boolean)

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

def archived?
  false
end

#auto_canceled?Boolean

Returns:

  • (Boolean)

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

def auto_canceled?
  canceled? && auto_canceled_by_id?
end

#cancelable?Boolean

Returns:

  • (Boolean)

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

def cancelable?
  false
end

#detailed_status(current_user) ⇒ Object


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

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

#durationObject

Time spent running.


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

def duration
  calculate_duration(started_at, finished_at)
end

#expire_etag_cache!Object


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

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

#failed_but_allowed?Boolean

Returns:

  • (Boolean)

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

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

#group_nameObject


231
232
233
234
235
236
237
238
239
# File 'app/models/commit_status.rb', line 231

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)

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

def has_trace?
  false
end

#importing?Object

We still create some CommitStatuses outside of CreatePipelineService.

These are pages deployments and external statuses.


107
108
109
110
111
112
113
# File 'app/models/commit_status.rb', line 107

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)

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

def latest?
  !retried?
end

#locking_enabled?Boolean

Returns:

  • (Boolean)

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

def locking_enabled?
  will_save_change_to_status?
end

#playable?Boolean

Returns:

  • (Boolean)

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

def playable?
  false
end

#queued_durationObject

Time spent in the pending state.


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

def queued_duration
  calculate_duration(queued_at, started_at)
end

#recoverable?Boolean

Returns:

  • (Boolean)

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

def recoverable?
  failed? && !unrecoverable_failure?
end

#retryable?Boolean

Returns:

  • (Boolean)

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

def retryable?
  false
end

#sortable_nameObject


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

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

#stuck?Boolean

Returns:

  • (Boolean)

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

def stuck?
  false
end

#update_older_statuses_retried!Object


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

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