diff options
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 |