Class: Releases::BaseService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility, Gitlab::Utils::StrongMemoize
Defined in:
app/services/releases/base_service.rb

Direct Known Subclasses

CreateService, DestroyService, UpdateService

Constant Summary collapse

ReleaseProtectedTagAccessError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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, params = {}) ⇒ BaseService

Returns a new instance of BaseService.


12
13
14
15
16
# File 'app/services/releases/base_service.rb', line 12

def initialize(project, user = nil, params = {})
  @project = project
  @current_user = user
  @params = params.dup
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.


10
11
12
# File 'app/services/releases/base_service.rb', line 10

def current_user
  @current_user
end

#paramsObject

Returns the value of attribute params.


10
11
12
# File 'app/services/releases/base_service.rb', line 10

def params
  @params
end

#projectObject

Returns the value of attribute project.


10
11
12
# File 'app/services/releases/base_service.rb', line 10

def project
  @project
end

Instance Method Details

#descriptionObject


30
31
32
# File 'app/services/releases/base_service.rb', line 30

def description
  params[:description]
end

#execute_hooks(release, action = 'create') ⇒ Object


82
83
84
# File 'app/services/releases/base_service.rb', line 82

def execute_hooks(release, action = 'create')
  release.execute_hooks(action)
end

#existing_tagObject


50
51
52
53
54
# File 'app/services/releases/base_service.rb', line 50

def existing_tag
  strong_memoize(:existing_tag) do
    repository.find_tag(tag_name)
  end
end

#inexistent_milestonesObject


71
72
73
74
75
76
# File 'app/services/releases/base_service.rb', line 71

def inexistent_milestones
  return [] unless param_for_milestone_titles_provided?

  existing_milestone_titles = milestones.map(&:title)
  Array(params[:milestones]) - existing_milestone_titles
end

#milestonesObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/services/releases/base_service.rb', line 56

def milestones
  return [] unless param_for_milestone_titles_provided?

  strong_memoize(:milestones) do
    MilestonesFinder.new(
      project: project,
      current_user: current_user,
      project_ids: Array(project.id),
      group_ids: Array(project_group_id),
      state: 'all',
      title: params[:milestones]
    ).execute
  end
end

#nameObject


26
27
28
# File 'app/services/releases/base_service.rb', line 26

def name
  params[:name] || tag_name
end

#param_for_milestone_titles_provided?Boolean

Returns:

  • (Boolean)

78
79
80
# File 'app/services/releases/base_service.rb', line 78

def param_for_milestone_titles_provided?
  !!params[:milestones]
end

#project_group_idObject

overridden in EE


87
# File 'app/services/releases/base_service.rb', line 87

def project_group_id; end

#refObject


22
23
24
# File 'app/services/releases/base_service.rb', line 22

def ref
  params[:ref]
end

#releaseObject


38
39
40
41
42
# File 'app/services/releases/base_service.rb', line 38

def release
  strong_memoize(:release) do
    project.releases.find_by_tag(tag_name)
  end
end

#released_atObject


34
35
36
# File 'app/services/releases/base_service.rb', line 34

def released_at
  params[:released_at]
end

#repositoryObject


44
45
46
47
48
# File 'app/services/releases/base_service.rb', line 44

def repository
  strong_memoize(:repository) do
    project.repository
  end
end

#tag_nameObject


18
19
20
# File 'app/services/releases/base_service.rb', line 18

def tag_name
  params[:tag]
end