debian-mirror-gitlab/app/services/merge_requests/update_service.rb

73 lines
2.4 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require_relative 'base_service'
require_relative 'reopen_service'
require_relative 'close_service'
module MergeRequests
class UpdateService < MergeRequests::BaseService
def execute(merge_request)
2015-09-11 14:41:01 +05:30
# We don't allow change of source/target projects and source branch
2014-09-02 18:07:02 +05:30
# after merge request was created
params.except!(:source_project_id)
params.except!(:target_project_id)
2015-09-11 14:41:01 +05:30
params.except!(:source_branch)
2014-09-02 18:07:02 +05:30
2015-09-11 14:41:01 +05:30
case params.delete(:state_event)
2014-09-02 18:07:02 +05:30
when 'reopen'
MergeRequests::ReopenService.new(project, current_user, {}).execute(merge_request)
when 'close'
MergeRequests::CloseService.new(project, current_user, {}).execute(merge_request)
end
2015-04-26 12:48:37 +05:30
params[:assignee_id] = "" if params[:assignee_id] == IssuableFinder::NONE
params[:milestone_id] = "" if params[:milestone_id] == IssuableFinder::NONE
2015-09-11 14:41:01 +05:30
filter_params
2015-04-26 12:48:37 +05:30
old_labels = merge_request.labels.to_a
2015-09-11 14:41:01 +05:30
if params.present? && merge_request.update_attributes(params.merge(updated_by: current_user))
2014-09-02 18:07:02 +05:30
merge_request.reset_events_cache
2015-04-26 12:48:37 +05:30
if merge_request.labels != old_labels
create_labels_note(
merge_request,
merge_request.labels - old_labels,
old_labels - merge_request.labels
)
end
2015-11-26 14:37:03 +05:30
handle_changes(merge_request)
merge_request.create_new_cross_references!(current_user)
execute_hooks(merge_request, 'update')
end
2015-09-11 14:41:01 +05:30
2015-11-26 14:37:03 +05:30
merge_request
end
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
def handle_changes(merge_request)
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-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
if merge_request.previous_changes.include?('milestone_id')
create_milestone_note(merge_request)
end
2015-09-11 14:41:01 +05:30
2015-11-26 14:37:03 +05:30
if merge_request.previous_changes.include?('assignee_id')
create_assignee_note(merge_request)
notification_service.reassigned_merge_request(merge_request, current_user)
end
2015-09-11 14:41:01 +05:30
2015-11-26 14:37:03 +05:30
if merge_request.previous_changes.include?('title')
create_title_change_note(merge_request, merge_request.previous_changes['title'].first)
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
if merge_request.previous_changes.include?('target_branch') ||
merge_request.previous_changes.include?('source_branch')
merge_request.mark_as_unchecked
end
2014-09-02 18:07:02 +05:30
end
end
end