debian-mirror-gitlab/app/services/security/ci_configuration/sast_create_service.rb

46 lines
1.3 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
module Security
module CiConfiguration
2021-06-08 01:23:25 +05:30
class SastCreateService < ::Security::CiConfiguration::BaseCreateService
attr_reader :params
2021-11-18 22:05:49 +05:30
def initialize(project, current_user, params, commit_on_default: false)
2021-06-08 01:23:25 +05:30
super(project, current_user)
2021-03-11 19:13:27 +05:30
@params = params
2021-11-18 22:05:49 +05:30
@commit_on_default = commit_on_default
@branch_name = project.default_branch if @commit_on_default
2021-03-11 19:13:27 +05:30
end
private
2021-11-18 22:05:49 +05:30
def remove_branch_on_exception
super unless @commit_on_default
end
2021-06-08 01:23:25 +05:30
def action
2021-11-18 22:05:49 +05:30
existing_content = begin
existing_gitlab_ci_content # this can fail on the very first commit
rescue StandardError
nil
end
2022-05-07 20:08:51 +05:30
Security::CiConfiguration::SastBuildAction.new(project.auto_devops_enabled?, params, existing_content, project.ci_config_path).generate
2021-03-11 19:13:27 +05:30
end
2021-06-08 01:23:25 +05:30
def next_branch
'set-sast-config'
2021-03-11 19:13:27 +05:30
end
2021-06-08 01:23:25 +05:30
def message
_('Configure SAST in `.gitlab-ci.yml`, creating this file if it does not already exist')
2021-03-11 19:13:27 +05:30
end
2021-06-08 01:23:25 +05:30
def description
_('Configure SAST in `.gitlab-ci.yml` using the GitLab managed template. You can [add variable overrides](https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings) to customize SAST settings.')
2021-03-11 19:13:27 +05:30
end
end
end
end