summaryrefslogtreecommitdiff
path: root/app/mailers/emails/projects.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/mailers/emails/projects.rb')
-rw-r--r--app/mailers/emails/projects.rb66
1 files changed, 50 insertions, 16 deletions
diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb
index b55129de292..48458baa674 100644
--- a/app/mailers/emails/projects.rb
+++ b/app/mailers/emails/projects.rb
@@ -16,31 +16,65 @@ module Emails
subject: subject("Project was moved"))
end
- def repository_push_email(project_id, recipient, author_id, branch, compare, reverse_compare = false, send_from_committer_email = false, disable_diffs = false)
+ def repository_push_email(project_id, recipient, author_id:,
+ ref:,
+ action:,
+ compare: nil,
+ reverse_compare: false,
+ send_from_committer_email: false,
+ disable_diffs: false)
@project = Project.find(project_id)
@author = User.find(author_id)
@reverse_compare = reverse_compare
@compare = compare
- @commits = Commit.decorate(compare.commits)
- @diffs = compare.diffs
- @branch = Gitlab::Git.ref_name(branch)
+ @ref_name = Gitlab::Git.ref_name(ref)
+ @ref_type = Gitlab::Git.tag_ref?(ref) ? "tag" : "branch"
+ @action = action
@disable_diffs = disable_diffs
- @subject = "[#{@project.path_with_namespace}][#{@branch}] "
+ if @compare
+ @commits = Commit.decorate(compare.commits)
+ @diffs = compare.diffs
+ end
+
+ @action_name =
+ case action
+ when :create
+ "pushed new"
+ when :delete
+ "deleted"
+ else
+ "pushed to"
+ end
+
+ @subject = "[#{@project.path_with_namespace}]"
+ @subject << "[#{@ref_name}]" if action == :push
+ @subject << " "
+
+ if action == :push
+ if @commits.length > 1
+ @target_url = namespace_project_compare_url(@project.namespace,
+ @project,
+ from: Commit.new(@compare.base),
+ to: Commit.new(@compare.head))
+ @subject << "Deleted " if @reverse_compare
+ @subject << "#{@commits.length} commits: #{@commits.first.title}"
+ else
+ @target_url = namespace_project_commit_url(@project.namespace,
+ @project, @commits.first)
- if @commits.length > 1
- @target_url = namespace_project_compare_url(@project.namespace,
- @project,
- from: Commit.new(@compare.base),
- to: Commit.new(@compare.head))
- @subject << "Deleted " if @reverse_compare
- @subject << "#{@commits.length} commits: #{@commits.first.title}"
+ @subject << "Deleted 1 commit: " if @reverse_compare
+ @subject << @commits.first.title
+ end
else
- @target_url = namespace_project_commit_url(@project.namespace,
- @project, @commits.first)
+ unless action == :delete
+ @target_url = namespace_project_tree_url(@project.namespace,
+ @project, @ref_name)
+ end
- @subject << "Deleted 1 commit: " if @reverse_compare
- @subject << @commits.first.title
+ subject_action = @action_name.dup
+ subject_action[0] = subject_action[0].capitalize
+ @subject << "#{subject_action} #{@ref_type} #{@ref_name}"
end
@disable_footer = true