diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-08 00:11:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-08 00:11:49 +0300 |
commit | 4fcfdad283a25ee4d1e955954aeceb08d7ffd5f7 (patch) | |
tree | f90b6e55f2cf974ea14c38cd065aa3b65fe3715a /app/services/security | |
parent | 5a71c032e8e0dcb5593df5c257c88487e332e5e5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/security')
-rw-r--r-- | app/services/security/ci_configuration/base_create_service.rb | 6 | ||||
-rw-r--r-- | app/services/security/ci_configuration/sast_create_service.rb | 17 |
2 files changed, 20 insertions, 3 deletions
diff --git a/app/services/security/ci_configuration/base_create_service.rb b/app/services/security/ci_configuration/base_create_service.rb index adb45244adb..ea77cd98ba3 100644 --- a/app/services/security/ci_configuration/base_create_service.rb +++ b/app/services/security/ci_configuration/base_create_service.rb @@ -25,7 +25,7 @@ module Security rescue Gitlab::Git::PreReceiveError => e ServiceResponse.error(message: e.message) rescue StandardError - project.repository.rm_branch(current_user, branch_name) if project.repository.branch_exists?(branch_name) + remove_branch_on_exception raise end @@ -50,6 +50,10 @@ module Security Gitlab::Routing.url_helpers.project_new_merge_request_url(project, merge_request: merge_request_params) end + def remove_branch_on_exception + project.repository.rm_branch(current_user, branch_name) if project.repository.branch_exists?(branch_name) + end + def track_event(attributes_for_commit) action = attributes_for_commit[:actions].first diff --git a/app/services/security/ci_configuration/sast_create_service.rb b/app/services/security/ci_configuration/sast_create_service.rb index f495cac18f8..47e01847b17 100644 --- a/app/services/security/ci_configuration/sast_create_service.rb +++ b/app/services/security/ci_configuration/sast_create_service.rb @@ -5,15 +5,28 @@ module Security class SastCreateService < ::Security::CiConfiguration::BaseCreateService attr_reader :params - def initialize(project, current_user, params) + def initialize(project, current_user, params, commit_on_default: false) super(project, current_user) @params = params + + @commit_on_default = commit_on_default + @branch_name = project.default_branch if @commit_on_default end private + def remove_branch_on_exception + super unless @commit_on_default + end + def action - Security::CiConfiguration::SastBuildAction.new(project.auto_devops_enabled?, params, existing_gitlab_ci_content).generate + existing_content = begin + existing_gitlab_ci_content # this can fail on the very first commit + rescue StandardError + nil + end + + Security::CiConfiguration::SastBuildAction.new(project.auto_devops_enabled?, params, existing_content).generate end def next_branch |