From c81ef3041e50411166620a99e6ac80f9dc97d86e Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Mon, 20 Feb 2017 01:17:24 +0300 Subject: add auto-cancel for pending pipelines on branch, if they are not HEAD fix changelog MR reference add non-HEAD builds finder and add `created` pipelines to scope add spec for auto-cancel non-HEAD pipelines and refactor create_pipeline_service_spec more refactoring for spec adds option for auto-cancel into CI/CD settings fix spec to new configuration fix rubocop fix schema.rb fix schema.rb replace Gitlab 9.0 with 9.1 in doc change wording on pipeline settings added auto_canceled_by field as identifier of autocancel subject remove unnecessary index replace service with retry_lock replace auto_cancel_pending_pipelines boolean setting with integer (and enum in model) fix schema.rb fix schema.rb remove projekt attribute and clean up spec clean up spec withcouple of shared examples added spec for "It does not cancel current pipeline" scenario add some specs to auto-cancel add spec for another branch pipelines --- .../projects/pipelines_settings_controller.rb | 2 +- app/models/ci/pipeline.rb | 8 ++++++++ app/models/concerns/has_status.rb | 1 + app/models/project.rb | 2 ++ app/services/ci/create_pipeline_service.rb | 12 ++++++++++++ app/views/projects/pipelines_settings/_show.html.haml | 17 +++++++++++++---- 6 files changed, 37 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/controllers/projects/pipelines_settings_controller.rb b/app/controllers/projects/pipelines_settings_controller.rb index c8c80551ac9..ff50602831c 100644 --- a/app/controllers/projects/pipelines_settings_controller.rb +++ b/app/controllers/projects/pipelines_settings_controller.rb @@ -23,7 +23,7 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController def update_params params.require(:project).permit( :runners_token, :builds_enabled, :build_allow_git_fetch, :build_timeout_in_minutes, :build_coverage_regex, - :public_builds + :public_builds, :auto_cancel_pending_pipelines ) end end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 49dec770096..0ac12d9c3dc 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -127,6 +127,14 @@ module Ci where.not(duration: nil).sum(:duration) end + def auto_cancelable_pipelines + project.pipelines + .where(ref: ref) + .where.not(id: id) + .where.not(sha: project.repository.sha_from_ref(ref)) + .created_or_pending + end + def stage(name) stage = Ci::Stage.new(self, name: name) stage unless stage.statuses_count.zero? diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb index 0a1a65da05a..2f61709110c 100644 --- a/app/models/concerns/has_status.rb +++ b/app/models/concerns/has_status.rb @@ -76,6 +76,7 @@ module HasStatus scope :canceled, -> { where(status: 'canceled') } scope :skipped, -> { where(status: 'skipped') } scope :manual, -> { where(status: 'manual') } + scope :created_or_pending, -> { where(status: [:created, :pending]) } scope :running_or_pending, -> { where(status: [:running, :pending]) } scope :finished, -> { where(status: [:success, :failed, :canceled]) } scope :failed_or_canceled, -> { where(status: [:failed, :canceled]) } diff --git a/app/models/project.rb b/app/models/project.rb index 83660d8c431..333b7319ffa 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -256,6 +256,8 @@ class Project < ActiveRecord::Base scope :with_builds_enabled, -> { with_feature_enabled(:builds) } scope :with_issues_enabled, -> { with_feature_enabled(:issues) } + enum auto_cancel_pending_pipelines: { enabled: 1, disabled: 0 } + # project features may be "disabled", "internal" or "enabled". If "internal", # they are only available to team members. This scope returns projects where # the feature is either enabled, or internal with permission for the user. diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 38a85e9fc42..cb09973081a 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -53,6 +53,8 @@ module Ci .execute(pipeline) end + cancel_pending_pipelines if project.auto_cancel_pending_pipelines? + pipeline.tap(&:process!) end @@ -63,6 +65,16 @@ module Ci pipeline.git_commit_message =~ /\[(ci[ _-]skip|skip[ _-]ci)\]/i end + def cancel_pending_pipelines + Gitlab::OptimisticLocking.retry_lock( + pipeline.auto_cancelable_pipelines) do |cancelables| + cancelables.find_each do |cancelable| + cancelable.cancel_running + cancelable.update_attributes(auto_canceled_by: pipeline.id) + end + end + end + def commit @commit ||= project.commit(origin_sha || origin_ref) end diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml index 132f6372e40..a3f84476dea 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -21,7 +21,7 @@ Git strategy for pipelines %p Choose between clone or fetch to get the recent application code - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'git-strategy') + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'git-strategy'), target: '_blank' .radio = f.label :build_allow_git_fetch_false do = f.radio_button :build_allow_git_fetch, 'false' @@ -43,7 +43,7 @@ = f.number_field :build_timeout_in_minutes, class: 'form-control', min: '0' %p.help-block Per job in minutes. If a job passes this threshold, it will be marked as failed. - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'timeout') + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'timeout'), target: '_blank' %hr .form-group @@ -53,7 +53,16 @@ %strong Public pipelines .help-block Allow everyone to access pipelines for public and internal projects - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'visibility-of-pipelines') + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'visibility-of-pipelines'), target: '_blank' + %hr + .form-group + .checkbox + = f.label :auto_cancel_pending_pipelines do + = f.check_box :auto_cancel_pending_pipelines, {}, 'enabled', 'disabled' + %strong Auto-cancel redundant, pending pipelines + .help-block + New pipelines will cancel older, pending pipelines on the same branch + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'auto-cancel-pending-pipelines'), target: '_blank' %hr .form-group @@ -65,7 +74,7 @@ %p.help-block A regular expression that will be used to find the test coverage output in the job trace. Leave blank to disable - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'test-coverage-parsing') + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'test-coverage-parsing'), target: '_blank' .bs-callout.bs-callout-info %p Below are examples of regex for existing tools: %ul -- cgit v1.2.1 From b1dc850ad6037def0ed47ea190cb33ba8493ac27 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 13:04:14 +0300 Subject: move `auto_cancelable_pipelines` method to `create_pipeline_service.rb` --- app/models/ci/pipeline.rb | 8 -------- app/services/ci/create_pipeline_service.rb | 11 +++++++++-- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 0ac12d9c3dc..49dec770096 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -127,14 +127,6 @@ module Ci where.not(duration: nil).sum(:duration) end - def auto_cancelable_pipelines - project.pipelines - .where(ref: ref) - .where.not(id: id) - .where.not(sha: project.repository.sha_from_ref(ref)) - .created_or_pending - end - def stage(name) stage = Ci::Stage.new(self, name: name) stage unless stage.statuses_count.zero? diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index cb09973081a..2f5ffddb12e 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -66,8 +66,7 @@ module Ci end def cancel_pending_pipelines - Gitlab::OptimisticLocking.retry_lock( - pipeline.auto_cancelable_pipelines) do |cancelables| + Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines) do |cancelables| cancelables.find_each do |cancelable| cancelable.cancel_running cancelable.update_attributes(auto_canceled_by: pipeline.id) @@ -75,6 +74,14 @@ module Ci end end + def auto_cancelable_pipelines + project.pipelines + .where(ref: pipeline.ref) + .where.not(id: pipeline.id) + .where.not(sha: project.repository.sha_from_ref(pipeline.ref)) + .created_or_pending + end + def commit @commit ||= project.commit(origin_sha || origin_ref) end -- cgit v1.2.1 From 67f27a1c4bb5fa87b65845bf26ef50bb05a09fcd Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 13:38:42 +0300 Subject: change order of enum options in auto_cancel_pending_pipelines --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 333b7319ffa..ca80b8a2dc8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -256,7 +256,7 @@ class Project < ActiveRecord::Base scope :with_builds_enabled, -> { with_feature_enabled(:builds) } scope :with_issues_enabled, -> { with_feature_enabled(:issues) } - enum auto_cancel_pending_pipelines: { enabled: 1, disabled: 0 } + enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 } # project features may be "disabled", "internal" or "enabled". If "internal", # they are only available to team members. This scope returns projects where -- cgit v1.2.1 From a4d08e6babbbdbd44267aebdcccd2cc2c63e48ed Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sat, 18 Mar 2017 14:46:56 +0300 Subject: rename `auto_canceled_by` and add foreign key --- app/models/ci/pipeline.rb | 2 ++ app/services/ci/create_pipeline_service.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 49dec770096..5e88ba0c170 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -7,7 +7,9 @@ module Ci belongs_to :project belongs_to :user + belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' + has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id' has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id has_many :builds, foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 2f5ffddb12e..f944c869922 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -69,7 +69,7 @@ module Ci Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines) do |cancelables| cancelables.find_each do |cancelable| cancelable.cancel_running - cancelable.update_attributes(auto_canceled_by: pipeline.id) + cancelable.update_attributes(auto_canceled_by_id: pipeline.id) end end end -- cgit v1.2.1 From 2d7bc6959606bc9af5144463433507685f81a9a0 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sun, 19 Mar 2017 21:04:45 +0300 Subject: adds tooltips into several places --- app/helpers/ci_status_helper.rb | 4 ++++ app/views/ci/status/_badge.html.haml | 9 +++++---- app/views/projects/builds/_header.html.haml | 2 +- app/views/projects/ci/builds/_build.html.haml | 2 +- app/views/projects/pipelines/_info.html.haml | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 2de9e0de310..88e18500430 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -121,4 +121,8 @@ module CiStatusHelper status.respond_to?(:label) && status.respond_to?(:icon) end + + def status_title(pipeline) + "This pipeline is redundant as a newer pipeline exists (canceled by ##{pipeline.auto_canceled_by_id} pipeline)" if pipeline.auto_canceled_by_id? && pipeline.canceled? + end end diff --git a/app/views/ci/status/_badge.html.haml b/app/views/ci/status/_badge.html.haml index c00c7f7407e..c4ff1b5bdc9 100644 --- a/app/views/ci/status/_badge.html.haml +++ b/app/views/ci/status/_badge.html.haml @@ -1,12 +1,13 @@ - status = local_assigns.fetch(:status) -- link = local_assigns.fetch(:link, true) -- css_classes = "ci-status ci-#{status.group}" +- link = local_assigns.fetch(:link, true) +- title = local_assigns.fetch(:title, nil) +- css_classes = "ci-status ci-#{status.group} #{'has-tooltip' if title.present? }" - if link && status.has_details? - = link_to status.details_path, class: css_classes do + = link_to status.details_path, class: css_classes, title: title do = custom_icon(status.icon) = status.text - else - %span{ class: css_classes } + %span{ class: css_classes, title: title } = custom_icon(status.icon) = status.text diff --git a/app/views/projects/builds/_header.html.haml b/app/views/projects/builds/_header.html.haml index 7eb17e887e7..aeb1dba4b3f 100644 --- a/app/views/projects/builds/_header.html.haml +++ b/app/views/projects/builds/_header.html.haml @@ -1,6 +1,6 @@ .content-block.build-header.top-area .header-content - = render 'ci/status/badge', status: @build.detailed_status(current_user), link: false + = render 'ci/status/badge', status: @build.detailed_status(current_user), link: false, title: status_title(@build.pipeline) Job %strong.js-build-id ##{@build.id} in pipeline diff --git a/app/views/projects/ci/builds/_build.html.haml b/app/views/projects/ci/builds/_build.html.haml index aeed293a724..b9ec59df3ca 100644 --- a/app/views/projects/ci/builds/_build.html.haml +++ b/app/views/projects/ci/builds/_build.html.haml @@ -9,7 +9,7 @@ %tr.build.commit{ class: ('retried' if retried) } %td.status - = render "ci/status/badge", status: build.detailed_status(current_user) + = render "ci/status/badge", status: build.detailed_status(current_user), title: status_title(build.pipeline) %td.branch-commit - if can?(current_user, :read_build, build) diff --git a/app/views/projects/pipelines/_info.html.haml b/app/views/projects/pipelines/_info.html.haml index 4be9a1371ec..17f38cef718 100644 --- a/app/views/projects/pipelines/_info.html.haml +++ b/app/views/projects/pipelines/_info.html.haml @@ -1,6 +1,6 @@ .page-content-header .header-main-content - = render 'ci/status/badge', status: @pipeline.detailed_status(current_user) + = render 'ci/status/badge', status: @pipeline.detailed_status(current_user), title: status_title(@pipeline) %strong Pipeline ##{@pipeline.id} triggered #{time_ago_with_tooltip(@pipeline.created_at)} - if @pipeline.user -- cgit v1.2.1 From ebf052010c14130a1ed1117c4723315c4feb57fc Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Sun, 19 Mar 2017 22:04:56 +0300 Subject: add tooltip on badge in pipelines index --- app/assets/javascripts/vue_pipelines_index/components/status.js | 7 ++++++- app/serializers/pipeline_entity.rb | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/javascripts/vue_pipelines_index/components/status.js b/app/assets/javascripts/vue_pipelines_index/components/status.js index 21a281af438..82db731b73c 100644 --- a/app/assets/javascripts/vue_pipelines_index/components/status.js +++ b/app/assets/javascripts/vue_pipelines_index/components/status.js @@ -36,7 +36,7 @@ export default { computed: { cssClasses() { - return `ci-status ci-${this.pipeline.details.status.group}`; + return `ci-status ci-${this.pipeline.details.status.group} has-tooltip`; }, detailsPath() { @@ -47,12 +47,17 @@ export default { content() { return `${this.svg} ${this.pipeline.details.status.text}`; }, + + tooltipTitle() { + return this.pipeline.details.status_tooltip; + } }, template: ` diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 3f16dd66d54..6dc84c925fe 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -13,6 +13,7 @@ class PipelineEntity < Grape::Entity expose :details do expose :detailed_status, as: :status, with: StatusEntity + expose :status_tooltip expose :duration expose :finished_at expose :stages, using: StageEntity @@ -81,4 +82,8 @@ class PipelineEntity < Grape::Entity def detailed_status pipeline.detailed_status(request.user) end + + def status_tooltip + "This pipeline is redundant as a newer pipeline exists (canceled by ##{pipeline.auto_canceled_by_id} pipeline)" if pipeline.auto_canceled_by_id? && pipeline.canceled? + end end -- cgit v1.2.1 From 29db8ab982bc912c2404cf35527362b5f991e1ce Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Mon, 20 Mar 2017 01:00:10 +0300 Subject: fix linter error --- app/assets/javascripts/vue_pipelines_index/components/status.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/javascripts/vue_pipelines_index/components/status.js b/app/assets/javascripts/vue_pipelines_index/components/status.js index 82db731b73c..ece1ec89f89 100644 --- a/app/assets/javascripts/vue_pipelines_index/components/status.js +++ b/app/assets/javascripts/vue_pipelines_index/components/status.js @@ -50,7 +50,7 @@ export default { tooltipTitle() { return this.pipeline.details.status_tooltip; - } + }, }, template: ` -- cgit v1.2.1 From 63dbdb9f52d1aa56cbf1e15022623c306083fdd1 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Tue, 21 Mar 2017 01:05:52 +0300 Subject: add presenter for status badge --- app/helpers/ci_status_helper.rb | 2 +- app/presenters/ci/pipeline_status_badge_presenter.rb | 13 +++++++++++++ app/serializers/pipeline_entity.rb | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/presenters/ci/pipeline_status_badge_presenter.rb (limited to 'app') diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 88e18500430..da4826567d4 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -123,6 +123,6 @@ module CiStatusHelper end def status_title(pipeline) - "This pipeline is redundant as a newer pipeline exists (canceled by ##{pipeline.auto_canceled_by_id} pipeline)" if pipeline.auto_canceled_by_id? && pipeline.canceled? + Ci::PipelineStatusBadgePresenter.new(pipeline).status_title end end diff --git a/app/presenters/ci/pipeline_status_badge_presenter.rb b/app/presenters/ci/pipeline_status_badge_presenter.rb new file mode 100644 index 00000000000..bc6601c8a7f --- /dev/null +++ b/app/presenters/ci/pipeline_status_badge_presenter.rb @@ -0,0 +1,13 @@ +module Ci + class PipelineStatusBadgePresenter < Gitlab::View::Presenter::Delegated + presents :pipeline + + def auto_canceled? + canceled? && auto_canceled_by_id? + end + + def status_title + "Pipeline is redundant and is auto-canceled by Pipeline ##{pipeline.auto_canceled_by_id}" if auto_canceled? + end + end +end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 6dc84c925fe..82ee960f530 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -84,6 +84,6 @@ class PipelineEntity < Grape::Entity end def status_tooltip - "This pipeline is redundant as a newer pipeline exists (canceled by ##{pipeline.auto_canceled_by_id} pipeline)" if pipeline.auto_canceled_by_id? && pipeline.canceled? + Ci::PipelineStatusBadgePresenter.new(pipeline).status_title end end -- cgit v1.2.1 From 86d8c2a78e3e9834bcb59a94041be6f9e40c7f98 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Mon, 27 Mar 2017 21:14:17 +0300 Subject: remove redundant `pipeline` --- app/presenters/ci/pipeline_status_badge_presenter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/presenters/ci/pipeline_status_badge_presenter.rb b/app/presenters/ci/pipeline_status_badge_presenter.rb index bc6601c8a7f..ac6325dd5fa 100644 --- a/app/presenters/ci/pipeline_status_badge_presenter.rb +++ b/app/presenters/ci/pipeline_status_badge_presenter.rb @@ -7,7 +7,7 @@ module Ci end def status_title - "Pipeline is redundant and is auto-canceled by Pipeline ##{pipeline.auto_canceled_by_id}" if auto_canceled? + "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" if auto_canceled? end end end -- cgit v1.2.1 From 3a7352fddc93dc2736a3bfd24008a2006c5fc4eb Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Mon, 27 Mar 2017 21:15:23 +0300 Subject: remove unnecessary space --- app/views/ci/status/_badge.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/ci/status/_badge.html.haml b/app/views/ci/status/_badge.html.haml index c4ff1b5bdc9..39c7fb0eba2 100644 --- a/app/views/ci/status/_badge.html.haml +++ b/app/views/ci/status/_badge.html.haml @@ -1,7 +1,7 @@ - status = local_assigns.fetch(:status) - link = local_assigns.fetch(:link, true) - title = local_assigns.fetch(:title, nil) -- css_classes = "ci-status ci-#{status.group} #{'has-tooltip' if title.present? }" +- css_classes = "ci-status ci-#{status.group} #{'has-tooltip' if title.present?}" - if link && status.has_details? = link_to status.details_path, class: css_classes, title: title do -- cgit v1.2.1 From 14722b66a1ee0dd711a631a8d48e8761334ed4a4 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Tue, 28 Mar 2017 20:47:11 +0300 Subject: rename pipeline_presenter --- app/helpers/ci_status_helper.rb | 2 +- app/presenters/ci/pipeline_presenter.rb | 13 +++++++++++++ app/presenters/ci/pipeline_status_badge_presenter.rb | 13 ------------- app/serializers/pipeline_entity.rb | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 app/presenters/ci/pipeline_presenter.rb delete mode 100644 app/presenters/ci/pipeline_status_badge_presenter.rb (limited to 'app') diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index da4826567d4..2db95729dd9 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -123,6 +123,6 @@ module CiStatusHelper end def status_title(pipeline) - Ci::PipelineStatusBadgePresenter.new(pipeline).status_title + Ci::PipelinePresenter.new(pipeline).status_title end end diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb new file mode 100644 index 00000000000..8f9e4fa707d --- /dev/null +++ b/app/presenters/ci/pipeline_presenter.rb @@ -0,0 +1,13 @@ +module Ci + class PipelinePresenter < Gitlab::View::Presenter::Delegated + presents :pipeline + + def auto_canceled? + canceled? && auto_canceled_by_id? + end + + def status_title + "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" if auto_canceled? + end + end +end diff --git a/app/presenters/ci/pipeline_status_badge_presenter.rb b/app/presenters/ci/pipeline_status_badge_presenter.rb deleted file mode 100644 index ac6325dd5fa..00000000000 --- a/app/presenters/ci/pipeline_status_badge_presenter.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Ci - class PipelineStatusBadgePresenter < Gitlab::View::Presenter::Delegated - presents :pipeline - - def auto_canceled? - canceled? && auto_canceled_by_id? - end - - def status_title - "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" if auto_canceled? - end - end -end diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 82ee960f530..c6b80dc0952 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -84,6 +84,6 @@ class PipelineEntity < Grape::Entity end def status_tooltip - Ci::PipelineStatusBadgePresenter.new(pipeline).status_title + Ci::PipelinePresenter.new(pipeline).status_title end end -- cgit v1.2.1 From 2575661865be0cd230993950b78e0b4550694f78 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Tue, 28 Mar 2017 23:27:16 +0300 Subject: replace helper with decorator --- app/helpers/ci_status_helper.rb | 4 ---- app/models/ci/pipeline.rb | 1 + app/serializers/pipeline_entity.rb | 2 +- app/views/projects/builds/_header.html.haml | 12 +++++++----- 4 files changed, 9 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 2db95729dd9..2de9e0de310 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -121,8 +121,4 @@ module CiStatusHelper status.respond_to?(:label) && status.respond_to?(:icon) end - - def status_title(pipeline) - Ci::PipelinePresenter.new(pipeline).status_title - end end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 5e88ba0c170..9ef35ebdd50 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -4,6 +4,7 @@ module Ci include HasStatus include Importable include AfterCommitQueue + include Presentable belongs_to :project belongs_to :user diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index c6b80dc0952..78af8b51709 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -84,6 +84,6 @@ class PipelineEntity < Grape::Entity end def status_tooltip - Ci::PipelinePresenter.new(pipeline).status_title + pipeline.present(current_user: request.user).status_title end end diff --git a/app/views/projects/builds/_header.html.haml b/app/views/projects/builds/_header.html.haml index aeb1dba4b3f..67da50646c7 100644 --- a/app/views/projects/builds/_header.html.haml +++ b/app/views/projects/builds/_header.html.haml @@ -1,14 +1,16 @@ +- pipeline = @build.pipeline.present(current_user: current_user) + .content-block.build-header.top-area .header-content - = render 'ci/status/badge', status: @build.detailed_status(current_user), link: false, title: status_title(@build.pipeline) + = render 'ci/status/badge', status: @build.detailed_status(current_user), link: false, title: pipeline.status_title Job %strong.js-build-id ##{@build.id} in pipeline - = link_to pipeline_path(@build.pipeline) do - %strong ##{@build.pipeline.id} + = link_to pipeline_path(pipeline) do + %strong ##{pipeline.id} for commit - = link_to namespace_project_commit_path(@project.namespace, @project, @build.pipeline.sha) do - %strong= @build.pipeline.short_sha + = link_to namespace_project_commit_path(@project.namespace, @project, pipeline.sha) do + %strong= pipeline.short_sha from = link_to namespace_project_commits_path(@project.namespace, @project, @build.ref) do %code -- cgit v1.2.1 From c9806b47b868ca5fe424476077262edc1d64cac0 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Tue, 4 Apr 2017 21:49:16 +0300 Subject: extract build.pipeline as variable --- app/views/projects/ci/builds/_build.html.haml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/views/projects/ci/builds/_build.html.haml b/app/views/projects/ci/builds/_build.html.haml index b9ec59df3ca..c57e4e81912 100644 --- a/app/views/projects/ci/builds/_build.html.haml +++ b/app/views/projects/ci/builds/_build.html.haml @@ -6,10 +6,11 @@ - stage = local_assigns.fetch(:stage, false) - coverage = local_assigns.fetch(:coverage, false) - allow_retry = local_assigns.fetch(:allow_retry, false) +- pipeline = build.pipeline.present(current_user: current_user) %tr.build.commit{ class: ('retried' if retried) } %td.status - = render "ci/status/badge", status: build.detailed_status(current_user), title: status_title(build.pipeline) + = render "ci/status/badge", status: build.detailed_status(current_user), title: pipeline.status_title %td.branch-commit - if can?(current_user, :read_build, build) @@ -51,11 +52,11 @@ - if pipeline_link %td - = link_to pipeline_path(build.pipeline) do - %span.pipeline-id ##{build.pipeline.id} + = link_to pipeline_path(pipeline) do + %span.pipeline-id ##{pipeline.id} %span by - - if build.pipeline.user - = user_avatar(user: build.pipeline.user, size: 20) + - if pipeline.user + = user_avatar(user: pipeline.user, size: 20) - else %span.monospace API -- cgit v1.2.1 From 2d4fd769a7a53f6f8ac1cd0331a8eb6b625dc8b6 Mon Sep 17 00:00:00 2001 From: Rydkin Maxim Date: Tue, 4 Apr 2017 22:21:12 +0300 Subject: replaced one more helper with presenter --- app/controllers/projects/pipelines_controller.rb | 2 +- app/views/projects/pipelines/_info.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 43a1abaa662..0da0420185d 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -114,7 +114,7 @@ class Projects::PipelinesController < Projects::ApplicationController end def pipeline - @pipeline ||= project.pipelines.find_by!(id: params[:id]) + @pipeline ||= project.pipelines.find_by!(id: params[:id]).present(current_user: current_user) end def commit diff --git a/app/views/projects/pipelines/_info.html.haml b/app/views/projects/pipelines/_info.html.haml index 17f38cef718..c9d83d23d56 100644 --- a/app/views/projects/pipelines/_info.html.haml +++ b/app/views/projects/pipelines/_info.html.haml @@ -1,6 +1,6 @@ .page-content-header .header-main-content - = render 'ci/status/badge', status: @pipeline.detailed_status(current_user), title: status_title(@pipeline) + = render 'ci/status/badge', status: @pipeline.detailed_status(current_user), title: @pipeline.status_title %strong Pipeline ##{@pipeline.id} triggered #{time_ago_with_tooltip(@pipeline.created_at)} - if @pipeline.user -- cgit v1.2.1 From 34eea29511b9730fdab0316573d26d864d0f1e98 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 5 Apr 2017 23:33:19 +0800 Subject: Fix test and only show job status title if it's cancelled and the pipeline is auto-cancelled. --- app/presenters/ci/build_presenter.rb | 6 +++ app/views/projects/builds/_header.html.haml | 4 +- app/views/projects/ci/builds/_build.html.haml | 75 ++++++++++++++------------- 3 files changed, 46 insertions(+), 39 deletions(-) (limited to 'app') diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb index ed72ed14d72..d9970396cc6 100644 --- a/app/presenters/ci/build_presenter.rb +++ b/app/presenters/ci/build_presenter.rb @@ -11,5 +11,11 @@ module Ci def erased_by_name erased_by.name if erased_by_user? end + + def status_title + if canceled? && pipeline.auto_canceled? + "Job is redundant and is auto-canceled by Pipeline ##{pipeline.auto_canceled_by_id}" + end + end end end diff --git a/app/views/projects/builds/_header.html.haml b/app/views/projects/builds/_header.html.haml index 67da50646c7..104db85809c 100644 --- a/app/views/projects/builds/_header.html.haml +++ b/app/views/projects/builds/_header.html.haml @@ -1,8 +1,8 @@ -- pipeline = @build.pipeline.present(current_user: current_user) +- pipeline = @build.pipeline .content-block.build-header.top-area .header-content - = render 'ci/status/badge', status: @build.detailed_status(current_user), link: false, title: pipeline.status_title + = render 'ci/status/badge', status: @build.detailed_status(current_user), link: false, title: @build.status_title Job %strong.js-build-id ##{@build.id} in pipeline diff --git a/app/views/projects/ci/builds/_build.html.haml b/app/views/projects/ci/builds/_build.html.haml index c57e4e81912..238662f1125 100644 --- a/app/views/projects/ci/builds/_build.html.haml +++ b/app/views/projects/ci/builds/_build.html.haml @@ -1,3 +1,5 @@ +- job = build.present(current_user: current_user) +- pipeline = job.pipeline - admin = local_assigns.fetch(:admin, false) - ref = local_assigns.fetch(:ref, nil) - commit_sha = local_assigns.fetch(:commit_sha, nil) @@ -6,48 +8,47 @@ - stage = local_assigns.fetch(:stage, false) - coverage = local_assigns.fetch(:coverage, false) - allow_retry = local_assigns.fetch(:allow_retry, false) -- pipeline = build.pipeline.present(current_user: current_user) %tr.build.commit{ class: ('retried' if retried) } %td.status - = render "ci/status/badge", status: build.detailed_status(current_user), title: pipeline.status_title + = render "ci/status/badge", status: job.detailed_status(current_user), title: job.status_title %td.branch-commit - - if can?(current_user, :read_build, build) - = link_to namespace_project_build_url(build.project.namespace, build.project, build) do - %span.build-link ##{build.id} + - if can?(current_user, :read_build, job) + = link_to namespace_project_build_url(job.project.namespace, job.project, job) do + %span.build-link ##{job.id} - else - %span.build-link ##{build.id} + %span.build-link ##{job.id} - if ref - - if build.ref + - if job.ref .icon-container - = build.tag? ? icon('tag') : icon('code-fork') - = link_to build.ref, namespace_project_commits_path(build.project.namespace, build.project, build.ref), class: "monospace branch-name" + = job.tag? ? icon('tag') : icon('code-fork') + = link_to job.ref, namespace_project_commits_path(job.project.namespace, job.project, job.ref), class: "monospace branch-name" - else .light none .icon-container.commit-icon = custom_icon("icon_commit") - if commit_sha - = link_to build.short_sha, namespace_project_commit_path(build.project.namespace, build.project, build.sha), class: "commit-id monospace" + = link_to job.short_sha, namespace_project_commit_path(job.project.namespace, job.project, job.sha), class: "commit-id monospace" - - if build.stuck? + - if job.stuck? = icon('warning', class: 'text-warning has-tooltip', title: 'Job is stuck. Check runners.') - if retried = icon('refresh', class: 'text-warning has-tooltip', title: 'Job was retried') .label-container - - if build.tags.any? - - build.tags.each do |tag| + - if job.tags.any? + - job.tags.each do |tag| %span.label.label-primary = tag - - if build.try(:trigger_request) + - if job.try(:trigger_request) %span.label.label-info triggered - - if build.try(:allow_failure) + - if job.try(:allow_failure) %span.label.label-danger allowed to fail - - if build.action? + - if job.action? %span.label.label-info manual - if pipeline_link @@ -62,49 +63,49 @@ - if admin %td - - if build.project - = link_to build.project.name_with_namespace, admin_namespace_project_path(build.project.namespace, build.project) + - if job.project + = link_to job.project.name_with_namespace, admin_namespace_project_path(job.project.namespace, job.project) %td - - if build.try(:runner) - = runner_link(build.runner) + - if job.try(:runner) + = runner_link(job.runner) - else .light none - if stage %td - = build.stage + = job.stage %td - = build.name + = job.name %td - - if build.duration + - if job.duration %p.duration = custom_icon("icon_timer") - = duration_in_numbers(build.duration) + = duration_in_numbers(job.duration) - - if build.finished_at + - if job.finished_at %p.finished-at = icon("calendar") - %span= time_ago_with_tooltip(build.finished_at) + %span= time_ago_with_tooltip(job.finished_at) %td.coverage - - if coverage && build.try(:coverage) - #{build.coverage}% + - if coverage && job.try(:coverage) + #{job.coverage}% %td .pull-right - - if can?(current_user, :read_build, build) && build.artifacts? - = link_to download_namespace_project_build_artifacts_path(build.project.namespace, build.project, build), rel: 'nofollow', download: '', title: 'Download artifacts', class: 'btn btn-build' do + - if can?(current_user, :read_build, job) && job.artifacts? + = link_to download_namespace_project_build_artifacts_path(job.project.namespace, job.project, job), rel: 'nofollow', download: '', title: 'Download artifacts', class: 'btn btn-build' do = icon('download') - - if can?(current_user, :update_build, build) - - if build.active? - = link_to cancel_namespace_project_build_path(build.project.namespace, build.project, build, return_to: request.original_url), method: :post, title: 'Cancel', class: 'btn btn-build' do + - if can?(current_user, :update_build, job) + - if job.active? + = link_to cancel_namespace_project_build_path(job.project.namespace, job.project, job, return_to: request.original_url), method: :post, title: 'Cancel', class: 'btn btn-build' do = icon('remove', class: 'cred') - elsif allow_retry - - if build.playable? && !admin - = link_to play_namespace_project_build_path(build.project.namespace, build.project, build, return_to: request.original_url), method: :post, title: 'Play', class: 'btn btn-build' do + - if job.playable? && !admin + = link_to play_namespace_project_build_path(job.project.namespace, job.project, job, return_to: request.original_url), method: :post, title: 'Play', class: 'btn btn-build' do = custom_icon('icon_play') - - elsif build.retryable? - = link_to retry_namespace_project_build_path(build.project.namespace, build.project, build, return_to: request.original_url), method: :post, title: 'Retry', class: 'btn btn-build' do + - elsif job.retryable? + = link_to retry_namespace_project_build_path(job.project.namespace, job.project, job, return_to: request.original_url), method: :post, title: 'Retry', class: 'btn btn-build' do = icon('repeat') -- cgit v1.2.1 From 33deaaf3061bccba7bcaf591aaf9d0dc025f1e6e Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Apr 2017 00:29:08 +0800 Subject: Remove tooltip from API and vue, follow up: https://gitlab.com/gitlab-org/gitlab-ce/issues/30511 --- app/assets/javascripts/vue_pipelines_index/components/status.js | 7 +------ app/serializers/pipeline_entity.rb | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/vue_pipelines_index/components/status.js b/app/assets/javascripts/vue_pipelines_index/components/status.js index ece1ec89f89..21a281af438 100644 --- a/app/assets/javascripts/vue_pipelines_index/components/status.js +++ b/app/assets/javascripts/vue_pipelines_index/components/status.js @@ -36,7 +36,7 @@ export default { computed: { cssClasses() { - return `ci-status ci-${this.pipeline.details.status.group} has-tooltip`; + return `ci-status ci-${this.pipeline.details.status.group}`; }, detailsPath() { @@ -47,17 +47,12 @@ export default { content() { return `${this.svg} ${this.pipeline.details.status.text}`; }, - - tooltipTitle() { - return this.pipeline.details.status_tooltip; - }, }, template: ` diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 78af8b51709..3f16dd66d54 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -13,7 +13,6 @@ class PipelineEntity < Grape::Entity expose :details do expose :detailed_status, as: :status, with: StatusEntity - expose :status_tooltip expose :duration expose :finished_at expose :stages, using: StageEntity @@ -82,8 +81,4 @@ class PipelineEntity < Grape::Entity def detailed_status pipeline.detailed_status(request.user) end - - def status_tooltip - pipeline.present(current_user: request.user).status_title - end end -- cgit v1.2.1 From e258e6f1471fb176e39daf6fef7785af120c2178 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Apr 2017 03:10:52 +0800 Subject: Add test for presenters --- app/models/ci/pipeline.rb | 4 ++++ app/presenters/ci/pipeline_presenter.rb | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 9ef35ebdd50..8aad149519e 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -219,6 +219,10 @@ module Ci statuses.cancelable.any? end + def auto_canceled? + canceled? && auto_canceled_by_id? + end + def cancel_running Gitlab::OptimisticLocking.retry_lock( statuses.cancelable) do |cancelable| diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb index 8f9e4fa707d..b8e74bf5509 100644 --- a/app/presenters/ci/pipeline_presenter.rb +++ b/app/presenters/ci/pipeline_presenter.rb @@ -2,10 +2,6 @@ module Ci class PipelinePresenter < Gitlab::View::Presenter::Delegated presents :pipeline - def auto_canceled? - canceled? && auto_canceled_by_id? - end - def status_title "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" if auto_canceled? end -- cgit v1.2.1 From 057c0d7a5c062f3030bcc46614ef2442009002de Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Apr 2017 21:32:56 +0800 Subject: Also track auto-cancelling in jobs, detail: Not only tracking auto-cancelling in pipelines, we'll also track this in jobs because pipelines could be retried and the information would get lost when this happened. Also erase auto-cancelling relation for pipelines when they're retried. --- app/models/ci/pipeline.rb | 19 ++++++++++++++++++- app/models/commit_status.rb | 5 +++++ app/presenters/ci/build_presenter.rb | 4 ++-- app/presenters/ci/pipeline_presenter.rb | 4 +++- app/services/ci/create_pipeline_service.rb | 3 +-- 5 files changed, 29 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 8aad149519e..e03def25755 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -11,6 +11,8 @@ module Ci belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id' + has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id' + has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id has_many :builds, foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id @@ -93,6 +95,10 @@ module Ci PipelineNotificationWorker.perform_async(pipeline.id) end end + + after_transition :canceled => any - [:canceled] do |pipeline| + pipeline.update(auto_canceled_by: nil) + end end # ref can't be HEAD or SHA, can only be branch/tag name @@ -226,10 +232,21 @@ module Ci def cancel_running Gitlab::OptimisticLocking.retry_lock( statuses.cancelable) do |cancelable| - cancelable.find_each(&:cancel) + cancelable.find_each do |job| + yield(job) if block_given? + job.cancel + end end end + def auto_cancel_running(pipeline) + update(auto_canceled_by: pipeline) + + cancel_running do |job| + job.auto_canceled_by = pipeline + end + end + def retry_failed(current_user) Ci::RetryPipelineService.new(project, current_user) .execute(self) diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 17b322b5ae3..2c4033146bf 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -7,6 +7,7 @@ class CommitStatus < ActiveRecord::Base belongs_to :project belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :commit_id + belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' belongs_to :user delegate :commit, to: :pipeline @@ -137,6 +138,10 @@ class CommitStatus < ActiveRecord::Base false end + def auto_canceled? + canceled? && auto_canceled_by_id? + end + # Added in 9.0 to keep backward compatibility for projects exported in 8.17 # and prior. def gl_project_id diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb index d9970396cc6..c495c3f39bb 100644 --- a/app/presenters/ci/build_presenter.rb +++ b/app/presenters/ci/build_presenter.rb @@ -13,8 +13,8 @@ module Ci end def status_title - if canceled? && pipeline.auto_canceled? - "Job is redundant and is auto-canceled by Pipeline ##{pipeline.auto_canceled_by_id}" + if auto_canceled? + "Job is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" end end end diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb index b8e74bf5509..a542bdd8295 100644 --- a/app/presenters/ci/pipeline_presenter.rb +++ b/app/presenters/ci/pipeline_presenter.rb @@ -3,7 +3,9 @@ module Ci presents :pipeline def status_title - "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" if auto_canceled? + if auto_canceled? + "Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" + end end end end diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index f944c869922..21350be5557 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -68,8 +68,7 @@ module Ci def cancel_pending_pipelines Gitlab::OptimisticLocking.retry_lock(auto_cancelable_pipelines) do |cancelables| cancelables.find_each do |cancelable| - cancelable.cancel_running - cancelable.update_attributes(auto_canceled_by_id: pipeline.id) + cancelable.auto_cancel_running(pipeline) end end end -- cgit v1.2.1 From 38c324b95fb10d7d49a2d54e1d2cb53528f03d3f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Apr 2017 21:38:45 +0800 Subject: We don't have to save, transition would save for us --- app/models/ci/pipeline.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index e03def25755..23c6ad819c4 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -97,7 +97,7 @@ module Ci end after_transition :canceled => any - [:canceled] do |pipeline| - pipeline.update(auto_canceled_by: nil) + pipeline.auto_canceled_by = nil end end -- cgit v1.2.1 From cdfa17c429964bb730f7c444e2163a7463963dd8 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Apr 2017 22:04:45 +0800 Subject: Use before_transition --- app/models/ci/pipeline.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 23c6ad819c4..9165565d8fd 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -70,6 +70,10 @@ module Ci pipeline.update_duration end + before_transition :canceled => any - [:canceled] do |pipeline| + pipeline.auto_canceled_by = nil + end + after_transition [:created, :pending] => :running do |pipeline| pipeline.run_after_commit { PipelineMetricsWorker.perform_async(id) } end @@ -95,10 +99,6 @@ module Ci PipelineNotificationWorker.perform_async(pipeline.id) end end - - after_transition :canceled => any - [:canceled] do |pipeline| - pipeline.auto_canceled_by = nil - end end # ref can't be HEAD or SHA, can only be branch/tag name -- cgit v1.2.1 From 503f8822758fd6deb93e448bf37e1e3e70422e29 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Apr 2017 23:47:37 +0800 Subject: Fix rubocop offenses --- app/models/ci/pipeline.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 9165565d8fd..250ae496b06 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -70,7 +70,7 @@ module Ci pipeline.update_duration end - before_transition :canceled => any - [:canceled] do |pipeline| + before_transition canceled: any - [:canceled] do |pipeline| pipeline.auto_canceled_by = nil end -- cgit v1.2.1 From 38796f56173caa2ed6575a4f60f7bf07ed90af55 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 7 Apr 2017 14:47:15 +0800 Subject: Fix bad conflict resolution --- app/models/ci/pipeline.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 134ca5f60a3..1f47756269e 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -228,13 +228,12 @@ module Ci end def cancel_running - Gitlab::OptimisticLocking.retry_lock( - statuses.cancelable) do |cancelable| - cancelable.find_each do |job| - yield(job) if block_given? - job.cancel - end + Gitlab::OptimisticLocking.retry_lock(cancelable_statuses) do |cancelable| + cancelable.find_each do |job| + yield(job) if block_given? + job.cancel end + end end def auto_cancel_running(pipeline) -- cgit v1.2.1