diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-09 12:47:11 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-13 15:11:21 +0100 |
commit | ffcf3c68586b5e4a977a3c92cd1b3f8b1871c322 (patch) | |
tree | 7b243e742f1eeb1589e4b7ffb3971ed88de51b34 | |
parent | 008f22cd820a5bf9e8ff9a68550c9550463d3279 (diff) | |
download | gitlab-ce-ffcf3c68586b5e4a977a3c92cd1b3f8b1871c322.tar.gz |
Skip job only when canceling the pipeline it belongs to
-rw-r--r-- | app/models/ci/pipeline.rb | 8 | ||||
-rw-r--r-- | app/models/commit_status.rb | 3 | ||||
-rw-r--r-- | spec/requests/api/commit_statuses_spec.rb | 5 |
3 files changed, 12 insertions, 4 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index bbc358adb83..8371c2d8c72 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -214,7 +214,13 @@ module Ci def cancel_running Gitlab::OptimisticLocking.retry_lock( statuses.cancelable) do |cancelable| - cancelable.each(&:cancel) + cancelable.each do |status| + if status.created? + status.skip + elsif status.active? + status.cancel + end + end end end diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 4a064644d64..9547c57b2ae 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -65,8 +65,7 @@ class CommitStatus < ActiveRecord::Base end event :cancel do - transition [:created] => :skipped - transition [:pending, :running] => :canceled + transition [:created, :pending, :running] => :canceled end before_transition created: [:pending, :running] do |commit_status| diff --git a/spec/requests/api/commit_statuses_spec.rb b/spec/requests/api/commit_statuses_spec.rb index 88361def3cf..ee5865ad740 100644 --- a/spec/requests/api/commit_statuses_spec.rb +++ b/spec/requests/api/commit_statuses_spec.rb @@ -5,12 +5,15 @@ describe API::CommitStatuses, api: true do let!(:project) { create(:project, :repository) } let(:commit) { project.repository.commit } - let(:commit_status) { create(:commit_status, pipeline: pipeline) } let(:guest) { create_user(:guest) } let(:reporter) { create_user(:reporter) } let(:developer) { create_user(:developer) } let(:sha) { commit.id } + let(:commit_status) do + create(:commit_status, status: :pending, pipeline: pipeline) + end + describe "GET /projects/:id/repository/commits/:sha/statuses" do let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" } |