debian-mirror-gitlab/app/mailers/emails/merge_requests.rb

171 lines
7.6 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Emails
module MergeRequests
2018-03-17 18:26:18 +05:30
def new_merge_request_email(recipient_id, merge_request_id, reason = nil)
2018-11-08 19:23:39 +05:30
setup_merge_request_mail(merge_request_id, recipient_id, present: true)
2018-03-17 18:26:18 +05:30
mail_new_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, recipient_id, reason))
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
def new_mention_in_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
2018-11-08 19:23:39 +05:30
setup_merge_request_mail(merge_request_id, recipient_id, present: true)
2018-03-17 18:26:18 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
2016-09-13 17:45:13 +05:30
end
2018-05-09 12:01:36 +05:30
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
@updated_by_user = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
end
2021-04-17 20:07:23 +05:30
def change_in_merge_request_draft_status_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
@updated_by_user = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2019-07-31 22:56:46 +05:30
def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_ids, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
2019-07-31 22:56:46 +05:30
@previous_assignees = []
@previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any?
2018-03-17 18:26:18 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
2016-06-02 11:05:42 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-06-02 11:05:42 +05:30
2021-01-03 14:25:43 +05:30
# rubocop: disable CodeReuse/ActiveRecord
def changed_reviewer_of_merge_request_email(recipient_id, merge_request_id, previous_reviewer_ids, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
@previous_reviewers = []
@previous_reviewers = User.where(id: previous_reviewer_ids) if previous_reviewer_ids.any?
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
end
# rubocop: enable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def relabeled_merge_request_email(recipient_id, merge_request_id, label_names, updated_by_user_id, reason = nil)
2016-06-02 11:05:42 +05:30
setup_merge_request_mail(merge_request_id, recipient_id)
@label_names = label_names
2017-09-10 17:25:29 +05:30
@labels_url = project_labels_url(@project)
2018-03-17 18:26:18 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
2014-09-02 18:07:02 +05:30
end
2018-12-13 13:39:08 +05:30
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)
2019-02-15 15:39:39 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason).merge({
template_name: 'changed_milestone_email'
}))
2018-12-13 13:39:08 +05:30
end
2019-09-04 21:01:54 +05:30
def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason: nil, closed_via: nil)
setup_merge_request_mail(merge_request_id, recipient_id)
2016-06-02 11:05:42 +05:30
@updated_by = User.find(updated_by_user_id)
2018-03-17 18:26:18 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
2014-09-02 18:07:02 +05:30
end
2019-09-04 21:01:54 +05:30
def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason: nil, closed_via: nil)
setup_merge_request_mail(merge_request_id, recipient_id)
2018-03-17 18:26:18 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
2014-09-02 18:07:02 +05:30
end
2021-03-11 19:13:27 +05:30
def request_review_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
@updated_by = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
end
2014-09-02 18:07:02 +05:30
2018-03-17 18:26:18 +05:30
def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
2014-09-02 18:07:02 +05:30
@mr_status = status
2016-06-02 11:05:42 +05:30
@updated_by = User.find(updated_by_user_id)
2018-03-17 18:26:18 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
end
2018-11-08 19:23:39 +05:30
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))
end
2018-03-17 18:26:18 +05:30
def resolved_all_discussions_email(recipient_id, merge_request_id, resolved_by_user_id, reason = nil)
2016-09-13 17:45:13 +05:30
setup_merge_request_mail(merge_request_id, recipient_id)
@resolved_by = User.find(resolved_by_user_id)
2018-03-17 18:26:18 +05:30
mail_answer_thread(@merge_request, merge_request_thread_options(resolved_by_user_id, recipient_id, reason))
2016-09-13 17:45:13 +05:30
end
2020-07-28 23:09:34 +05:30
def merge_when_pipeline_succeeds_email(recipient_id, merge_request_id, mwps_set_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
@mwps_set_by = ::User.find(mwps_set_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(mwps_set_by_user_id, recipient_id, reason))
end
2021-01-03 14:25:43 +05:30
def merge_requests_csv_email(user, project, csv_data, export_status)
@project = project
@count = export_status.fetch(:rows_expected)
@written_count = export_status.fetch(:rows_written)
@truncated = export_status.fetch(:truncated)
2021-03-08 18:12:59 +05:30
@size_limit = ActiveSupport::NumberHelper
.number_to_human_size(Issuable::ExportCsv::BaseService::TARGET_FILESIZE)
2021-01-03 14:25:43 +05:30
filename = "#{project.full_path.parameterize}_merge_requests_#{Date.current.iso8601}.csv"
attachments[filename] = { content: csv_data, mime_type: 'text/csv' }
mail(to: user.notification_email_for(@project.group), subject: subject("Exported merge requests")) do |format|
format.html { render layout: 'mailer' }
format.text { render layout: 'mailer' }
end
end
private
2018-11-08 19:23:39 +05:30
def setup_merge_request_mail(merge_request_id, recipient_id, present: false)
@merge_request = MergeRequest.find(merge_request_id)
@project = @merge_request.project
2017-09-10 17:25:29 +05:30
@target_url = project_merge_request_url(@project, @merge_request)
2014-09-02 18:07:02 +05:30
2018-11-08 19:23:39 +05:30
if present
recipient = User.find(recipient_id)
@mr_presenter = @merge_request.present(current_user: recipient)
end
@sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
def merge_request_thread_options(sender_id, recipient_id, reason = nil)
2016-06-02 11:05:42 +05:30
{
from: sender(sender_id),
2019-12-21 20:55:43 +05:30
to: User.find(recipient_id).notification_email_for(@project.group),
2018-03-17 18:26:18 +05:30
subject: subject("#{@merge_request.title} (#{@merge_request.to_reference})"),
'X-GitLab-NotificationReason' => reason
2016-06-02 11:05:42 +05:30
}
end
2014-09-02 18:07:02 +05:30
end
end
2019-12-04 20:38:33 +05:30
Emails::MergeRequests.prepend_if_ee('EE::Emails::MergeRequests')