merge_requests.rb 3.61 KB
Newer Older
1 2
module Emails
  module MergeRequests
3
    def new_merge_request_email(recipient_id, merge_request_id)
4
      @merge_request = MergeRequest.find(merge_request_id)
5
      @project = @merge_request.project
6
      @target_url = project_merge_request_url(@project, @merge_request)
7 8
      mail(from: sender(@merge_request.author_id),
           to: recipient(recipient_id),
9
           subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
10 11
    end

12
    def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id)
13
      @merge_request = MergeRequest.find(merge_request_id)
skv's avatar
skv committed
14
      @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
15
      @project = @merge_request.project
16
      @target_url = project_merge_request_url(@project, @merge_request)
17 18
      mail(from: sender(updated_by_user_id),
           to: recipient(recipient_id),
19
           subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
20
    end
21 22 23 24

    def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
      @merge_request = MergeRequest.find(merge_request_id)
      @updated_by = User.find updated_by_user_id
25
      @project = @merge_request.project
26
      @target_url = project_merge_request_url(@project, @merge_request)
27 28
      mail(from: sender(updated_by_user_id),
           to: recipient(recipient_id),
29
           subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
30 31
    end

32
    def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
33
      @merge_request = MergeRequest.find(merge_request_id)
34
      @project = @merge_request.project
35
      @target_url = project_merge_request_url(@project, @merge_request)
36
      mail(from: sender(updated_by_user_id),
37
           to: recipient(recipient_id),
38
           subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
39
    end
40
  end
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

  # Over rides default behavour to show source/target
  # Formats arguments into a String suitable for use as an email subject
  #
  # extra - Extra Strings to be inserted into the subject
  #
  # Examples
  #
  #   >> subject('Lorem ipsum')
  #   => "GitLab Merge Request | Lorem ipsum"
  #
  #   # Automatically inserts Project name:
  #   Forked MR
  #   => source project => <Project id: 1, name: "Ruby on Rails", path: "ruby_on_rails", ...>
  #   => target project => <Project id: 2, name: "My Ror", path: "ruby_on_rails", ...>
  #   => source branch => source
  #   => target branch => target
  #   >> subject('Lorem ipsum')
  #   => "GitLab Merge Request | Ruby on Rails:source >> My Ror:target | Lorem ipsum "
  #
  #   Non Forked MR
  #   => source project => <Project id: 1, name: "Ruby on Rails", path: "ruby_on_rails", ...>
  #   => target project => <Project id: 1, name: "Ruby on Rails", path: "ruby_on_rails", ...>
  #   => source branch => source
  #   => target branch => target
  #   >> subject('Lorem ipsum')
  #   => "GitLab Merge Request | Ruby on Rails | source >> target | Lorem ipsum "
  #   # Accepts multiple arguments
  #   >> subject('Lorem ipsum', 'Dolor sit amet')
  #   => "GitLab Merge Request | Lorem ipsum | Dolor sit amet"
  def subject(*extra)
72
    subject = "Merge Request | "
73 74 75 76 77 78 79 80
    if @merge_request.for_fork?
      subject << "#{@merge_request.source_project.name_with_namespace}:#{merge_request.source_branch} >> #{@merge_request.target_project.name_with_namespace}:#{merge_request.target_branch}"
    else
      subject << "#{@merge_request.source_project.name_with_namespace} | #{merge_request.source_branch} >> #{merge_request.target_branch}"
    end
    subject << " | " + extra.join(' | ') if extra.present?
    subject
  end
81

82
end