diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ability.rb | 7 | ||||
-rw-r--r-- | app/models/ci/build.rb | 4 | ||||
-rw-r--r-- | app/models/ci/commit.rb | 12 | ||||
-rw-r--r-- | app/models/commit_status.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/ci_status.rb | 11 |
5 files changed, 29 insertions, 7 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index c0bf6def7c5..ec5ac54c277 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -195,6 +195,7 @@ class Ability :admin_label, :read_commit_status, :read_build, + :read_pipeline, ] end @@ -206,6 +207,8 @@ class Ability :update_commit_status, :create_build, :update_build, + :create_pipeline, + :update_pipeline, :create_merge_request, :create_wiki, :push_code @@ -234,7 +237,8 @@ class Ability :admin_wiki, :admin_project, :admin_commit_status, - :admin_build + :admin_build, + :admin_pipeline ] end @@ -277,6 +281,7 @@ class Ability unless project.builds_enabled rules += named_abilities('build') + rules += named_abilities('pipeline') end rules diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index c99aeff6f1c..d497cf67cbc 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -129,6 +129,10 @@ module Ci !self.commit.latest.include?(self) end + def retry + Ci::Build.retry(self) + end + def depends_on_builds # Get builds of the same type latest_builds = self.commit.builds.latest diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb index cd9ce0a283d..45309614115 100644 --- a/app/models/ci/commit.rb +++ b/app/models/ci/commit.rb @@ -67,6 +67,12 @@ module Ci .pluck(:stage, :stage_idx).map(&:first) end + def stages + statuses + .group(:stage, :stage_idx).order(:stage_idx) + .pluck(:stage, :stage_idx).map(&:first) + end + def to_param sha end @@ -115,6 +121,12 @@ module Ci Gitlab::Git::branch_ref?(origin_ref) end + def retryable? + builds.latest.any? do |build| + build.failed? || build.retryable? + end + end + def create_builds(ref, tag, user, trigger_request = nil) return unless config_processor config_processor.stages.any? do |stage| diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 3a059f01d49..88cb7e21d66 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -53,7 +53,7 @@ class CommitStatus < ActiveRecord::Base scope :failed, -> { where(status: 'failed') } scope :running_or_pending, -> { where(status: [:running, :pending]) } scope :finished, -> { where(status: [:success, :failed, :canceled]) } - scope :latest, -> { where(id: unscope(:select).select('max(id)').group(:name, :ref)) } + scope :latest, -> { where(id: unscope(:select).select('max(id)').group(:name)) } scope :ordered, -> { order(:ref, :stage_idx, :name) } scope :for_ref, ->(ref) { where(ref: ref) } diff --git a/app/models/concerns/ci_status.rb b/app/models/concerns/ci_status.rb index 494db025048..f7a9af1507d 100644 --- a/app/models/concerns/ci_status.rb +++ b/app/models/concerns/ci_status.rb @@ -3,15 +3,16 @@ module CiStatus module ClassMethods def status - if all.none? + objs = all.to_a + if objs.none? nil - elsif all.all? { |status| status.success? || status.ignored? } + elsif objs.all? { |status| status.success? || status.ignored? } 'success' - elsif all.all?(&:pending?) + elsif objs.all?(&:pending?) 'pending' - elsif all.any?(&:running?) || all.any?(&:pending?) + elsif objs.any?(&:running?) || all.any?(&:pending?) 'running' - elsif all.all?(&:canceled?) + elsif objs.all?(&:canceled?) 'canceled' else 'failed' |