guillermo-rgithook 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-09-04
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 =Guillermo Álvarez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,9 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ lib/rgithook.rb
7
+ lib/rgithook/version.rb
8
+ lib/rgithook/html.rb
9
+ lib/rgithook/githook.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on rgithook, see http://rgithook.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = rgithook
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 =Guillermo Álvarez
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/rgithook.rb ADDED
@@ -0,0 +1,11 @@
1
+ __DIR__ = File.dirname(__FILE__)
2
+
3
+ $:.unshift(__DIR__) unless
4
+ $:.include?(__DIR__) || $:.include?(File.expand_path(__DIR__))
5
+
6
+ %w(version githook html).each { |f| require 'rgithook/'+f }
7
+
8
+ CONSTANTE="hola"
9
+
10
+
11
+
@@ -0,0 +1,190 @@
1
+ module RGitHook
2
+
3
+ # PostReceivePack es el pack que se recive al hacer un push
4
+ # Un mismo pack puede tener actualizacioens para diferentes branches
5
+ class PostReceivePack
6
+ def initialize(string = nil)
7
+ string ||= STDIN.read
8
+ @heads, @updates = string.split("\n"), []
9
+ @heads.each { |head| @updates << RefUpdate.new(head) }
10
+ require 'rubygems'
11
+ require 'tmail'
12
+ end
13
+
14
+ def to_html
15
+ "<div class='post_receive_pack'>\n#{map{|e|e.to_html}.join}\n</div>"
16
+ end
17
+
18
+ def to_s
19
+ text = "Se han recibido #{@heads.size} actualizaciones\n"
20
+ each_with_index do |update,index|
21
+ text << format("Actualización %d\n", index+1)
22
+ text << update.to_s
23
+ text << format("\n")
24
+ end
25
+ text
26
+ end
27
+
28
+ # Returns an Array of Strings naming refs
29
+ def refs
30
+ map {|update| update.ref}
31
+ end
32
+
33
+
34
+ def each
35
+ @updates.each {|u| yield u}
36
+ end
37
+
38
+ def each_with_index
39
+ @updates.each_with_index {|u| yield u}
40
+ end
41
+
42
+ def map
43
+ @updates.map {|u| yield u}
44
+ end
45
+
46
+ def sendmail
47
+ each do |refupdate|
48
+ refupdate.sendmail
49
+ end
50
+ end
51
+ end
52
+
53
+ # Un RefUpdate es una coleción de commits
54
+ class RefUpdate
55
+
56
+
57
+ attr_reader :ref
58
+ def initialize(string)
59
+ @rev_old, @rev_new, @ref = string.split(" ")
60
+ commits = %x(git rev-list #{@rev_old}..#{@rev_new}).split
61
+ @commits = commits.map {|c| Commit.new(c)}
62
+ end
63
+
64
+ def sendmail
65
+ to = %x(git-config hooks.mailinglist).strip
66
+ part = ::TMail::Mail.new
67
+ part.set_content_type "text", "html"
68
+ part.body = HTML_HEADER+to_html+HTML_FOOTER
69
+
70
+ mail = ::TMail::Mail.new
71
+ mail.to = to
72
+ mail.from = format("%s@%s",@ref.gsub("/","."),%x(hostname).strip)
73
+ mail.subject = format("%s se actualizo",@ref)
74
+ mail.body = to_s
75
+ mail.parts << part
76
+
77
+ sendmail = IO.popen("/usr/sbin/sendmail #{to}", "w")
78
+ sendmail.write mail.to_s
79
+ sendmail.close
80
+ mail.to_s
81
+ end
82
+
83
+ def to_s
84
+ commits = map {|commit| commit.to_s}
85
+ commits.join("\n")
86
+ end
87
+
88
+ def to_html
89
+ html = ""
90
+ html << "<div class='refupdate'>\n"
91
+ html << "<h2>Actualización de #{@ref}</h2>"
92
+ if @commits.size > 1
93
+
94
+ html << "<div class='summary'><ul>"
95
+ @commits.each do |commit|
96
+ html << format("<li class='summarycommit'>%s<br/><ul>",commit.message.split("\n")[0])
97
+ commit.files.each do |file|
98
+ html << format("<li class='file'><span>%s (<span class='insertions'>+%s</span>/<span class='deletions'>-%s</span>)</span></li>\n",file.name, file.ins.to_s, file.del.to_s)
99
+ end
100
+ html << "</ul></li>"
101
+ end
102
+ html << "</ul></div>\n"
103
+ end
104
+ html << "\n#{map {|c|c.to_html}.join}\n</div>\n"
105
+ html
106
+ end
107
+
108
+ protected
109
+ def each
110
+ @commits.each {|c| yield c}
111
+ end
112
+
113
+ def map
114
+ @commits.map {|c| yield c}
115
+ end
116
+
117
+ end
118
+
119
+ class Helpers
120
+ HTML_ESCAPE = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
121
+
122
+ # Returns a copy of <tt>text</tt> with ampersands, angle brackets and quotes
123
+ # escaped into HTML entities.
124
+ def self.html_escape(text)
125
+ text.to_s.gsub(/[\"><&]/) { |s| HTML_ESCAPE[s] }
126
+ end
127
+ end
128
+
129
+
130
+ # Commit Identifica a un único commit
131
+ class Commit
132
+ attr_reader :commit, :message, :author, :date, :files
133
+ def initialize(commit)
134
+ @commit = commit
135
+ log = %x(git-cat-file -p #{commit}).split("\n")
136
+
137
+ @message = log[5..-1].join("\n")
138
+ @author = log[2].split(" ")[1..-3].join(" ")
139
+ @date = Time.at log[2].split(" ")[-2].to_i
140
+ @files = %x(git diff #{commit}^ #{commit} --numstat).split("\n").map {|f| f.split("\t")}.map do |f|
141
+ diff = %x(git diff #{commit}^ #{commit} -- #{f[2]})
142
+ File.new(f[2],f[0],f[1], diff )
143
+ end
144
+ end
145
+
146
+ def to_s
147
+ "#{@commit[0..6]}... #{@message.split("\n")[0]}."
148
+ end
149
+
150
+ def to_html
151
+ html = ""
152
+ html << "<div class='commit'>"
153
+ html << "<dl>\n"
154
+ html << "<dt>sha1</dt><dd class='sha1'>#{@commit}</dd>\n"
155
+ html << "<dt>author</dt><dd class='author'>#{Helpers.html_escape(@author)}</dd>\n"
156
+ html << "<dt>date</dt><dd class='date'>#{@date}</dd>\n"
157
+ html << "<dt>message</dt><dd class='message'>\n\t#{Helpers.html_escape(@message)}\n\t</dd>\n"
158
+ html << "</dl>"
159
+ html << "<div class='diffs'>\n\t#{@files.map{ |diff| diff.to_html} }\n\t</div>\n"
160
+ html << "</div>"
161
+ html
162
+ end
163
+ end
164
+
165
+ class File
166
+ attr_reader :name, :ins, :del, :diff
167
+ def initialize(filename,inserts,deletions,diff)
168
+ @name, @ins, @del = filename,inserts,deletions
169
+ @diff = diff.split("\n")[4..-1].join("\n")
170
+ rescue NoMethodError
171
+ # No se pudo generar el diff
172
+ ensure
173
+ @diff = "" if @diff.nil?
174
+ end
175
+ def to_s
176
+ format("FILE: %s (+%s/-%s)\n%s",@name,@ins.to_s,@del.to_s,@diff)
177
+ end
178
+ def to_html
179
+ html = "<div class='file'>"
180
+ html << "<div class='filename'>#{@name}</div>"
181
+ html << "<div class='insertions'>+#{@ins}</div>"
182
+ html << "<div class='deletions'>-#{@del}</div>"
183
+ diff = Helpers.html_escape(@diff)
184
+ diff.gsub!( /^(\+[^+].*)$/, '<ins>\1</ins>')
185
+ diff.gsub!( /^(\-[^-].*)$/, '<del>\1</del>')
186
+ html << "<div class='diff'><pre>"+diff+"</pre></div>\n"
187
+ html << "</div>\n"
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,53 @@
1
+ module RGitHook
2
+ HTML_HEADER=<<-END
3
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html;" charset="utf-8"/>
7
+ <style>
8
+ .commit dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
9
+ .commit dt { float: left; width: 6em; font-weight: bold; }
10
+ .commit dt:after { content:':';}
11
+ .commit dl, .commit dt, .commit ul, .commit li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
12
+ .commit dl a { font-weight: bold}
13
+ .commit dl a:link { color:#fc3; }
14
+ .commit dl a:active { color:#ff0; }
15
+ .commit dl a:visited { color:#cc6; }
16
+ h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
17
+ .commit pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
18
+ .commit ul, pre { overflow: auto; }
19
+ #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
20
+ .diff { width: 100%; }
21
+ .diff h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
22
+ .diff .propset h4, .diff .binary h4 {margin:0;}
23
+ .diff pre {padding:0;line-height:1.2em;margin:0;}
24
+ .diff .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
25
+ .diff .propset .diff, .diff .binary .diff {padding:10px 0;}
26
+ .diff span {display:block;padding:0 10px;}
27
+ .diff .modfile, .diff .addfile, .diff .delfile, .diff .propset, .diff .binary, .diff .copfile {border:1px solid #ccc;margin:10px 0;}
28
+ .diff ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
29
+ .diff del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
30
+ .diff .lines, .info {color:#888;background:#fff;}
31
+ .filename, .insertions, .deletions {display: inline;}
32
+ .file {margin: 5px 0px 10px 20px}
33
+ .filename {font-weight: bolder;}
34
+ .insertions {color: green;}
35
+ .deletions {color: red;}
36
+ .summary {border: 1px #006 solid; padding: 6px;}
37
+ .summary li {list-style-type: none; margin: 0;padding: 0; font-size: 90%}
38
+ .summary .file {color: #444;font-size: 0.9em; padding-left: 20px;}
39
+ .summary ul {margin: 0; padding: 0;line-height:1.0em}
40
+ .summary ul ul {margin: 0px 0px 10px 0px;}
41
+ </style>
42
+ </head>
43
+ <body>
44
+ END
45
+
46
+ HTML_FOOTER=<<-END
47
+ </body>
48
+ </html>
49
+ END
50
+
51
+
52
+
53
+ end
@@ -0,0 +1,9 @@
1
+ module RGitHook
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/rgithook'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestRgithook < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guillermo-rgithook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "=Guillermo \xC3\x81lvarez"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - /home/guillermo/.gem/gem-public_cert.pem
12
+ date: 2008-09-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.7.0
23
+ version:
24
+ description: description of gem
25
+ email:
26
+ - =guillermo@cientifico.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - License.txt
34
+ - Manifest.txt
35
+ - PostInstall.txt
36
+ files:
37
+ - History.txt
38
+ - License.txt
39
+ - Manifest.txt
40
+ - PostInstall.txt
41
+ - README.rdoc
42
+ - lib/rgithook.rb
43
+ - lib/rgithook/version.rb
44
+ - lib/rgithook/html.rb
45
+ - lib/rgithook/githook.rb
46
+ - test/test_helper.rb
47
+ - test/test_rgithook.rb
48
+ has_rdoc: true
49
+ homepage: http://rgithook.rubyforge.org
50
+ post_install_message: |+
51
+
52
+ For more information on rgithook, see http://rgithook.rubyforge.org
53
+
54
+ NOTE: Change this information in PostInstall.txt
55
+ You can also delete it if you don't want it.
56
+
57
+
58
+ rdoc_options:
59
+ - --main
60
+ - README.txt
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project: rgithook
78
+ rubygems_version: 1.2.0
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: description of gem
82
+ test_files:
83
+ - test/test_helper.rb
84
+ - test/test_rgithook.rb