2014-04-02 14:51:17 -04:00
|
|
|
module MergeRequests
|
2014-10-07 10:09:28 -04:00
|
|
|
class BaseService < ::IssuableBaseService
|
2014-04-02 14:51:17 -04:00
|
|
|
def create_note(merge_request)
|
2015-05-09 18:18:50 -04:00
|
|
|
SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
|
2016-02-26 22:34:14 -05:00
|
|
|
def create_title_change_note(issuable, old_title)
|
2016-09-08 05:18:41 -04:00
|
|
|
removed_wip = MergeRequest.work_in_progress?(old_title) && !issuable.work_in_progress?
|
|
|
|
added_wip = !MergeRequest.work_in_progress?(old_title) && issuable.work_in_progress?
|
|
|
|
changed_title = MergeRequest.wipless_title(old_title) != issuable.wipless_title
|
2016-02-26 22:34:14 -05:00
|
|
|
|
|
|
|
if removed_wip
|
|
|
|
SystemNoteService.remove_merge_request_wip(issuable, issuable.project, current_user)
|
|
|
|
elsif added_wip
|
|
|
|
SystemNoteService.add_merge_request_wip(issuable, issuable.project, current_user)
|
|
|
|
end
|
2016-09-08 05:18:41 -04:00
|
|
|
|
|
|
|
super if changed_title
|
2016-02-26 22:34:14 -05:00
|
|
|
end
|
|
|
|
|
2016-07-27 15:39:45 -04:00
|
|
|
def hook_data(merge_request, action, oldrev = nil)
|
2015-02-19 00:02:57 -05:00
|
|
|
hook_data = merge_request.to_hook_data(current_user)
|
2016-04-13 05:25:42 -04:00
|
|
|
hook_data[:object_attributes][:url] = Gitlab::UrlBuilder.build(merge_request)
|
2015-02-19 00:02:57 -05:00
|
|
|
hook_data[:object_attributes][:action] = action
|
2016-07-27 15:39:45 -04:00
|
|
|
if oldrev && !Gitlab::Git.blank_ref?(oldrev)
|
|
|
|
hook_data[:object_attributes][:oldrev] = oldrev
|
|
|
|
end
|
2015-02-19 00:02:57 -05:00
|
|
|
hook_data
|
|
|
|
end
|
|
|
|
|
2016-07-27 15:39:45 -04:00
|
|
|
def execute_hooks(merge_request, action = 'open', oldrev = nil)
|
2014-04-02 14:51:17 -04:00
|
|
|
if merge_request.project
|
2016-07-27 15:39:45 -04:00
|
|
|
merge_data = hook_data(merge_request, action, oldrev)
|
2015-02-19 00:02:57 -05:00
|
|
|
merge_request.project.execute_hooks(merge_data, :merge_request_hooks)
|
|
|
|
merge_request.project.execute_services(merge_data, :merge_request_hooks)
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
end
|
2015-07-24 15:46:40 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def filter_params
|
|
|
|
super(:merge_request)
|
|
|
|
end
|
2016-03-08 13:22:50 -05:00
|
|
|
|
2016-10-06 06:31:39 -04:00
|
|
|
def merge_requests_for(branch)
|
|
|
|
origin_merge_requests = @project.origin_merge_requests
|
|
|
|
.opened.where(source_branch: branch).to_a
|
2016-03-08 13:22:50 -05:00
|
|
|
|
2016-10-06 06:31:39 -04:00
|
|
|
fork_merge_requests = @project.fork_merge_requests
|
|
|
|
.opened.where(source_branch: branch).to_a
|
2016-03-08 13:22:50 -05:00
|
|
|
|
2016-10-06 06:31:39 -04:00
|
|
|
(origin_merge_requests + fork_merge_requests)
|
|
|
|
.uniq.select(&:source_project)
|
2016-03-08 13:22:50 -05:00
|
|
|
end
|
|
|
|
|
2016-10-04 09:59:11 -04:00
|
|
|
def pipeline_merge_requests(pipeline)
|
2016-10-06 06:31:39 -04:00
|
|
|
merge_requests_for(pipeline.ref).each do |merge_request|
|
2016-11-28 05:13:32 -05:00
|
|
|
next unless pipeline == merge_request.head_pipeline
|
2016-10-06 06:19:50 -04:00
|
|
|
|
2016-10-04 09:59:11 -04:00
|
|
|
yield merge_request
|
|
|
|
end
|
|
|
|
end
|
2016-03-08 13:22:50 -05:00
|
|
|
|
2016-10-04 09:59:11 -04:00
|
|
|
def commit_status_merge_requests(commit_status)
|
2016-10-06 06:31:39 -04:00
|
|
|
merge_requests_for(commit_status.ref).each do |merge_request|
|
2016-11-28 05:13:32 -05:00
|
|
|
pipeline = merge_request.head_pipeline
|
2016-10-06 06:31:39 -04:00
|
|
|
|
2016-10-06 06:19:50 -04:00
|
|
|
next unless pipeline
|
|
|
|
next unless pipeline.sha == commit_status.sha
|
|
|
|
|
2016-10-04 09:59:11 -04:00
|
|
|
yield merge_request
|
2016-03-08 13:22:50 -05:00
|
|
|
end
|
|
|
|
end
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
end
|