Class: Files::BaseService

Inherits:
BaseService show all
Defined in:
app/services/files/base_service.rb

Defined Under Namespace

Classes: ValidationError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #initialize, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#executeObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/files/base_service.rb', line 5

def execute
  @source_project = params[:source_project] || @project
  @source_branch = params[:source_branch]
  @target_branch  = params[:target_branch]

  @commit_message = params[:commit_message]
  @file_path      = params[:file_path]
  @file_content   = if params[:file_content_encoding] == 'base64'
                      Base64.decode64(params[:file_content])
                    else
                      params[:file_content]
                    end

  # Validate parameters
  validate

  # Create new branch if it different from source_branch
  if different_branch?
    create_target_branch
  end

  if commit
    success
  else
    error("Something went wrong. Your changes were not committed")
  end
rescue Repository::CommitError, Gitlab::Git::Repository::InvalidBlobName, GitHooksService::PreReceiveError, ValidationError => ex
  error(ex.message)
end