Class: Gitlab::Email::Message::RepositoryPush
- Inherits:
-
Object
- Object
- Gitlab::Email::Message::RepositoryPush
show all
- Includes:
- DiffHelper, Routing
- Defined in:
- lib/gitlab/email/message/repository_push.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from DiffHelper
#apply_diff_view_cookie!, #collapsed_diff_url, #conflicts, #diff_file_blob_raw_path, #diff_file_blob_raw_url, #diff_file_html_data, #diff_file_old_blob_raw_path, #diff_file_old_blob_raw_url, #diff_file_stats_data, #diff_line_content, #diff_link_number, #diff_match_line, #diff_nomappinginraw_line, #diff_options, #diff_view, #diffs_expanded?, #editable_diff?, #inline_diff_btn, #mark_inline_diffs, #parallel_diff_btn, #parallel_diff_discussions, #params_with_whitespace, #render_fork_suggestion, #render_overflow_warning?, #show_only_context_commits?, #submodule_diff_compare_link, #submodule_link
Methods included from Routing
includes_helpers, redirect_legacy_paths, url_helpers
Constructor Details
#initialize(notify, project_id, opts = {}) ⇒ RepositoryPush
Returns a new instance of RepositoryPush.
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/gitlab/email/message/repository_push.rb', line 16
def initialize(notify, project_id, opts = {})
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
|
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
7
8
9
|
# File 'lib/gitlab/email/message/repository_push.rb', line 7
def action
@action
end
|
#author_id ⇒ Object
Returns the value of attribute author_id.
7
8
9
|
# File 'lib/gitlab/email/message/repository_push.rb', line 7
def author_id
@author_id
end
|
#ref ⇒ Object
Returns the value of attribute ref.
7
8
9
|
# File 'lib/gitlab/email/message/repository_push.rb', line 7
def ref
@ref
end
|
Instance Method Details
#action_name ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/gitlab/email/message/repository_push.rb', line 78
def action_name
@action_name ||=
case @action
when :create
s_('Notify|pushed new')
when :delete
s_('Notify|deleted')
else
s_('Notify|pushed to')
end
end
|
#author ⇒ Object
33
34
35
|
# File 'lib/gitlab/email/message/repository_push.rb', line 33
def author
@author ||= User.find(@author_id)
end
|
#commits ⇒ Object
37
38
39
40
41
|
# File 'lib/gitlab/email/message/repository_push.rb', line 37
def commits
return unless compare
@commits ||= compare.commits
end
|
#compare ⇒ Object
54
55
56
|
# File 'lib/gitlab/email/message/repository_push.rb', line 54
def compare
@opts[:compare]
end
|
#compare_timeout ⇒ Object
62
63
64
|
# File 'lib/gitlab/email/message/repository_push.rb', line 62
def compare_timeout
diffs&.overflow?
end
|
#diff_refs ⇒ Object
58
59
60
|
# File 'lib/gitlab/email/message/repository_push.rb', line 58
def diff_refs
@opts[:diff_refs]
end
|
#diffs ⇒ Object
43
44
45
46
47
48
|
# File 'lib/gitlab/email/message/repository_push.rb', line 43
def diffs
return unless compare
@diffs ||= compare.diffs(max_files: 30, max_lines: 5000, expanded: true).diff_files
end
|
#diffs_count ⇒ Object
50
51
52
|
# File 'lib/gitlab/email/message/repository_push.rb', line 50
def diffs_count
diffs&.size
end
|
#disable_diffs? ⇒ Boolean
70
71
72
|
# File 'lib/gitlab/email/message/repository_push.rb', line 70
def disable_diffs?
@opts[:disable_diffs] || false
end
|
#project ⇒ Object
29
30
31
|
# File 'lib/gitlab/email/message/repository_push.rb', line 29
def project
@project ||= Project.find(@project_id)
end
|
#ref_name ⇒ Object
90
91
92
|
# File 'lib/gitlab/email/message/repository_push.rb', line 90
def ref_name
@ref_name ||= Gitlab::Git.ref_name(@ref)
end
|
#ref_type ⇒ Object
94
95
96
|
# File 'lib/gitlab/email/message/repository_push.rb', line 94
def ref_type
@ref_type ||= Gitlab::Git.tag_ref?(@ref) ? 'tag' : 'branch'
end
|
#reply_to ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/gitlab/email/message/repository_push.rb', line 112
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
|
#reverse_compare? ⇒ Boolean
66
67
68
|
# File 'lib/gitlab/email/message/repository_push.rb', line 66
def reverse_compare?
@opts[:reverse_compare] || false
end
|
#send_from_committer_email? ⇒ Boolean
74
75
76
|
# File 'lib/gitlab/email/message/repository_push.rb', line 74
def send_from_committer_email?
@opts[:send_from_committer_email] || false
end
|
#subject ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/gitlab/email/message/repository_push.rb', line 120
def subject
subject_text = ['[Git]']
subject_text << "[#{project.full_path}]"
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
subject_text.join
end
|
#target_url ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/gitlab/email/message/repository_push.rb', line 98
def target_url
if @action == :push && commits
if commits.length > 1
project_compare_url(project, from: compare.start_commit, to: compare.head_commit)
else
project_commit_url(project, commits.first)
end
else
unless @action == :delete
project_tree_url(project, ref_name)
end
end
end
|