2021-01-20 19:11:07 -05:00
# frozen_string_literal: true
module Security
module CiConfiguration
2021-04-28 08:10:09 -04:00
class SastCreateService < :: Security :: CiConfiguration :: BaseCreateService
attr_reader :params
2021-10-07 17:11:49 -04:00
def initialize ( project , current_user , params , commit_on_default : false )
2021-04-28 08:10:09 -04:00
super ( project , current_user )
2021-01-20 19:11:07 -05:00
@params = params
2021-10-07 17:11:49 -04:00
@commit_on_default = commit_on_default
@branch_name = project . default_branch if @commit_on_default
2021-01-20 19:11:07 -05:00
end
private
2021-10-07 17:11:49 -04:00
def remove_branch_on_exception
super unless @commit_on_default
end
2021-04-28 08:10:09 -04:00
def action
2021-10-07 17:11:49 -04:00
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
2021-01-20 19:11:07 -05:00
end
2021-04-28 08:10:09 -04:00
def next_branch
'set-sast-config'
2021-01-20 19:11:07 -05:00
end
2021-04-28 08:10:09 -04:00
def message
_ ( 'Configure SAST in `.gitlab-ci.yml`, creating this file if it does not already exist' )
2021-01-20 19:11:07 -05:00
end
2021-04-28 08:10:09 -04:00
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-01-20 19:11:07 -05:00
end
end
end
end