2014-04-02 14:51:17 -04:00
|
|
|
module MergeRequests
|
2014-10-07 10:09:28 -04:00
|
|
|
class BaseService < ::IssuableBaseService
|
2014-04-03 11:16:05 -04:00
|
|
|
|
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-03-18 18:27:35 -04: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-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)
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-19 00:02:57 -05:00
|
|
|
def hook_data(merge_request, action)
|
|
|
|
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
|
|
|
|
hook_data
|
|
|
|
end
|
|
|
|
|
2015-01-17 19:34:34 -05:00
|
|
|
def execute_hooks(merge_request, action = 'open')
|
2014-04-02 14:51:17 -04:00
|
|
|
if merge_request.project
|
2015-02-19 00:02:57 -05:00
|
|
|
merge_data = hook_data(merge_request, action)
|
|
|
|
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
|
|
|
|
|
|
|
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 10:19:18 -04:00
|
|
|
pipeline = merge_request.pipeline
|
2016-03-08 13:22:50 -05:00
|
|
|
|
2016-06-02 10:19:18 -04:00
|
|
|
next unless pipeline
|
|
|
|
next unless pipeline.sha == commit_status.sha
|
2016-03-08 13:22:50 -05:00
|
|
|
|
2016-06-02 10:19:18 -04:00
|
|
|
yield merge_request, pipeline
|
2016-03-08 13:22:50 -05:00
|
|
|
end
|
|
|
|
end
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
end
|