Class: Packages::Go::CreatePackageService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/packages/go/create_package_service.rb

Constant Summary collapse

GoZipSizeError =
Class.new(StandardError)

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(project, user = nil, version:) ⇒ CreatePackageService

Returns a new instance of CreatePackageService.


10
11
12
13
14
# File 'app/services/packages/go/create_package_service.rb', line 10

def initialize(project, user = nil, version:)
  super(project, user)

  @version = version
end

Instance Attribute Details

#versionObject

Returns the value of attribute version.


8
9
10
# File 'app/services/packages/go/create_package_service.rb', line 8

def version
  @version
end

Instance Method Details

#executeObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/packages/go/create_package_service.rb', line 16

def execute
  # check for existing package to avoid SQL errors due to the index
  package = ::Packages::Go::PackageFinder.new(version.mod.project, version.mod.name, version.name).execute
  return package if package

  # this can be expensive, so do it outside the transaction
  files = {}
  files[:mod] = prepare_file(version, :mod, version.gomod)
  files[:zip] = prepare_file(version, :zip, version.archive.string)

  ApplicationRecord.transaction do
    # create new package and files
    package = create_package
    files.each { |type, (file, digests)| create_file(package, type, file, digests) }
    package
  end
end