summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-20 12:10:29 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-20 12:10:29 +0000
commita84766a28a87c0342c6b048f5ea2eab2f3216fcf (patch)
treec929643b8b21e05da13692620bd508a869d6fbe7 /app/services
parentf5f1f221ba08228dbbdd7080509028a7cac2fce2 (diff)
downloadgitlab-ce-a84766a28a87c0342c6b048f5ea2eab2f3216fcf.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/ci/create_downstream_pipeline_service.rb5
-rw-r--r--app/services/ci/create_pipeline_service.rb16
-rw-r--r--app/services/ci/external_pull_requests/create_pipeline_service.rb11
-rw-r--r--app/services/ci/pipeline_trigger_service.rb8
-rw-r--r--app/services/merge_requests/create_pipeline_service.rb6
-rw-r--r--app/services/projects/lfs_pointers/lfs_object_download_list_service.rb18
6 files changed, 49 insertions, 15 deletions
diff --git a/app/services/ci/create_downstream_pipeline_service.rb b/app/services/ci/create_downstream_pipeline_service.rb
index e9ec2338171..a65c22e273c 100644
--- a/app/services/ci/create_downstream_pipeline_service.rb
+++ b/app/services/ci/create_downstream_pipeline_service.rb
@@ -33,8 +33,9 @@ module Ci
current_user,
pipeline_params.fetch(:target_revision))
- downstream_pipeline = service.execute(
- pipeline_params.fetch(:source), **pipeline_params[:execute_params])
+ downstream_pipeline = service
+ .execute(pipeline_params.fetch(:source), **pipeline_params[:execute_params])
+ .payload
downstream_pipeline.tap do |pipeline|
update_bridge_status!(@bridge, pipeline)
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index c039f31aafc..bc95e601e6c 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -87,12 +87,16 @@ module Ci
if pipeline.persisted?
schedule_head_pipeline_update
create_namespace_onboarding_action
+ else
+ # If pipeline is not persisted, try to recover IID
+ pipeline.reset_project_iid
end
- # If pipeline is not persisted, try to recover IID
- pipeline.reset_project_iid unless pipeline.persisted?
-
- pipeline
+ if error_message = pipeline.full_error_messages.presence || pipeline.failure_reason.presence
+ ServiceResponse.error(message: error_message, payload: pipeline)
+ else
+ ServiceResponse.success(payload: pipeline)
+ end
end
# rubocop: enable Metrics/ParameterLists
@@ -100,8 +104,8 @@ module Ci
source = args[0]
params = Hash(args[1])
- execute(source, **params, &block).tap do |pipeline|
- unless pipeline.persisted?
+ execute(source, **params, &block).tap do |response|
+ unless response.payload.persisted?
raise CreateError, pipeline.full_error_messages
end
end
diff --git a/app/services/ci/external_pull_requests/create_pipeline_service.rb b/app/services/ci/external_pull_requests/create_pipeline_service.rb
index 78be94bfb41..83499524a8e 100644
--- a/app/services/ci/external_pull_requests/create_pipeline_service.rb
+++ b/app/services/ci/external_pull_requests/create_pipeline_service.rb
@@ -7,7 +7,8 @@ module Ci
module ExternalPullRequests
class CreatePipelineService < BaseService
def execute(pull_request)
- return unless pull_request.open? && pull_request.actual_branch_head?
+ return pull_request_not_open_error unless pull_request.open?
+ return pull_request_branch_error unless pull_request.actual_branch_head?
create_pipeline_for(pull_request)
end
@@ -26,6 +27,14 @@ module Ci
target_sha: pull_request.target_sha
}
end
+
+ def pull_request_not_open_error
+ ServiceResponse.error(message: 'The pull request is not opened', payload: nil)
+ end
+
+ def pull_request_branch_error
+ ServiceResponse.error(message: 'The source sha is not the head of the source branch', payload: nil)
+ end
end
end
end
diff --git a/app/services/ci/pipeline_trigger_service.rb b/app/services/ci/pipeline_trigger_service.rb
index 62c4d6b4599..7746382b845 100644
--- a/app/services/ci/pipeline_trigger_service.rb
+++ b/app/services/ci/pipeline_trigger_service.rb
@@ -27,13 +27,13 @@ module Ci
# this check is to not leak the presence of the project if user cannot read it
return unless trigger.project == project
- pipeline = Ci::CreatePipelineService
+ response = Ci::CreatePipelineService
.new(project, trigger.owner, ref: params[:ref], variables_attributes: variables)
.execute(:trigger, ignore_skip_ci: true) do |pipeline|
pipeline.trigger_requests.build(trigger: trigger)
end
- pipeline_service_response(pipeline)
+ pipeline_service_response(response.payload)
end
def pipeline_service_response(pipeline)
@@ -57,7 +57,7 @@ module Ci
# this check is to not leak the presence of the project if user cannot read it
return unless can?(job.user, :read_project, project)
- pipeline = Ci::CreatePipelineService
+ response = Ci::CreatePipelineService
.new(project, job.user, ref: params[:ref], variables_attributes: variables)
.execute(:pipeline, ignore_skip_ci: true) do |pipeline|
source = job.sourced_pipelines.build(
@@ -69,7 +69,7 @@ module Ci
pipeline.source_pipeline = source
end
- pipeline_service_response(pipeline)
+ pipeline_service_response(response.payload)
end
def job_from_token
diff --git a/app/services/merge_requests/create_pipeline_service.rb b/app/services/merge_requests/create_pipeline_service.rb
index ebeba0ee5b8..6b032545230 100644
--- a/app/services/merge_requests/create_pipeline_service.rb
+++ b/app/services/merge_requests/create_pipeline_service.rb
@@ -3,7 +3,7 @@
module MergeRequests
class CreatePipelineService < MergeRequests::BaseService
def execute(merge_request)
- return unless can_create_pipeline_for?(merge_request)
+ return cannot_create_pipeline_error unless can_create_pipeline_for?(merge_request)
create_detached_merge_request_pipeline(merge_request)
end
@@ -60,6 +60,10 @@ module MergeRequests
::Gitlab::UserAccess.new(current_user, container: merge_request.target_project)
.can_update_branch?(merge_request.source_branch_ref)
end
+
+ def cannot_create_pipeline_error
+ ServiceResponse.error(message: 'Cannot create a pipeline for this merge request.', payload: nil)
+ end
end
end
diff --git a/app/services/projects/lfs_pointers/lfs_object_download_list_service.rb b/app/services/projects/lfs_pointers/lfs_object_download_list_service.rb
index 75106297043..b4872cd9442 100644
--- a/app/services/projects/lfs_pointers/lfs_object_download_list_service.rb
+++ b/app/services/projects/lfs_pointers/lfs_object_download_list_service.rb
@@ -31,7 +31,7 @@ module Projects
#
LfsDownloadLinkListService
.new(project, remote_uri: current_endpoint_uri)
- .execute(lfs_pointers_in_repository)
+ .execute(missing_lfs_files)
rescue LfsDownloadLinkListService::DownloadLinksError => e
raise LfsObjectDownloadListError, "The LFS objects download list couldn't be imported. Error: #{e.message}"
end
@@ -53,6 +53,22 @@ module Projects
@lfs_pointers_in_repository ||= LfsListService.new(project).execute
end
+ def existing_lfs_objects
+ project.lfs_objects
+ end
+
+ def existing_lfs_objects_hash
+ {}.tap do |hash|
+ existing_lfs_objects.find_each do |lfs_object|
+ hash[lfs_object.oid] = lfs_object.size
+ end
+ end
+ end
+
+ def missing_lfs_files
+ lfs_pointers_in_repository.except(*existing_lfs_objects_hash.keys)
+ end
+
def lfsconfig_endpoint_uri
strong_memoize(:lfsconfig_endpoint_uri) do
# Retrieveing the blob data from the .lfsconfig file