Class: GitCommitMailer::PushInfo

Inherits:
Info
  • Object
show all
Defined in:
lib/git-commit-mailer/push-info.rb

Constant Summary collapse

REFERENCE_TYPE =
{
  :branch => "branch",
  :annotated_tag => "annotated tag",
  :unannotated_tag => "unannotated tag"
}
CHANGE_TYPE =
{
  :create => "created",
  :update => "updated",
  :delete => "deleted",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Info

#get_record, #get_records, #git, host_name, host_name=, #short_reference, #short_revision

Constructor Details

#initialize(mailer, old_revision, new_revision, reference, reference_type, change_type, log, commits = []) ⇒ PushInfo

Returns a new instance of PushInfo.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/git-commit-mailer/push-info.rb', line 24

def initialize(mailer, old_revision, new_revision, reference,
               reference_type, change_type, log, commits=[])
  @mailer = mailer
  @old_revision = old_revision
  @new_revision = new_revision
  if @new_revision != '0' * 40 #XXX well, i need to properly fix this bug later.
    @revision = @new_revision
  else
    @revision = @old_revision
  end
  @reference = reference
  @reference_type = reference_type
  @log = log
  author_name, author_email = get_records(["%an", "%ae"])
  @author_name = author_name
  @author_email = author_email
  @date = @mailer.date
  @change_type = change_type
  @commits = commits || []
end

Instance Attribute Details

#author_emailObject (readonly)

Returns the value of attribute author_email.



22
23
24
# File 'lib/git-commit-mailer/push-info.rb', line 22

def author_email
  @author_email
end

#author_nameObject (readonly)

Returns the value of attribute author_name.



22
23
24
# File 'lib/git-commit-mailer/push-info.rb', line 22

def author_name
  @author_name
end

#change_typeObject (readonly)

Returns the value of attribute change_type.



22
23
24
# File 'lib/git-commit-mailer/push-info.rb', line 22

def change_type
  @change_type
end

#commitsObject (readonly)

Returns the value of attribute commits.



23
24
25
# File 'lib/git-commit-mailer/push-info.rb', line 23

def commits
  @commits
end

#dateObject (readonly)

Returns the value of attribute date.



22
23
24
# File 'lib/git-commit-mailer/push-info.rb', line 22

def date
  @date
end

#logObject (readonly)

Returns the value of attribute log.



21
22
23
# File 'lib/git-commit-mailer/push-info.rb', line 21

def log
  @log
end

#new_revisionObject (readonly)

Returns the value of attribute new_revision.



21
22
23
# File 'lib/git-commit-mailer/push-info.rb', line 21

def new_revision
  @new_revision
end

#old_revisionObject (readonly)

Returns the value of attribute old_revision.



21
22
23
# File 'lib/git-commit-mailer/push-info.rb', line 21

def old_revision
  @old_revision
end

#referenceObject (readonly)

Returns the value of attribute reference.



21
22
23
# File 'lib/git-commit-mailer/push-info.rb', line 21

def reference
  @reference
end

#reference_typeObject (readonly)

Returns the value of attribute reference_type.



21
22
23
# File 'lib/git-commit-mailer/push-info.rb', line 21

def reference_type
  @reference_type
end

#subjectObject (readonly)

Returns the value of attribute subject.



22
23
24
# File 'lib/git-commit-mailer/push-info.rb', line 22

def subject
  @subject
end

Instance Method Details

#branch_changed?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/git-commit-mailer/push-info.rb', line 63

def branch_changed?
  !@commits.empty?
end

#format_mail_body_htmlObject



96
97
98
# File 'lib/git-commit-mailer/push-info.rb', line 96

def format_mail_body_html
  "<pre>#{ERB::Util.h(format_mail_body_text)}</pre>"
end

#format_mail_body_textObject



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/git-commit-mailer/push-info.rb', line 83

def format_mail_body_text
  body = ""
  body << "#{author_name}\t#{@mailer.format_time(date)}\n"
  body << "\n"
  body << "New Push:\n"
  body << "\n"
  body << "  Message:\n"
  log.rstrip.each_line do |line|
    body << "    #{line}"
  end
  body << "\n\n"
end

#format_mail_subjectObject



78
79
80
81
# File 'lib/git-commit-mailer/push-info.rb', line 78

def format_mail_subject
  "(push) #{PushInfo::REFERENCE_TYPE[reference_type]} " +
    "(#{short_reference}) is #{PushInfo::CHANGE_TYPE[change_type]}."
end

#headersObject



53
54
55
56
57
58
59
60
61
# File 'lib/git-commit-mailer/push-info.rb', line 53

def headers
  [
    "X-Git-OldRev: #{old_revision}",
    "X-Git-NewRev: #{new_revision}",
    "X-Git-Refname: #{reference}",
    "X-Git-Reftype: #{REFERENCE_TYPE[reference_type]}",
    "Message-ID: #{message_id}",
  ]
end

#message_idObject



49
50
51
# File 'lib/git-commit-mailer/push-info.rb', line 49

def message_id
  "<#{old_revision}.#{new_revision}@#{self.class.host_name}>"
end

#revisionObject



45
46
47
# File 'lib/git-commit-mailer/push-info.rb', line 45

def revision
  @new_revision
end