Class: MergeRequests::UpdateService

Inherits:
BaseService show all
Extended by:
Gitlab::Utils::Override
Defined in:
app/services/merge_requests/update_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

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

Methods inherited from BaseService

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

Methods included from AssignsMergeParams

#assign_allowed_merge_params, included

Methods inherited from BaseService

#initialize

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?

Instance Method Details

#after_update(issuable) ⇒ Object


90
91
92
# File 'app/services/merge_requests/update_service.rb', line 90

def after_update(issuable)
  issuable.cache_merge_request_closes_issues!(current_user)
end

#close_serviceObject


86
87
88
# File 'app/services/merge_requests/update_service.rb', line 86

def close_service
  MergeRequests::CloseService
end

#execute(merge_request) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/merge_requests/update_service.rb', line 7

def execute(merge_request)
  # We don't allow change of source/target projects and source branch
  # after merge request was created
  params.delete(:source_project_id)
  params.delete(:target_project_id)
  params.delete(:source_branch)

  if merge_request.closed_without_fork?
    params.delete(:target_branch)
    params.delete(:force_remove_source_branch)
  end

  update_task_event(merge_request) || update(merge_request)
end

#handle_changes(merge_request, options) ⇒ Object


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/services/merge_requests/update_service.rb', line 22

def handle_changes(merge_request, options)
  old_associations = options.fetch(:old_associations, {})
  old_labels = old_associations.fetch(:labels, [])
  old_mentioned_users = old_associations.fetch(:mentioned_users, [])
  old_assignees = old_associations.fetch(:assignees, [])
  old_reviewers = old_associations.fetch(:reviewers, [])

  if has_changes?(merge_request, old_labels: old_labels, old_assignees: old_assignees, old_reviewers: old_reviewers)
    todo_service.resolve_todos_for_target(merge_request, current_user)
  end

  if merge_request.previous_changes.include?('title') ||
      merge_request.previous_changes.include?('description')
    todo_service.update_merge_request(merge_request, current_user, old_mentioned_users)
  end

  if merge_request.previous_changes.include?('target_branch')
    create_branch_change_note(merge_request, 'target',
                              merge_request.previous_changes['target_branch'].first,
                              merge_request.target_branch)

    abort_auto_merge(merge_request, 'target branch was changed')
  end

  handle_assignees_change(merge_request, old_assignees) if merge_request.assignees != old_assignees

  handle_reviewers_change(merge_request, old_reviewers) if merge_request.reviewers != old_reviewers

  if merge_request.previous_changes.include?('target_branch') ||
      merge_request.previous_changes.include?('source_branch')
    merge_request.mark_as_unchecked
  end

  handle_milestone_change(merge_request)

  added_labels = merge_request.labels - old_labels
  if added_labels.present?
    notification_service.async.relabeled_merge_request(
      merge_request,
      added_labels,
      current_user
    )
  end

  added_mentions = merge_request.mentioned_users(current_user) - old_mentioned_users

  if added_mentions.present?
    notification_service.async.new_mentions_in_merge_request(
      merge_request,
      added_mentions,
      current_user
    )
  end
end

#handle_task_changes(merge_request) ⇒ Object


77
78
79
80
# File 'app/services/merge_requests/update_service.rb', line 77

def handle_task_changes(merge_request)
  todo_service.resolve_todos_for_target(merge_request, current_user)
  todo_service.update_merge_request(merge_request, current_user)
end

#reopen_serviceObject


82
83
84
# File 'app/services/merge_requests/update_service.rb', line 82

def reopen_service
  MergeRequests::ReopenService
end