debian-mirror-gitlab/lib/gitlab/email/message/repository_push.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
3.7 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2015-12-23 02:04:40 +05:30
module Gitlab
module Email
module Message
class RepositoryPush
attr_reader :author_id, :ref, :action
2017-09-10 17:25:29 +05:30
include Gitlab::Routing
2016-06-02 11:05:42 +05:30
include DiffHelper
2015-12-23 02:04:40 +05:30
delegate :namespace, :name_with_namespace, to: :project, prefix: :project
delegate :name, to: :author, prefix: :author
2016-01-29 22:53:50 +05:30
delegate :username, to: :author, prefix: :author
2015-12-23 02:04:40 +05:30
2016-06-02 11:05:42 +05:30
def initialize(notify, project_id, opts = {})
2015-12-23 02:04:40 +05:30
raise ArgumentError, 'Missing options: author_id, ref, action' unless
opts[:author_id] && opts[:ref] && opts[:action]
@notify = notify
@project_id = project_id
@opts = opts.dup
@author_id = @opts.delete(:author_id)
@ref = @opts.delete(:ref)
@action = @opts.delete(:action)
end
def project
@project ||= Project.find(@project_id)
end
def author
@author ||= User.find(@author_id)
end
def commits
2016-08-24 12:49:21 +05:30
return unless compare
2016-09-13 17:45:13 +05:30
@commits ||= compare.commits
2015-12-23 02:04:40 +05:30
end
def diffs
2016-08-24 12:49:21 +05:30
return unless compare
2016-09-13 17:45:13 +05:30
# This diff is more moderated in number of files and lines
2017-09-10 17:25:29 +05:30
@diffs ||= compare.diffs(max_files: 30, max_lines: 5000, expanded: true).diff_files
2015-12-23 02:04:40 +05:30
end
def diffs_count
2017-08-17 22:00:37 +05:30
diffs&.size
2015-12-23 02:04:40 +05:30
end
def compare
2020-05-24 23:13:21 +05:30
@opts[:compare]
2015-12-23 02:04:40 +05:30
end
2016-06-02 11:05:42 +05:30
def diff_refs
@opts[:diff_refs]
end
2015-12-23 02:04:40 +05:30
def compare_timeout
2017-08-17 22:00:37 +05:30
diffs&.overflow?
2015-12-23 02:04:40 +05:30
end
def reverse_compare?
@opts[:reverse_compare] || false
end
def disable_diffs?
@opts[:disable_diffs] || false
end
def send_from_committer_email?
@opts[:send_from_committer_email] || false
end
def action_name
@action_name ||=
case @action
when :create
2022-10-11 01:57:18 +05:30
s_('Notify|pushed new')
2015-12-23 02:04:40 +05:30
when :delete
2022-10-11 01:57:18 +05:30
s_('Notify|deleted')
2015-12-23 02:04:40 +05:30
else
2022-10-11 01:57:18 +05:30
s_('Notify|pushed to')
2015-12-23 02:04:40 +05:30
end
end
def ref_name
@ref_name ||= Gitlab::Git.ref_name(@ref)
end
def ref_type
@ref_type ||= Gitlab::Git.tag_ref?(@ref) ? 'tag' : 'branch'
end
def target_url
if @action == :push && commits
if commits.length > 1
2017-09-10 17:25:29 +05:30
project_compare_url(project, from: compare.start_commit, to: compare.head_commit)
2015-12-23 02:04:40 +05:30
else
2017-09-10 17:25:29 +05:30
project_commit_url(project, commits.first)
2015-12-23 02:04:40 +05:30
end
else
unless @action == :delete
2017-09-10 17:25:29 +05:30
project_tree_url(project, ref_name)
2015-12-23 02:04:40 +05:30
end
end
end
def reply_to
if send_from_committer_email? && @notify.can_send_from_user_email?(author)
author.email
else
Gitlab.config.gitlab.email_reply_to
end
end
def subject
2019-02-15 15:39:39 +05:30
subject_text = ['[Git]']
2017-09-10 17:25:29 +05:30
subject_text << "[#{project.full_path}]"
2015-12-23 02:04:40 +05:30
subject_text << "[#{ref_name}]" if @action == :push
subject_text << ' '
if @action == :push && commits
if commits.length > 1
subject_text << "Deleted " if reverse_compare?
subject_text << "#{commits.length} commits: #{commits.first.title}"
else
subject_text << "Deleted 1 commit: " if reverse_compare?
subject_text << commits.first.title
end
else
subject_action = action_name.dup
subject_action[0] = subject_action[0].capitalize
subject_text << "#{subject_action} #{ref_type} #{ref_name}"
end
2019-02-15 15:39:39 +05:30
subject_text.join
2015-12-23 02:04:40 +05:30
end
end
end
end
end