Class: Gitlab::Email::Message::RepositoryPush

Inherits:
Object
  • Object
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.

Raises:

  • (ArgumentError)


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

#actionObject (readonly)

Returns the value of attribute action.



7
8
9
# File 'lib/gitlab/email/message/repository_push.rb', line 7

def action
  @action
end

#author_idObject (readonly)

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

#refObject (readonly)

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_nameObject



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

#authorObject



33
34
35
# File 'lib/gitlab/email/message/repository_push.rb', line 33

def author
  @author ||= User.find(@author_id)
end

#commitsObject



37
38
39
40
41
# File 'lib/gitlab/email/message/repository_push.rb', line 37

def commits
  return unless compare

  @commits ||= compare.commits
end

#compareObject



54
55
56
# File 'lib/gitlab/email/message/repository_push.rb', line 54

def compare
  @opts[:compare]
end

#compare_timeoutObject



62
63
64
# File 'lib/gitlab/email/message/repository_push.rb', line 62

def compare_timeout
  diffs&.overflow?
end

#diff_refsObject



58
59
60
# File 'lib/gitlab/email/message/repository_push.rb', line 58

def diff_refs
  @opts[:diff_refs]
end

#diffsObject



43
44
45
46
47
48
# File 'lib/gitlab/email/message/repository_push.rb', line 43

def diffs
  return unless compare

  # This diff is more moderated in number of files and lines
  @diffs ||= compare.diffs(max_files: 30, max_lines: 5000, expanded: true).diff_files
end

#diffs_countObject



50
51
52
# File 'lib/gitlab/email/message/repository_push.rb', line 50

def diffs_count
  diffs&.size
end

#disable_diffs?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/gitlab/email/message/repository_push.rb', line 70

def disable_diffs?
  @opts[:disable_diffs] || false
end

#projectObject



29
30
31
# File 'lib/gitlab/email/message/repository_push.rb', line 29

def project
  @project ||= Project.find(@project_id)
end

#ref_nameObject



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_typeObject



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_toObject



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

Returns:

  • (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

Returns:

  • (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

#subjectObject



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_urlObject



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