summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2019-05-02 17:30:33 +0700
committerShinya Maeda <shinya@gitlab.com>2019-05-02 20:17:33 +0700
commit339452ff4c89c3257298ac4cf82b510cb2b72f3d (patch)
tree642b37c2d5dcf2f2bfdc7b65ebf9ce3736aeebb0
parenta8347c22d0e33ab626ee4c3b4b9acffa69f7cf46 (diff)
downloadgitlab-ce-create-pipelines-for-merge-request-service.tar.gz
Public API support for pipelines for merge requestscreate-pipelines-for-merge-request-service
Currently, we don't support pipeline creation for Pipelines for Merge Requests. We add the support with a dedicated pipeline creation service.
-rw-r--r--app/services/merge_requests/base_service.rb4
-rw-r--r--app/services/merge_requests/create_pipeline_service.rb11
-rw-r--r--lib/api/merge_requests.rb20
-rw-r--r--spec/services/merge_requests/refresh_service_spec.rb12
4 files changed, 31 insertions, 16 deletions
diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb
index a9dd26c02ad..b6054180070 100644
--- a/app/services/merge_requests/base_service.rb
+++ b/app/services/merge_requests/base_service.rb
@@ -78,10 +78,6 @@ module MergeRequests
end
def can_create_pipeline_for?(merge_request)
- ##
- # UpdateMergeRequestsWorker could be retried by an exception.
- # pipelines for merge request should not be recreated in such case.
- return false if merge_request.merge_request_pipeline_exists?
return false if merge_request.has_no_commits?
true
diff --git a/app/services/merge_requests/create_pipeline_service.rb b/app/services/merge_requests/create_pipeline_service.rb
new file mode 100644
index 00000000000..ed12169ee8c
--- /dev/null
+++ b/app/services/merge_requests/create_pipeline_service.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module MergeRequests
+ class CreatePipelineService < MergeRequests::BaseService
+ def execute(merge_request)
+ create_pipeline_for(merge_request).tap do |pipeline|
+ merge_request.update_head_pipeline if pipeline&.persisted?
+ end
+ end
+ end
+end
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index ce85772e4ed..d842f9f9412 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -317,6 +317,26 @@ module API
present paginate(pipelines), with: Entities::PipelineBasic
end
+ desc 'Create a pipeline for merge request' do
+ success Entities::Pipeline
+ end
+ post ':id/merge_requests/:merge_request_iid/pipeline' do
+ authorize! :create_pipeline, user_project
+
+ mr = find_merge_request_with_access(params[:merge_request_iid])
+
+ pipeline = MergeRequest::CreatePipelineService
+ .new(user_project, current_user).execute(mr)
+
+ not_allowed! unless pipeline
+
+ if pipeline.persisted?
+ present pipeline, with: Entities::Pipeline
+ else
+ render_validation_error!(pipeline)
+ end
+ end
+
desc 'Update a merge request' do
success Entities::MergeRequest
end
diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb
index d20b2d81763..13cedf781bf 100644
--- a/spec/services/merge_requests/refresh_service_spec.rb
+++ b/spec/services/merge_requests/refresh_service_spec.rb
@@ -240,18 +240,6 @@ describe MergeRequests::RefreshService do
expect(@merge_request.all_pipelines.second).to be_push
end
end
-
- context "when MergeRequestUpdateWorker is retried by an exception" do
- it 'does not re-create a duplicate detached merge request pipeline' do
- expect do
- service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/master')
- end.to change { @merge_request.merge_request_pipelines.count }.by(1)
-
- expect do
- service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/master')
- end.not_to change { @merge_request.merge_request_pipelines.count }
- end
- end
end
context "when .gitlab-ci.yml does not have merge_requests keywords" do