Class: Security::CiConfiguration::BaseCreateService
- Inherits:
-
Object
- Object
- Security::CiConfiguration::BaseCreateService
- Defined in:
- app/services/security/ci_configuration/base_create_service.rb
Direct Known Subclasses
ContainerScanningCreateService, DependencyScanningCreateService, SastCreateService, SastIacCreateService, SecretDetectionCreateService
Instance Attribute Summary collapse
-
#branch_name ⇒ Object
readonly
Returns the value of attribute branch_name.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(project, current_user) ⇒ BaseCreateService
constructor
A new instance of BaseCreateService.
Constructor Details
#initialize(project, current_user) ⇒ BaseCreateService
Returns a new instance of BaseCreateService.
10 11 12 13 14 |
# File 'app/services/security/ci_configuration/base_create_service.rb', line 10 def initialize(project, current_user) @project = project @current_user = current_user @branch_name = project.repository.next_branch(next_branch) end |
Instance Attribute Details
#branch_name ⇒ Object (readonly)
Returns the value of attribute branch_name.
8 9 10 |
# File 'app/services/security/ci_configuration/base_create_service.rb', line 8 def branch_name @branch_name end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
8 9 10 |
# File 'app/services/security/ci_configuration/base_create_service.rb', line 8 def current_user @current_user end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'app/services/security/ci_configuration/base_create_service.rb', line 8 def name @name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
8 9 10 |
# File 'app/services/security/ci_configuration/base_create_service.rb', line 8 def project @project end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/services/security/ci_configuration/base_create_service.rb', line 16 def execute if project.repository.empty? && !(@params && @params[:initialize_with_sast]) docs_link = ActionController::Base.helpers.link_to _('add at least one file to the repository'), Rails.application.routes.url_helpers.help_page_url('user/project/repository/index.md', anchor: 'add-files-to-a-repository'), target: '_blank', rel: 'noopener noreferrer' return ServiceResponse.error( message: _(format('You must %s before using Security features.', docs_link)).html_safe ) end project.repository.add_branch(current_user, branch_name, project.default_branch) attributes_for_commit = attributes result = ::Files::MultiService.new(project, current_user, attributes_for_commit).execute return ServiceResponse.error(message: result[:message]) unless result[:status] == :success track_event(attributes_for_commit) ServiceResponse.success(payload: { branch: branch_name, success_path: successful_change_path }) rescue CiContentParseError => e Gitlab::ErrorTracking.track_exception(e) ServiceResponse.error(message: e.) rescue Gitlab::Git::PreReceiveError => e ServiceResponse.error(message: e.) rescue StandardError remove_branch_on_exception raise end |