Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/security/ci_configuration/base_create_service.rb')
-rw-r--r--app/services/security/ci_configuration/base_create_service.rb24
1 files changed, 15 insertions, 9 deletions
diff --git a/app/services/security/ci_configuration/base_create_service.rb b/app/services/security/ci_configuration/base_create_service.rb
index b60a949fd4e..a205a68532b 100644
--- a/app/services/security/ci_configuration/base_create_service.rb
+++ b/app/services/security/ci_configuration/base_create_service.rb
@@ -2,6 +2,8 @@
module Security
module CiConfiguration
+ CiContentParseError = Class.new(StandardError)
+
class BaseCreateService
attr_reader :branch_name, :current_user, :project, :name
@@ -15,12 +17,13 @@ module Security
if project.repository.empty? && !(@params && @params[:initialize_with_sast])
docs_link = ActionController::Base.helpers.link_to _('add at least one file to the repository'),
Rails.application.routes.url_helpers.help_page_url('user/project/repository/index.md',
- anchor: 'add-files-to-a-repository'),
+ anchor: 'add-files-to-a-repository'),
target: '_blank',
rel: 'noopener noreferrer'
- raise Gitlab::Graphql::Errors::MutationError,
- Gitlab::Utils::ErrorMessage.to_user_facing(
- _(format('You must %s before using Security features.', docs_link.html_safe)).html_safe)
+
+ return ServiceResponse.error(
+ message: _(format('You must %s before using Security features.', docs_link)).html_safe
+ )
end
project.repository.add_branch(current_user, branch_name, project.default_branch)
@@ -33,6 +36,10 @@ module Security
track_event(attributes_for_commit)
ServiceResponse.success(payload: { branch: branch_name, success_path: successful_change_path })
+ rescue CiContentParseError => e
+ Gitlab::ErrorTracking.track_exception(e)
+
+ ServiceResponse.error(message: e.message)
rescue Gitlab::Git::PreReceiveError => e
ServiceResponse.error(message: e.message)
rescue StandardError
@@ -58,13 +65,12 @@ module Security
@gitlab_ci_yml ||= project.ci_config_for(root_ref)
YAML.safe_load(@gitlab_ci_yml) if @gitlab_ci_yml
rescue Psych::BadAlias
- raise Gitlab::Graphql::Errors::MutationError,
- Gitlab::Utils::ErrorMessage.to_user_facing(
- _(".gitlab-ci.yml with aliases/anchors is not supported. Please change the CI configuration manually."))
+ raise CiContentParseError, _(".gitlab-ci.yml with aliases/anchors is not supported. " \
+ "Please change the CI configuration manually.")
rescue Psych::Exception => e
Gitlab::AppLogger.error("Failed to process existing .gitlab-ci.yml: #{e.message}")
- raise Gitlab::Graphql::Errors::MutationError,
- "#{name} merge request creation mutation failed"
+
+ raise CiContentParseError, "#{name} merge request creation failed"
end
def successful_change_path