2018-08-15 17:45:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-19 14:00:41 -04:00
|
|
|
module Emails
|
|
|
|
module MergeRequests
|
2017-12-28 12:25:02 -05:00
|
|
|
def new_merge_request_email(recipient_id, merge_request_id, reason = nil)
|
2018-09-14 11:59:28 -04:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id, present: true)
|
2015-12-09 05:59:25 -05:00
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_new_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, recipient_id, reason))
|
2013-03-19 14:00:41 -04:00
|
|
|
end
|
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
def new_mention_in_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
|
2018-09-14 11:59:28 -04:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id, present: true)
|
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
2016-08-15 09:47:16 -04:00
|
|
|
end
|
|
|
|
|
2017-07-25 07:56:09 -04:00
|
|
|
def push_to_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil, new_commits: [], existing_commits: [])
|
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
@new_commits = new_commits
|
|
|
|
@existing_commits = existing_commits
|
2018-04-03 07:51:09 -04:00
|
|
|
@updated_by_user = User.find(updated_by_user_id)
|
2017-07-25 07:56:09 -04:00
|
|
|
|
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2019-04-07 14:35:16 -04:00
|
|
|
def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_ids, updated_by_user_id, reason = nil)
|
2015-12-09 05:59:25 -05:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
@previous_assignees = []
|
|
|
|
@previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any?
|
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
2013-03-19 14:00:41 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2013-03-28 06:14:53 -04:00
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
def relabeled_merge_request_email(recipient_id, merge_request_id, label_names, updated_by_user_id, reason = nil)
|
2016-03-15 12:24:55 -04:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
2016-03-01 11:33:13 -05:00
|
|
|
|
2016-02-12 09:58:39 -05:00
|
|
|
@label_names = label_names
|
2017-06-29 13:06:35 -04:00
|
|
|
@labels_url = project_labels_url(@project)
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|
|
|
|
|
2018-11-02 12:29:32 -04:00
|
|
|
def removed_milestone_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
|
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
|
|
|
end
|
|
|
|
|
|
|
|
def changed_milestone_merge_request_email(recipient_id, merge_request_id, milestone, updated_by_user_id, reason = nil)
|
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
|
|
|
@milestone = milestone
|
|
|
|
@milestone_url = milestone_url(@milestone)
|
2018-12-12 04:51:36 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason).merge({
|
|
|
|
template_name: 'changed_milestone_email'
|
|
|
|
}))
|
2018-11-02 12:29:32 -04:00
|
|
|
end
|
|
|
|
|
2019-05-16 07:59:02 -04:00
|
|
|
def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason: nil, closed_via: nil)
|
2015-12-09 05:59:25 -05:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
2016-02-12 09:58:39 -05:00
|
|
|
@updated_by = User.find(updated_by_user_id)
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
2013-03-28 06:14:53 -04:00
|
|
|
end
|
|
|
|
|
2019-05-16 07:59:02 -04:00
|
|
|
def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason: nil, closed_via: nil)
|
2015-12-09 05:59:25 -05:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
2013-03-28 06:14:53 -04:00
|
|
|
end
|
2014-07-03 07:40:21 -04:00
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id, reason = nil)
|
2015-12-09 05:59:25 -05:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
2014-07-03 07:40:21 -04:00
|
|
|
@mr_status = status
|
2016-02-12 09:58:39 -05:00
|
|
|
@updated_by = User.find(updated_by_user_id)
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
|
2018-05-09 05:49:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_unmergeable_email(recipient_id, merge_request_id, reason = nil)
|
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, recipient_id, reason))
|
2015-12-09 05:59:25 -05:00
|
|
|
end
|
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
def resolved_all_discussions_email(recipient_id, merge_request_id, resolved_by_user_id, reason = nil)
|
2016-07-28 23:00:32 -04:00
|
|
|
setup_merge_request_mail(merge_request_id, recipient_id)
|
|
|
|
|
|
|
|
@resolved_by = User.find(resolved_by_user_id)
|
2017-12-28 12:25:02 -05:00
|
|
|
mail_answer_thread(@merge_request, merge_request_thread_options(resolved_by_user_id, recipient_id, reason))
|
2016-07-28 23:00:32 -04:00
|
|
|
end
|
|
|
|
|
2015-12-09 05:59:25 -05:00
|
|
|
private
|
|
|
|
|
2018-09-14 11:59:28 -04:00
|
|
|
def setup_merge_request_mail(merge_request_id, recipient_id, present: false)
|
2015-12-09 05:59:25 -05:00
|
|
|
@merge_request = MergeRequest.find(merge_request_id)
|
|
|
|
@project = @merge_request.project
|
2017-06-29 13:06:35 -04:00
|
|
|
@target_url = project_merge_request_url(@project, @merge_request)
|
2016-03-01 11:33:13 -05:00
|
|
|
|
2018-09-14 11:59:28 -04:00
|
|
|
if present
|
|
|
|
recipient = User.find(recipient_id)
|
|
|
|
@mr_presenter = @merge_request.present(current_user: recipient)
|
|
|
|
end
|
|
|
|
|
2016-03-15 12:24:55 -04:00
|
|
|
@sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key)
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
2015-08-18 18:46:36 -04:00
|
|
|
|
2017-12-28 12:25:02 -05:00
|
|
|
def merge_request_thread_options(sender_id, recipient_id, reason = nil)
|
2016-03-01 11:33:13 -05:00
|
|
|
{
|
|
|
|
from: sender(sender_id),
|
2019-02-15 12:56:13 -05:00
|
|
|
to: recipient(recipient_id, @project.group),
|
2017-12-28 12:25:02 -05:00
|
|
|
subject: subject("#{@merge_request.title} (#{@merge_request.to_reference})"),
|
|
|
|
'X-GitLab-NotificationReason' => reason
|
2016-03-01 11:33:13 -05:00
|
|
|
}
|
2014-07-03 07:40:21 -04:00
|
|
|
end
|
2013-03-19 14:00:41 -04:00
|
|
|
end
|
|
|
|
end
|