diff options
author | Stan Hu <stanhu@gmail.com> | 2017-12-05 22:24:20 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-12-12 15:07:23 -0800 |
commit | f6966cfa63fab7e3c8847d69101c6c6a444fb85f (patch) | |
tree | d26bcf1a227a13fa49388f7a49e39a5eb1e0fbb7 | |
parent | 8e7f19c60bea4eec86844be1e0db12ebf30f105e (diff) | |
download | gitlab-ce-f6966cfa63fab7e3c8847d69101c6c6a444fb85f.tar.gz |
Address some comments with running a pipeline schedule
-rw-r--r-- | app/controllers/projects/pipeline_schedules_controller.rb | 6 | ||||
-rw-r--r-- | app/helpers/gitlab_routing_helper.rb | 4 | ||||
-rw-r--r-- | app/workers/run_pipeline_schedule_worker.rb | 6 | ||||
-rw-r--r-- | config/routes/project.rb | 2 | ||||
-rw-r--r-- | spec/controllers/projects/pipeline_schedules_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/workers/run_pipeline_schedule_worker_spec.rb | 15 |
6 files changed, 21 insertions, 16 deletions
diff --git a/app/controllers/projects/pipeline_schedules_controller.rb b/app/controllers/projects/pipeline_schedules_controller.rb index 9fc7935950d..38edb38f9fc 100644 --- a/app/controllers/projects/pipeline_schedules_controller.rb +++ b/app/controllers/projects/pipeline_schedules_controller.rb @@ -1,10 +1,10 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController before_action :schedule, except: [:index, :new, :create] - before_action :authorize_create_pipeline!, only: [:run] + before_action :authorize_create_pipeline!, only: [:play] before_action :authorize_read_pipeline_schedule! before_action :authorize_create_pipeline_schedule!, only: [:new, :create] - before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :run] + before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :play] before_action :authorize_admin_pipeline_schedule!, only: [:destroy] def index @@ -41,7 +41,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController end end - def run + def play job_id = RunPipelineScheduleWorker.perform_async(schedule.id, current_user.id) flash[:notice] = diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb index 5f72c6e64b6..7f3c118c7ab 100644 --- a/app/helpers/gitlab_routing_helper.rb +++ b/app/helpers/gitlab_routing_helper.rb @@ -182,9 +182,9 @@ module GitlabRoutingHelper edit_project_pipeline_schedule_path(project, schedule) end - def run_pipeline_schedule_path(schedule, *args) + def play_pipeline_schedule_path(schedule, *args) project = schedule.project - run_project_pipeline_schedule_path(project, schedule, *args) + play_project_pipeline_schedule_path(project, schedule, *args) end def take_ownership_pipeline_schedule_path(schedule, *args) diff --git a/app/workers/run_pipeline_schedule_worker.rb b/app/workers/run_pipeline_schedule_worker.rb index ac6371f0871..3e0d3fed20a 100644 --- a/app/workers/run_pipeline_schedule_worker.rb +++ b/app/workers/run_pipeline_schedule_worker.rb @@ -5,8 +5,10 @@ class RunPipelineScheduleWorker enqueue_in group: :creation def perform(schedule_id, user_id) - schedule = Ci::PipelineSchedule.find(schedule_id) - user = User.find(user_id) + schedule = Ci::PipelineSchedule.find_by(id: schedule_id) + user = User.find_by(id: user_id) + + return unless schedule && user run_pipeline_schedule(schedule, user) end diff --git a/config/routes/project.rb b/config/routes/project.rb index 3dcb21e45c5..239b5480321 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -179,7 +179,7 @@ constraints(ProjectUrlConstrainer.new) do resources :pipeline_schedules, except: [:show] do member do - post :run + post :play post :take_ownership end end diff --git a/spec/controllers/projects/pipeline_schedules_controller_spec.rb b/spec/controllers/projects/pipeline_schedules_controller_spec.rb index 384a407a100..e875f5bce08 100644 --- a/spec/controllers/projects/pipeline_schedules_controller_spec.rb +++ b/spec/controllers/projects/pipeline_schedules_controller_spec.rb @@ -364,7 +364,7 @@ describe Projects::PipelineSchedulesController do end end - describe 'POST #run' do + describe 'POST #play' do set(:user) { create(:user) } context 'when a developer makes the request' do @@ -384,7 +384,7 @@ describe Projects::PipelineSchedulesController do end def go - post :run, namespace_id: project.namespace.to_param, project_id: project, id: pipeline_schedule.id + post :play, namespace_id: project.namespace.to_param, project_id: project, id: pipeline_schedule.id end end diff --git a/spec/workers/run_pipeline_schedule_worker_spec.rb b/spec/workers/run_pipeline_schedule_worker_spec.rb index 4a88ac51f62..481a84837f9 100644 --- a/spec/workers/run_pipeline_schedule_worker_spec.rb +++ b/spec/workers/run_pipeline_schedule_worker_spec.rb @@ -2,27 +2,30 @@ require 'spec_helper' describe RunPipelineScheduleWorker do describe '#perform' do - let(:project) { create(:project) } + set(:project) { create(:project) } + set(:user) { create(:user) } + set(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) } let(:worker) { described_class.new } - let(:user) { create(:user) } - let(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) } context 'when a project not found' do it 'does not call the Service' do expect(Ci::CreatePipelineService).not_to receive(:new) - expect { worker.perform(100000, user.id) }.to raise_error(ActiveRecord::RecordNotFound) + expect(worker).not_to receive(:run_pipeline_schedule) + + worker.perform(100000, user.id) end end context 'when a user not found' do it 'does not call the Service' do expect(Ci::CreatePipelineService).not_to receive(:new) - expect { worker.perform(pipeline_schedule.id, 10000) }.to raise_error(ActiveRecord::RecordNotFound) + expect(worker).not_to receive(:run_pipeline_schedule) + + worker.perform(pipeline_schedule.id, 10000) end end context 'when everything is ok' do - let(:project) { create(:project) } let(:create_pipeline_service) { instance_double(Ci::CreatePipelineService) } it 'calls the Service' do |