diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/services/security/ci_configuration/base_create_service.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.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 | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/app/services/security/ci_configuration/base_create_service.rb b/app/services/security/ci_configuration/base_create_service.rb index 7f3b66d40e1..aaa850fde39 100644 --- a/app/services/security/ci_configuration/base_create_service.rb +++ b/app/services/security/ci_configuration/base_create_service.rb @@ -3,7 +3,7 @@ module Security module CiConfiguration class BaseCreateService - attr_reader :branch_name, :current_user, :project + attr_reader :branch_name, :current_user, :project, :name def initialize(project, current_user) @project = project @@ -41,8 +41,18 @@ module Security end def existing_gitlab_ci_content - @gitlab_ci_yml ||= project.ci_config_for(project.repository.root_ref_sha) + root_ref = root_ref_sha(project) + return if root_ref.nil? + + @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-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" end def successful_change_path @@ -61,6 +71,15 @@ module Security self.class.to_s, action[:action], label: action[:default_values_overwritten].to_s ) end + + def root_ref_sha(project) + project.repository.root_ref_sha + rescue StandardError => e + # this might fail on the very first commit, + # and unfortunately it raises a StandardError + Gitlab::ErrorTracking.track_exception(e, project_id: project.id) + nil + end end end end |