projects.rb 1.63 KB
Newer Older
1 2
module Emails
  module Projects
3 4 5
    def project_access_granted_email(user_project_id)
      @project_member = ProjectMember.find user_project_id
      @project = @project_member.project
Vinnie Okada's avatar
Vinnie Okada committed
6
      @target_url = namespace_project_url(@project.namespace, @project)
7
      mail(to: @project_member.user.email,
8
           subject: subject("Access to project was granted"))
9 10
    end

11 12 13
    def project_was_moved_email(project_id, user_id)
      @user = User.find user_id
      @project = Project.find project_id
Vinnie Okada's avatar
Vinnie Okada committed
14
      @target_url = namespace_project_url(@project.namespace, @project)
15
      mail(to: @user.notification_email,
16
           subject: subject("Project was moved"))
17
    end
18

19 20 21
    def repository_push_email(project_id, recipient, author_id, branch, compare)
      @project = Project.find(project_id)
      @author  = User.find(author_id)
22
      @compare = compare
23
      @commits = Commit.decorate(compare.commits)
24 25
      @diffs   = compare.diffs
      @branch  = branch
26
      if @commits.length > 1
Vinnie Okada's avatar
Vinnie Okada committed
27 28 29 30
        @target_url = namespace_project_compare_url(@project.namespace,
                                                    @project,
                                                    from: @commits.first,
                                                    to: @commits.last)
31
        @subject = "#{@commits.length} new commits pushed to repository"
32
      else
Vinnie Okada's avatar
Vinnie Okada committed
33 34
        @target_url = namespace_project_commit_url(@project.namespace,
                                                   @project, @commits.first)
35
        @subject = @commits.first.title
36
      end
37

38
      mail(from: sender(author_id),
39
           to: recipient,
40
           subject: subject(@subject))
41
    end
42 43
  end
end