Class: RGitHook::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/rgithook/githook.rb

Overview

Commit Identifica a un único commit

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commit) ⇒ Commit

Returns a new instance of Commit.



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/rgithook/githook.rb', line 136

def initialize(commit)
  @commit = commit
  log     = Git.cat_file(commit).split("\n")

  @message = log[5..-1].join("\n")
  @author  = log[2].split(" ")[1..-3].join(" ")
  @date    = Time.at log[2].split(" ")[-2].to_i
  @files   = Git.diff_numstat( commit ).split("\n").map {|f| f.split("\t")}.map do |f|
    diff = Git.diff_path( commit, f[2] )
    CommitFile.new(f[2],f[0],f[1], diff )
  end
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



135
136
137
# File 'lib/rgithook/githook.rb', line 135

def author
  @author
end

#commitObject (readonly)

Returns the value of attribute commit.



135
136
137
# File 'lib/rgithook/githook.rb', line 135

def commit
  @commit
end

#dateObject (readonly)

Returns the value of attribute date.



135
136
137
# File 'lib/rgithook/githook.rb', line 135

def date
  @date
end

#filesObject (readonly)

Returns the value of attribute files.



135
136
137
# File 'lib/rgithook/githook.rb', line 135

def files
  @files
end

#messageObject (readonly)

Returns the value of attribute message.



135
136
137
# File 'lib/rgithook/githook.rb', line 135

def message
  @message
end

Instance Method Details

#to_htmlObject



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rgithook/githook.rb', line 153

def to_html
  html = ""
  html << "<div>"
  html << "<dl style='font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; border: 1px #006 solid; background: #369; padding: 6px; color: #fff;'>\n"
    html << "<dt style='float: left; width: 6em; font-weight: bold;'>sha1:</dt><dd>#{@commit}</dd>\n"
    html << "<dt style='float: left; width: 6em; font-weight: bold;'>author:</dt><dd>#{Helpers.html_escape(@author)}</dd>\n"
    html << "<dt style='float: left; width: 6em; font-weight: bold;'>date:</dt><dd>#{@date}</dd>\n"
    html << "<dt style='float: left; width: 6em; font-weight: bold;'>message:</dt><dd>\n\t#{Helpers.html_escape(@message)}\n\t</dd>\n"
  html << "</dl>"
  html << "<div>\n\t#{@files.map{ |diff| diff.to_html} }\n\t</div>\n"
  html << "</div>"
  html
end

#to_sObject



149
150
151
# File 'lib/rgithook/githook.rb', line 149

def to_s
  "#{@commit[0..6]}... #{@message.split("\n")[0]}."
end