2014-04-02 18:51:17 +00:00
|
|
|
module MergeRequests
|
2014-10-07 14:09:28 +00:00
|
|
|
class BaseService < ::IssuableBaseService
|
2014-04-02 18:51:17 +00:00
|
|
|
def create_note(merge_request)
|
2015-05-09 22:18:50 +00:00
|
|
|
SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
|
2014-04-02 18:51:17 +00:00
|
|
|
end
|
|
|
|
|
2016-02-27 03:34:14 +00:00
|
|
|
def create_title_change_note(issuable, old_title)
|
2016-03-18 22:27:35 +00:00
|
|
|
removed_wip = old_title =~ MergeRequest::WIP_REGEX && !issuable.work_in_progress?
|
|
|
|
added_wip = old_title !~ MergeRequest::WIP_REGEX && issuable.work_in_progress?
|
2016-02-27 03:34:14 +00: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)
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-27 19:39:45 +00:00
|
|
|
def hook_data(merge_request, action, oldrev = nil)
|
2015-02-19 05:02:57 +00:00
|
|
|
hook_data = merge_request.to_hook_data(current_user)
|
2016-04-13 09:25:42 +00:00
|
|
|
hook_data[:object_attributes][:url] = Gitlab::UrlBuilder.build(merge_request)
|
2015-02-19 05:02:57 +00:00
|
|
|
hook_data[:object_attributes][:action] = action
|
2016-07-27 19:39:45 +00:00
|
|
|
if oldrev && !Gitlab::Git.blank_ref?(oldrev)
|
|
|
|
hook_data[:object_attributes][:oldrev] = oldrev
|
|
|
|
end
|
2015-02-19 05:02:57 +00:00
|
|
|
hook_data
|
|
|
|
end
|
|
|
|
|
2016-07-27 19:39:45 +00:00
|
|
|
def execute_hooks(merge_request, action = 'open', oldrev = nil)
|
2014-04-02 18:51:17 +00:00
|
|
|
if merge_request.project
|
2016-07-27 19:39:45 +00:00
|
|
|
merge_data = hook_data(merge_request, action, oldrev)
|
2015-02-19 05:02:57 +00:00
|
|
|
merge_request.project.execute_hooks(merge_data, :merge_request_hooks)
|
|
|
|
merge_request.project.execute_services(merge_data, :merge_request_hooks)
|
2014-04-02 18:51:17 +00:00
|
|
|
end
|
|
|
|
end
|
2015-07-24 19:46:40 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def filter_params
|
|
|
|
super(:merge_request)
|
|
|
|
end
|
2016-03-08 18:22:50 +00:00
|
|
|
|
|
|
|
def merge_request_from(commit_status)
|
|
|
|
branches = commit_status.ref
|
|
|
|
|
|
|
|
# This is for ref-less builds
|
|
|
|
branches ||= @project.repository.branch_names_contains(commit_status.sha)
|
|
|
|
|
|
|
|
return [] if branches.blank?
|
|
|
|
|
|
|
|
merge_requests = @project.origin_merge_requests.opened.where(source_branch: branches).to_a
|
|
|
|
merge_requests += @project.fork_merge_requests.opened.where(source_branch: branches).to_a
|
|
|
|
|
|
|
|
merge_requests.uniq.select(&:source_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_merge_request(commit_status)
|
|
|
|
merge_request_from(commit_status).each do |merge_request|
|
2016-06-02 14:19:18 +00:00
|
|
|
pipeline = merge_request.pipeline
|
2016-03-08 18:22:50 +00:00
|
|
|
|
2016-06-02 14:19:18 +00:00
|
|
|
next unless pipeline
|
|
|
|
next unless pipeline.sha == commit_status.sha
|
2016-03-08 18:22:50 +00:00
|
|
|
|
2016-06-02 14:19:18 +00:00
|
|
|
yield merge_request, pipeline
|
2016-03-08 18:22:50 +00:00
|
|
|
end
|
|
|
|
end
|
2014-04-02 18:51:17 +00:00
|
|
|
end
|
|
|
|
end
|