summaryrefslogtreecommitdiff
path: root/app/mailers/emails/projects.rb
blob: 4bc40b35f2d0bff3e2ae3ffeab2b984ccc30bda3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Emails
  module Projects
    def project_access_granted_email(user_project_id)
      @project_member = ProjectMember.find user_project_id
      @project = @project_member.project
      @target_url = namespace_project_url(@project.namespace, @project)
      mail(to: @project_member.user.email,
           subject: subject("Access to project was granted"))
    end

    def project_was_moved_email(project_id, user_id)
      @user = User.find user_id
      @project = Project.find project_id
      @target_url = namespace_project_url(@project.namespace, @project)
      mail(to: @user.notification_email,
           subject: subject("Project was moved"))
    end

    def repository_push_email(project_id, recipient, author_id, branch, compare)
      @project = Project.find(project_id)
      @author  = User.find(author_id)
      @compare = compare
      @commits = Commit.decorate(compare.commits)
      @diffs   = compare.diffs
      @branch  = branch
      if @commits.length > 1
        @target_url = namespace_project_compare_url(@project.namespace,
                                                    @project,
                                                    from: @commits.first,
                                                    to: @commits.last)
        @subject = "#{@commits.length} new commits pushed to repository"
      else
        @target_url = namespace_project_commit_url(@project.namespace,
                                                   @project, @commits.first)
        @subject = @commits.first.title
      end

      mail(from: sender(author_id),
           to: recipient,
           subject: subject(@subject))
    end
  end
end