2015-10-06 06:01:16 -04:00
|
|
|
class CommitStatus < ActiveRecord::Base
|
2016-08-24 22:55:32 -04:00
|
|
|
include HasStatus
|
2016-06-13 07:34:36 -04:00
|
|
|
include Importable
|
2016-10-07 08:52:30 -04:00
|
|
|
include AfterCommitQueue
|
2016-03-31 13:51:28 -04:00
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
self.table_name = 'ci_builds'
|
|
|
|
|
2017-03-17 19:06:11 -04:00
|
|
|
belongs_to :project
|
2016-08-11 09:22:35 -04:00
|
|
|
belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :commit_id
|
2015-10-06 06:01:16 -04:00
|
|
|
belongs_to :user
|
|
|
|
|
2016-06-21 08:43:37 -04:00
|
|
|
delegate :commit, to: :pipeline
|
2017-02-22 17:35:08 -05:00
|
|
|
delegate :sha, :short_sha, to: :pipeline
|
2016-06-21 08:43:37 -04:00
|
|
|
|
2016-06-13 07:34:36 -04:00
|
|
|
validates :pipeline, presence: true, unless: :importing?
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2017-02-21 19:40:04 -05:00
|
|
|
validates :name, presence: true
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2015-10-12 06:15:48 -04:00
|
|
|
alias_attribute :author, :user
|
|
|
|
|
2016-07-20 13:10:08 -04:00
|
|
|
scope :latest, -> do
|
|
|
|
max_id = unscope(:select).select("max(#{quoted_table_name}.id)")
|
|
|
|
|
|
|
|
where(id: max_id.group(:name, :commit_id))
|
|
|
|
end
|
2016-08-10 10:45:30 -04:00
|
|
|
|
2016-10-03 06:22:51 -04:00
|
|
|
scope :failed_but_allowed, -> do
|
2017-03-06 08:43:32 -05:00
|
|
|
where(allow_failure: true, status: [:failed, :canceled])
|
2016-10-03 06:22:51 -04:00
|
|
|
end
|
2016-10-03 06:33:43 -04:00
|
|
|
|
2016-10-03 06:22:51 -04:00
|
|
|
scope :exclude_ignored, -> do
|
2017-03-06 08:43:32 -05:00
|
|
|
# We want to ignore failed but allowed to fail jobs.
|
|
|
|
#
|
|
|
|
# TODO, we also skip ignored optional manual actions.
|
2016-10-04 12:10:23 -04:00
|
|
|
where("allow_failure = ? OR status IN (?)",
|
2017-03-03 08:35:19 -05:00
|
|
|
false, all_state_names - [:failed, :canceled, :manual])
|
2016-10-03 06:22:51 -04:00
|
|
|
end
|
2016-10-03 06:33:43 -04:00
|
|
|
|
2017-02-14 05:38:19 -05:00
|
|
|
scope :retried, -> { where.not(id: latest) }
|
|
|
|
scope :ordered, -> { order(:name) }
|
2016-12-05 08:17:42 -05:00
|
|
|
scope :latest_ordered, -> { latest.ordered.includes(project: :namespace) }
|
|
|
|
scope :retried_ordered, -> { retried.ordered.includes(project: :namespace) }
|
2017-02-14 05:38:19 -05:00
|
|
|
scope :after_stage, -> (index) { where('stage_idx > ?', index) }
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-08-11 09:22:35 -04:00
|
|
|
state_machine :status do
|
2016-08-12 07:57:58 -04:00
|
|
|
event :enqueue do
|
2017-03-03 08:35:19 -05:00
|
|
|
transition [:created, :skipped, :manual] => :pending
|
2016-07-18 08:57:24 -04:00
|
|
|
end
|
|
|
|
|
2016-08-18 17:36:54 -04:00
|
|
|
event :process do
|
2017-03-03 08:35:19 -05:00
|
|
|
transition [:skipped, :manual] => :created
|
2016-08-18 17:36:54 -04:00
|
|
|
end
|
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
event :run do
|
|
|
|
transition pending: :running
|
|
|
|
end
|
|
|
|
|
2016-08-11 09:22:35 -04:00
|
|
|
event :skip do
|
|
|
|
transition [:created, :pending] => :skipped
|
|
|
|
end
|
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
event :drop do
|
2016-08-11 09:22:35 -04:00
|
|
|
transition [:created, :pending, :running] => :failed
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
event :success do
|
2016-08-11 09:22:35 -04:00
|
|
|
transition [:created, :pending, :running] => :success
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
event :cancel do
|
2017-03-03 08:35:19 -05:00
|
|
|
transition [:created, :pending, :running, :manual] => :canceled
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2016-10-26 05:34:40 -04:00
|
|
|
before_transition created: [:pending, :running] do |commit_status|
|
|
|
|
commit_status.queued_at = Time.now
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2016-10-26 05:34:40 -04:00
|
|
|
before_transition [:created, :pending] => :running do |commit_status|
|
|
|
|
commit_status.started_at = Time.now
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2016-10-26 05:34:40 -04:00
|
|
|
before_transition any => [:success, :failed, :canceled] do |commit_status|
|
|
|
|
commit_status.finished_at = Time.now
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2016-09-19 08:13:08 -04:00
|
|
|
after_transition do |commit_status, transition|
|
2016-10-12 09:21:11 -04:00
|
|
|
next if transition.loopback?
|
2016-10-08 14:42:09 -04:00
|
|
|
|
2016-10-08 14:25:16 -04:00
|
|
|
commit_status.run_after_commit do
|
|
|
|
pipeline.try do |pipeline|
|
2017-03-03 08:35:19 -05:00
|
|
|
if complete? || manual?
|
2016-10-12 05:52:54 -04:00
|
|
|
PipelineProcessWorker.perform_async(pipeline.id)
|
2016-10-08 14:25:16 -04:00
|
|
|
else
|
2016-10-12 05:52:54 -04:00
|
|
|
PipelineUpdateWorker.perform_async(pipeline.id)
|
2016-10-08 14:25:16 -04:00
|
|
|
end
|
2016-10-03 10:30:11 -04:00
|
|
|
end
|
2016-09-19 09:03:51 -04:00
|
|
|
end
|
2016-09-19 08:13:08 -04:00
|
|
|
end
|
|
|
|
|
2016-03-08 13:22:50 -05:00
|
|
|
after_transition any => :failed do |commit_status|
|
2016-10-08 14:25:16 -04:00
|
|
|
commit_status.run_after_commit do
|
2017-02-22 17:54:59 -05:00
|
|
|
MergeRequests::AddTodoWhenBuildFailsService
|
|
|
|
.new(pipeline.project, nil).execute(self)
|
2016-10-08 14:25:16 -04:00
|
|
|
end
|
2016-03-08 13:22:50 -05:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2016-04-16 15:46:26 -04:00
|
|
|
def before_sha
|
2016-06-03 07:09:49 -04:00
|
|
|
pipeline.before_sha || Gitlab::Git::BLANK_SHA
|
2016-04-16 15:46:26 -04:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-09-07 08:52:13 -04:00
|
|
|
def group_name
|
2016-09-14 09:04:12 -04:00
|
|
|
name.gsub(/\d+[\s:\/\\]+\d+\s*/, '').strip
|
2016-09-07 08:52:13 -04:00
|
|
|
end
|
|
|
|
|
2016-10-03 06:22:51 -04:00
|
|
|
def failed_but_allowed?
|
2016-03-17 10:54:56 -04:00
|
|
|
allow_failure? && (failed? || canceled?)
|
2016-02-19 13:58:43 -05:00
|
|
|
end
|
|
|
|
|
2016-11-22 00:36:19 -05:00
|
|
|
def duration
|
|
|
|
calculate_duration
|
|
|
|
end
|
|
|
|
|
2016-09-14 09:04:12 -04:00
|
|
|
def playable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2016-11-22 00:36:19 -05:00
|
|
|
def stuck?
|
|
|
|
false
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2015-10-12 09:45:46 -04:00
|
|
|
|
2016-11-22 00:36:19 -05:00
|
|
|
def has_trace?
|
2015-10-12 15:12:31 -04:00
|
|
|
false
|
|
|
|
end
|
2016-12-08 03:51:36 -05:00
|
|
|
|
2017-03-17 19:06:11 -04:00
|
|
|
# Added in 9.0 to keep backward compatibility for projects exported in 8.17
|
|
|
|
# and prior.
|
|
|
|
def gl_project_id
|
|
|
|
'dummy'
|
|
|
|
end
|
|
|
|
|
2016-12-08 11:52:24 -05:00
|
|
|
def detailed_status(current_user)
|
2017-02-22 17:54:59 -05:00
|
|
|
Gitlab::Ci::Status::Factory
|
|
|
|
.new(self, current_user)
|
|
|
|
.fabricate!
|
2016-12-08 03:51:36 -05:00
|
|
|
end
|
2016-12-22 15:31:42 -05:00
|
|
|
|
2016-12-27 10:59:42 -05:00
|
|
|
def sortable_name
|
2016-12-22 15:31:42 -05:00
|
|
|
name.split(/(\d+)/).map do |v|
|
|
|
|
v =~ /\d+/ ? v.to_i : v
|
|
|
|
end
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|