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

76 lines
2.4 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module MergeRequests
2015-04-26 12:48:37 +05:30
class BaseService < ::IssuableBaseService
2014-09-02 18:07:02 +05:30
def create_note(merge_request)
2015-09-11 14:41:01 +05:30
SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
def create_title_change_note(issuable, old_title)
2016-11-03 12:29:30 +05:30
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-06-02 11:05:42 +05:30
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-11-03 12:29:30 +05:30
super if changed_title
2016-06-02 11:05:42 +05:30
end
2016-09-13 17:45:13 +05:30
def hook_data(merge_request, action, oldrev = nil)
2015-04-26 12:48:37 +05:30
hook_data = merge_request.to_hook_data(current_user)
2016-06-02 11:05:42 +05:30
hook_data[:object_attributes][:url] = Gitlab::UrlBuilder.build(merge_request)
2015-04-26 12:48:37 +05:30
hook_data[:object_attributes][:action] = action
2016-09-13 17:45:13 +05:30
if oldrev && !Gitlab::Git.blank_ref?(oldrev)
hook_data[:object_attributes][:oldrev] = oldrev
end
2015-04-26 12:48:37 +05:30
hook_data
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
def execute_hooks(merge_request, action = 'open', oldrev = nil)
2015-04-26 12:48:37 +05:30
if merge_request.project
2016-09-13 17:45:13 +05:30
merge_data = hook_data(merge_request, action, oldrev)
2015-04-26 12:48:37 +05:30
merge_request.project.execute_hooks(merge_data, :merge_request_hooks)
merge_request.project.execute_services(merge_data, :merge_request_hooks)
end
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
private
def filter_params
super(:merge_request)
end
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
def merge_requests_for(branch)
origin_merge_requests = @project.origin_merge_requests
.opened.where(source_branch: branch).to_a
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
fork_merge_requests = @project.fork_merge_requests
.opened.where(source_branch: branch).to_a
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
(origin_merge_requests + fork_merge_requests)
.uniq.select(&:source_project)
end
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
def pipeline_merge_requests(pipeline)
merge_requests_for(pipeline.ref).each do |merge_request|
next unless pipeline == merge_request.pipeline
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
yield merge_request
end
2016-06-02 11:05:42 +05:30
end
2016-11-03 12:29:30 +05:30
def commit_status_merge_requests(commit_status)
merge_requests_for(commit_status.ref).each do |merge_request|
pipeline = merge_request.pipeline
2016-06-02 11:05:42 +05:30
next unless pipeline
next unless pipeline.sha == commit_status.sha
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
yield merge_request
2016-06-02 11:05:42 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
end