diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/commits_controller.rb | 9 | ||||
-rw-r--r-- | app/models/build.rb | 1 | ||||
-rw-r--r-- | app/views/commits/show.html.haml | 6 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | spec/features/commits_spec.rb | 13 |
6 files changed, 30 insertions, 1 deletions
@@ -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..0e3e350 100644 --- a/spec/features/commits_spec.rb +++ b/spec/features/commits_spec.rb @@ -18,6 +18,19 @@ 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 + FactoryGirl.create :build, commit: @commit + visit project_ref_commit_path(@project, @commit.ref, @commit.sha) + click_on "Cancel" + + @commit.reload + @commit.builds.each do |build| + build.status.should == "canceled" + end + end + end end context "Public pages" do |