Class: MergeRequests::GetUrlsService

Inherits:
BaseService show all
Defined in:
app/services/merge_requests/get_urls_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params

Instance Method Summary collapse

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #create_note, #execute_hooks, #hook_data, #inspect, #source_project, #target_project

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from AssignsMergeParams

#assign_allowed_merge_params, included

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) ⇒ GetUrlsService

Returns a new instance of GetUrlsService.


7
8
9
# File 'app/services/merge_requests/get_urls_service.rb', line 7

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project


5
6
7
# File 'app/services/merge_requests/get_urls_service.rb', line 5

def project
  @project
end

Instance Method Details

#execute(changes) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/merge_requests/get_urls_service.rb', line 11

def execute(changes)
  return [] unless project&.printing_merge_request_link_enabled

  branches = get_branches(changes)
  merge_requests_map = opened_merge_requests_from_source_branches(branches)
  branches.map do |branch|
    existing_merge_request = merge_requests_map[branch]
    if existing_merge_request
      url_for_existing_merge_request(existing_merge_request)
    else
      url_for_new_merge_request(branch)
    end
  end
end