summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-12-08 10:40:56 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-12-12 12:59:01 +0100
commit516dc7a5be3624f1866fa46f19f6472e2f9fae22 (patch)
treee00fc4a90befc0488a8a9fea828b334009ef88c2
parent633e64382d30674fecb1aaf138d18c73827c9a40 (diff)
downloadgitlab-ce-516dc7a5be3624f1866fa46f19f6472e2f9fae22.tar.gz
Improve actions
-rw-r--r--app/models/ci/build.rb4
-rw-r--r--lib/gitlab/ci/status/build/common.rb26
-rw-r--r--lib/gitlab/ci/status/build/factory.rb4
-rw-r--r--lib/gitlab/ci/status/build/play.rb47
-rw-r--r--lib/gitlab/ci/status/build/stop.rb47
5 files changed, 110 insertions, 18 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 0f4c498c266..73564dd2aa0 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -127,6 +127,10 @@ module Ci
end
end
+ def cancelable?
+ active?
+ end
+
def retryable?
project.builds_enabled? && commands.present? && complete?
end
diff --git a/lib/gitlab/ci/status/build/common.rb b/lib/gitlab/ci/status/build/common.rb
index d3d7e03ee3f..2bed68d1a11 100644
--- a/lib/gitlab/ci/status/build/common.rb
+++ b/lib/gitlab/ci/status/build/common.rb
@@ -13,33 +13,23 @@ module Gitlab
@subject.pipeline)
end
- def action_type
- case
- when @subject.playable? then :playable
- when @subject.active? then :cancel
- when @subject.retryable? then :retry
- end
- end
-
def has_action?(current_user)
- action_type && can?(current_user, :update_build, @subject)
+ (subject.cancelable? || subject.retryable?) &&
+ can?(current_user, :update_build, @subject)
end
def action_icon
- case action_type
- when :playable then 'remove'
- when :cancel then 'icon_play'
- when :retry then 'repeat'
+ case
+ when subject.cancelable? then 'icon_play'
+ when subject.retryable? then 'repeat'
end
end
def action_path
- case action_type
- when :playable
- play_namespace_project_build_path(subject.project.namespace, subject.project, subject)
- when :cancel
+ case
+ when subject.cancelable?
cancel_namespace_project_build_path(subject.project.namespace, subject.project, subject)
- when :retry
+ when subject.retryable?
retry_namespace_project_build_path(subject.project.namespace, subject.project, subject)
end
end
diff --git a/lib/gitlab/ci/status/build/factory.rb b/lib/gitlab/ci/status/build/factory.rb
index dd38e1418b6..d8a9f53f236 100644
--- a/lib/gitlab/ci/status/build/factory.rb
+++ b/lib/gitlab/ci/status/build/factory.rb
@@ -5,6 +5,10 @@ module Gitlab
class Factory < Status::Factory
private
+ def extended_statuses
+ [Stop, Play]
+ end
+
def core_status
super.extend(Status::Build::Common)
end
diff --git a/lib/gitlab/ci/status/build/play.rb b/lib/gitlab/ci/status/build/play.rb
new file mode 100644
index 00000000000..581c81d0175
--- /dev/null
+++ b/lib/gitlab/ci/status/build/play.rb
@@ -0,0 +1,47 @@
+module Gitlab
+ module Ci
+ module Status
+ module Status
+ class Play < SimpleDelegator
+ extend Status::Extended
+
+ def text
+ 'play'
+ end
+
+ def label
+ 'play'
+ end
+
+ def icon
+ 'icon_status_skipped'
+ end
+
+ def to_s
+ 'play'
+ end
+
+ def has_action?(current_user)
+ can?(current_user, :update_build, subject)
+ end
+
+ def action_icon
+ :play
+ end
+
+ def action_path
+ play_namespace_project_build_path(subject.project.namespace, subject.project, subject)
+ end
+
+ def action_method
+ :post
+ end
+
+ def self.matches?(build)
+ build.playable? && !build.stops_environment?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/build/stop.rb b/lib/gitlab/ci/status/build/stop.rb
new file mode 100644
index 00000000000..261de9695c5
--- /dev/null
+++ b/lib/gitlab/ci/status/build/stop.rb
@@ -0,0 +1,47 @@
+module Gitlab
+ module Ci
+ module Status
+ module Status
+ class Play < SimpleDelegator
+ extend Status::Extended
+
+ def text
+ 'stop'
+ end
+
+ def label
+ 'stop'
+ end
+
+ def icon
+ 'icon_status_skipped'
+ end
+
+ def to_s
+ 'stop'
+ end
+
+ def has_action?(current_user)
+ can?(current_user, :update_build, subject)
+ end
+
+ def action_icon
+ :play
+ end
+
+ def action_path
+ play_namespace_project_build_path(subject.project.namespace, subject.project, subject)
+ end
+
+ def action_method
+ :post
+ end
+
+ def self.matches?(build)
+ build.playable? && build.stops_environment?
+ end
+ end
+ end
+ end
+ end
+end