BigW Consortium Gitlab

merge_requests.rb 3.83 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 9 10
      set_message_id("merge_request_#{merge_request_id}")
      mail(from: sender(@merge_request.author_id),
           to: recipient(recipient_id),
           subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
11 12
    end

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

    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
27
      @project = @merge_request.project
28
      @target_url = project_merge_request_url(@project, @merge_request)
29 30 31 32
      set_reference("merge_request_#{merge_request_id}")
      mail(from: sender(updated_by_user_id),
           to: recipient(recipient_id),
           subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
33 34
    end

35
    def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
36
      @merge_request = MergeRequest.find(merge_request_id)
37
      @project = @merge_request.project
38
      @target_url = project_merge_request_url(@project, @merge_request)
39 40 41 42
      set_reference("merge_request_#{merge_request_id}")
      mail(from: sender(updated_by_user_id),
           to: recipient(recipient_id),
           subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
43
    end
44
  end
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 72 73 74 75

  # 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)
76
    subject = "Merge Request | "
77 78 79 80 81 82 83 84
    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
85

86
end