summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-06-23 16:46:36 +0300
committerValery Sizov <vsv2711@gmail.com>2015-06-24 13:23:20 +0300
commit21fc25fd8efc6fc1196fd26d59f5b5e776240e83 (patch)
tree11775dbd120dacc706edb7235e50095af693fbb2
parent3825fac65ba2e36620f7d50a8e52fc242ac0d710 (diff)
downloadgitlab-ci-21fc25fd8efc6fc1196fd26d59f5b5e776240e83.tar.gz
Ability to cancel all builds in the commit at once
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/commits_controller.rb9
-rw-r--r--app/models/build.rb1
-rw-r--r--app/views/commits/show.html.haml6
-rw-r--r--config/routes.rb1
-rw-r--r--spec/features/commits_spec.rb9
6 files changed, 26 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f94282b..6fdb70f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
v7.13.0
- Fix: No runner notification can see managers only
+ - Ability to cancel all builds in commit at once
v7.12.1
- Runner without tag should pick builds without tag only
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 06c24d6..88306f3 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -3,7 +3,8 @@ class CommitsController < ApplicationController
before_filter :authenticate_public_page!, only: :show
before_filter :project
before_filter :commit
- before_filter :authorize_access_project!, except: [:status, :show]
+ before_filter :authorize_access_project!, except: [:status, :show, :cancel]
+ before_filter :authorize_project_developer!, only: [:cancel]
def show
@builds = @commit.builds
@@ -13,6 +14,12 @@ class CommitsController < ApplicationController
render json: @commit.to_json(only: [:id, :sha], methods: [:status, :coverage])
end
+ def cancel
+ commit.builds.running_or_pending.each(&:cancel)
+
+ redirect_to project_ref_commit_path(project, commit.ref, commit.sha)
+ end
+
private
def project
diff --git a/app/models/build.rb b/app/models/build.rb
index 2ffb80c..6124c8f 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -32,6 +32,7 @@ class Build < ActiveRecord::Base
scope :success, ->() { where(status: "success") }
scope :failed, ->() { where(status: "failed") }
scope :unstarted, ->() { where(runner_id: nil) }
+ scope :running_or_pending, ->() { where(status:[:running, :pending]) }
acts_as_taggable
diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml
index 9ca6222..76b491f 100644
--- a/app/views/commits/show.html.haml
+++ b/app/views/commits/show.html.haml
@@ -33,6 +33,12 @@
%span.attr-name Created at:
#{@commit.created_at.to_s(:short)}
+- if current_user && current_user.has_developer_access?(@project.gitlab_id)
+ .pull-right
+ - if @commit.builds.running_or_pending.any?
+ = link_to "Cancel", cancel_project_ref_commit_path(@project, @commit.ref, @commit.sha), class: 'btn btn-sm btn-danger'
+
+
- if @commit.yaml_errors.present?
.bs-callout.bs-callout-danger
%h4 Found errors in your .gitlab-ci.yml:
diff --git a/config/routes.rb b/config/routes.rb
index bc77ee8..2b3ad5c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -37,6 +37,7 @@ Rails.application.routes.draw do
resources :commits, only: [:show] do
member do
get :status
+ get :cancel
end
end
end
diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb
index deaf729..e63d844 100644
--- a/spec/features/commits_spec.rb
+++ b/spec/features/commits_spec.rb
@@ -18,6 +18,15 @@ describe "Commits" do
it { page.should have_content @commit.git_commit_message }
it { page.should have_content @commit.git_author_name }
end
+
+ describe "Cancel commit" do
+ it "cancels commit" do
+ visit project_ref_commit_path(@project, @commit.ref, @commit.sha)
+ click_on "Cancel"
+
+ page.should have_content "canceled"
+ end
+ end
end
context "Public pages" do