diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /app/services/security/ci_configuration/base_create_service.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'app/services/security/ci_configuration/base_create_service.rb')
-rw-r--r-- | app/services/security/ci_configuration/base_create_service.rb | 24 |
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 |