summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-05-19 20:42:43 +0000
committerDouwe Maan <douwe@gitlab.com>2016-05-19 20:42:43 +0000
commitbd0cecfdf6ec504421b44f1174040c5003c13f65 (patch)
tree200c89a047765c7578bc34c16065d8b2ee81980a /app/models
parent53e2d30af4f5a23d4f58c051293188e891c385fa (diff)
parent4f1c63683175fa88ca41ba2180b68e266d7118e4 (diff)
downloadgitlab-ce-bd0cecfdf6ec504421b44f1174040c5003c13f65.tar.gz
Merge branch 'with-pipeline-view' into 'master'
Add pipeline view This is continuation of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3653 cc @DouweM @grzesiek Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/17551 Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/15625 See merge request !3703
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ability.rb5
-rw-r--r--app/models/ci/commit.rb24
-rw-r--r--app/models/commit_status.rb13
3 files changed, 34 insertions, 8 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb
index f70268d3138..f7ea2fd2b1f 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -205,6 +205,7 @@ class Ability
:read_commit_status,
:read_build,
:read_container_image,
+ :read_pipeline,
]
end
@@ -216,6 +217,8 @@ class Ability
:update_commit_status,
:create_build,
:update_build,
+ :create_pipeline,
+ :update_pipeline,
:create_merge_request,
:create_wiki,
:push_code,
@@ -248,6 +251,7 @@ class Ability
:admin_commit_status,
:admin_build,
:admin_container_image,
+ :admin_pipeline
]
end
@@ -290,6 +294,7 @@ class Ability
unless project.builds_enabled
rules += named_abilities('build')
+ rules += named_abilities('pipeline')
end
unless project.container_registry_enabled
diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb
index f4b61c75ab6..6675a3f5d53 100644
--- a/app/models/ci/commit.rb
+++ b/app/models/ci/commit.rb
@@ -8,8 +8,6 @@ module Ci
has_many :builds, class_name: 'Ci::Build'
has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'
- delegate :stages, to: :statuses
-
validates_presence_of :sha
validates_presence_of :status
validate :valid_commit_sha
@@ -22,7 +20,8 @@ module Ci
end
def self.stages
- CommitStatus.where(commit: all).stages
+ # We use pluck here due to problems with MySQL which doesn't allow LIMIT/OFFSET in queries
+ CommitStatus.where(commit: pluck(:id)).stages
end
def project_id
@@ -67,6 +66,25 @@ module Ci
end
end
+ def cancel_running
+ builds.running_or_pending.each(&:cancel)
+ end
+
+ def retry_failed
+ builds.latest.failed.select(&:retryable?).each(&:retry)
+ end
+
+ def latest?
+ return false unless ref
+ commit = project.commit(ref)
+ return false unless commit
+ commit.sha == sha
+ end
+
+ def triggered?
+ trigger_requests.any?
+ end
+
def create_builds(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 cacbc13b391..1548a51e942 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -14,7 +14,8 @@ class CommitStatus < ActiveRecord::Base
alias_attribute :author, :user
scope :latest, -> { where(id: unscope(:select).select('max(id)').group(:name, :commit_id)) }
- scope :ordered, -> { order(:ref, :stage_idx, :name) }
+ scope :retried, -> { where.not(id: latest) }
+ scope :ordered, -> { order(:name) }
scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) }
state_machine :status, initial: :pending do
@@ -54,13 +55,15 @@ class CommitStatus < ActiveRecord::Base
end
def self.stages
- order_by = 'max(stage_idx)'
- group('stage').order(order_by).pluck(:stage, order_by).map(&:first).compact
+ # We group by stage name, but order stages by theirs' index
+ unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').pluck('sg.stage')
end
def self.stages_status
- all.stages.inject({}) do |h, stage|
- h[stage] = all.where(stage: stage).status
+ # We execute subquery for each stage to calculate a stage status
+ statuses = unscoped.from(all, :sg).group('stage').pluck('sg.stage', all.where('stage=sg.stage').status_sql)
+ statuses.inject({}) do |h, k|
+ h[k.first] = k.last
h
end
end