2014-04-02 18:51:17 +00:00
|
|
|
module MergeRequests
|
|
|
|
class UpdateService < MergeRequests::BaseService
|
|
|
|
def execute(merge_request)
|
2015-05-29 16:40:35 +00:00
|
|
|
# We don't allow change of source/target projects and source branch
|
2014-04-02 18:51:17 +00:00
|
|
|
# after merge request was created
|
2014-06-26 20:24:17 +00:00
|
|
|
params.except!(:source_project_id)
|
|
|
|
params.except!(:target_project_id)
|
2015-05-29 16:40:35 +00:00
|
|
|
params.except!(:source_branch)
|
2014-04-02 18:51:17 +00:00
|
|
|
|
2016-07-26 11:57:43 +00:00
|
|
|
if merge_request.closed_without_fork?
|
|
|
|
params.except!(:target_branch, :force_remove_source_branch)
|
|
|
|
end
|
|
|
|
|
2016-10-11 15:52:49 +00:00
|
|
|
if params[:force_remove_source_branch].present?
|
|
|
|
merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch)
|
|
|
|
end
|
|
|
|
|
2016-09-08 09:18:41 +00:00
|
|
|
handle_wip_event(merge_request)
|
2015-11-17 11:42:43 +00:00
|
|
|
update(merge_request)
|
2015-11-12 23:06:42 +00:00
|
|
|
end
|
2014-06-10 09:33:17 +00:00
|
|
|
|
2016-08-15 11:05:08 +00:00
|
|
|
def handle_changes(merge_request, old_labels: [], old_mentioned_users: [])
|
2016-03-01 16:33:13 +00:00
|
|
|
if has_changes?(merge_request, old_labels: old_labels)
|
2016-02-20 13:59:59 +00:00
|
|
|
todo_service.mark_pending_todos_as_done(merge_request, current_user)
|
2016-02-18 21:12:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if merge_request.previous_changes.include?('title') ||
|
|
|
|
merge_request.previous_changes.include?('description')
|
2016-02-20 13:59:59 +00:00
|
|
|
todo_service.update_merge_request(merge_request, current_user)
|
2016-02-16 23:18:38 +00:00
|
|
|
end
|
|
|
|
|
2015-11-12 23:06:42 +00:00
|
|
|
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)
|
|
|
|
end
|
2014-04-02 18:51:17 +00:00
|
|
|
|
2015-11-12 23:06:42 +00:00
|
|
|
if merge_request.previous_changes.include?('milestone_id')
|
|
|
|
create_milestone_note(merge_request)
|
|
|
|
end
|
2015-05-27 01:49:04 +00:00
|
|
|
|
2015-11-12 23:06:42 +00:00
|
|
|
if merge_request.previous_changes.include?('assignee_id')
|
|
|
|
create_assignee_note(merge_request)
|
|
|
|
notification_service.reassigned_merge_request(merge_request, current_user)
|
2016-02-20 13:59:59 +00:00
|
|
|
todo_service.reassigned_merge_request(merge_request, current_user)
|
2015-11-12 23:06:42 +00:00
|
|
|
end
|
2015-05-29 01:00:37 +00:00
|
|
|
|
2015-11-12 23:06:42 +00:00
|
|
|
if merge_request.previous_changes.include?('target_branch') ||
|
|
|
|
merge_request.previous_changes.include?('source_branch')
|
|
|
|
merge_request.mark_as_unchecked
|
|
|
|
end
|
2016-02-12 14:58:39 +00:00
|
|
|
|
2016-03-01 16:33:13 +00:00
|
|
|
added_labels = merge_request.labels - old_labels
|
|
|
|
if added_labels.present?
|
|
|
|
notification_service.relabeled_merge_request(
|
|
|
|
merge_request,
|
|
|
|
added_labels,
|
|
|
|
current_user
|
|
|
|
)
|
2016-02-12 14:58:39 +00:00
|
|
|
end
|
2016-08-15 11:05:08 +00:00
|
|
|
|
2016-08-15 13:47:16 +00:00
|
|
|
added_mentions = merge_request.mentioned_users - old_mentioned_users
|
|
|
|
if added_mentions.present?
|
|
|
|
notification_service.new_mentions_in_merge_request(
|
|
|
|
merge_request,
|
|
|
|
added_mentions,
|
|
|
|
current_user
|
|
|
|
)
|
|
|
|
end
|
2014-04-02 18:51:17 +00:00
|
|
|
end
|
2015-11-17 11:42:43 +00:00
|
|
|
|
|
|
|
def reopen_service
|
|
|
|
MergeRequests::ReopenService
|
|
|
|
end
|
|
|
|
|
|
|
|
def close_service
|
|
|
|
MergeRequests::CloseService
|
|
|
|
end
|
2016-09-20 19:52:20 +00:00
|
|
|
|
|
|
|
def after_update(issuable)
|
|
|
|
issuable.cache_merge_request_closes_issues!(current_user)
|
|
|
|
end
|
2016-09-08 09:18:41 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def handle_wip_event(merge_request)
|
|
|
|
if wip_event = params.delete(:wip_event)
|
|
|
|
# We update the title that is provided in the params or we use the mr title
|
|
|
|
title = params[:title] || merge_request.title
|
|
|
|
params[:title] = case wip_event
|
|
|
|
when 'wip' then MergeRequest.wip_title(title)
|
|
|
|
when 'unwip' then MergeRequest.wipless_title(title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-02 18:51:17 +00:00
|
|
|
end
|
|
|
|
end
|