stupid-git-webhook 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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2009 Lucas Mundim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ = git-webhook
2
+
3
+ * http://github.com/lucasmundim/git-webhook
4
+
5
+ == DESCRIPTION:
6
+
7
+ Use it with a {git}[http://git-scm.com] post-receive hook script
8
+ to post JSON data to a web hook capable server.
9
+
10
+ This implements the {GitHub}[http://github.com] {Web hooks}[http://github.com/guides/post-receive-hooks]
11
+ as closely as possible.
12
+
13
+ This script works with almost every application that supports github
14
+ style notification.
15
+
16
+ == REQUIREMENTS:
17
+
18
+ * Grit (http://grit.rubyforge.org)
19
+ * Active Support (http://git-scm.com)
20
+
21
+ == INSTALL:
22
+
23
+ * sudo gem install git-webhook
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2009 Lucas Roxo Mundim. See LICENSE for details.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "git-webhook"
8
+ gem.summary = %Q{A github compatible post-receive web hook for git written in Ruby}
9
+ gem.email = "lucas.mundim@intelitiva.com"
10
+ gem.homepage = "http://github.com/lucasmundim/git-webhook"
11
+ gem.authors = ["Lucas Roxo Mundim"]
12
+ gem.rubyforge_project = "git-webhook"
13
+ gem.add_dependency('grit', '>= 1.1.1')
14
+ gem.add_dependency('active_support', '>= 2.3.3')
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+
18
+ Jeweler::RubyforgeTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_opts = ['--options', "spec/spec.opts"]
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ if File.exist?('VERSION.yml')
42
+ config = YAML.load(File.read('VERSION.yml'))
43
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
44
+ else
45
+ version = ""
46
+ end
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "git-webhook #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 1
4
+ :major: 0
@@ -0,0 +1,59 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{stupid-git-webhook}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Lucas Roxo Mundim"]
9
+ s.date = %q{2009-07-29}
10
+ s.email = %q{lucas.mundim@intelitiva.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "git-webhook.gemspec",
23
+ "lib/git-webhook.rb",
24
+ "lib/git-webhook/builder.rb",
25
+ "lib/git-webhook/core.rb",
26
+ "lib/git-webhook/notifier.rb",
27
+ "lib/git-webhook/repository.rb",
28
+ "script/console",
29
+ "spec/git-webhook_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/lucasmundim/git-webhook}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubyforge_project = %q{git-webhook}
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{A github compatible post-receive web hook for git written in Ruby}
39
+ s.test_files = [
40
+ "spec/git-webhook_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<grit>, [">= 1.1.1"])
50
+
51
+ else
52
+ s.add_dependency(%q<grit>, [">= 1.1.1"])
53
+
54
+ end
55
+ else
56
+ s.add_dependency(%q<grit>, [">= 1.1.1"])
57
+
58
+ end
59
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'git-webhook/core'
@@ -0,0 +1,23 @@
1
+ require 'git-webhook/repository'
2
+
3
+ module GitWebhook
4
+ class Builder
5
+
6
+ attr_reader :data_hash
7
+
8
+ def initialize(old, new, ref, repository_path, options = {})
9
+ @repository = GitWebhook::Repository.new(repository_path, options)
10
+ data = {
11
+ :before => old,
12
+ :after => new,
13
+ :ref => ref,
14
+ :commits => @repository.commits_between(old, new),
15
+ :repository => @repository.info
16
+ }
17
+ data.delete :repository if data[:repository].empty?
18
+ @data_hash = data
19
+ end
20
+
21
+
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'git-webhook/notifier'
2
+ require 'git-webhook/builder'
3
+
4
+ module GitWebhook
5
+
6
+ class Core
7
+
8
+ def initialize(old, new, ref, repository_path, options = {})
9
+ @data_hash = GitWebhook::Builder.new(old, new, ref, repository_path, options).data_hash
10
+ end
11
+
12
+ def notify(url)
13
+ notifier = GitWebhook::Notifier.new(@data_hash)
14
+ notifier.notify(url)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'rubygems'
4
+ require 'active_support'
5
+
6
+ module GitWebhook
7
+ class Notifier
8
+
9
+ def initialize(data_hash)
10
+ @data_hash = data_hash
11
+ end
12
+
13
+ def notify(url)
14
+ Net::HTTP.post_form(URI.parse(url), { :payload => @data_hash.to_json })
15
+ puts @data_hash.to_yaml
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,86 @@
1
+ require 'grit'
2
+
3
+ module GitWebhook
4
+
5
+ class Repository
6
+
7
+ def initialize(path, options = {})
8
+ options.to_options!
9
+ options.assert_valid_keys :url, :name, :description, :homepage, :watchers,
10
+ :forks, :private, :pledgie, :owner, :commit_url
11
+ options[:owner].assert_valid_keys(:name, :email) unless options[:owner].nil?
12
+
13
+ @repo = Grit::Repo.new(path)
14
+ @options = options
15
+ end
16
+
17
+ def info
18
+ @options.except(:commit_url)
19
+ end
20
+
21
+ def commits_between(old, new)
22
+ commits = []
23
+ @repo.commits_between(old, new).each do |commit|
24
+ commit_data = {
25
+ :id => commit.sha,
26
+ :author => {
27
+ :name => commit.author.name,
28
+ :email => commit.author.email
29
+ },
30
+ :message => commit.message,
31
+ :timestamp => commit.date.xmlschema
32
+ }
33
+ commit_data[:url] = @options[:commit_url] % commit.sha unless @options[:commit_url].blank?
34
+
35
+ commit_data.merge! commit_stats(commit)
36
+
37
+ commits << commit_data
38
+ end
39
+ commits
40
+ end
41
+
42
+ private
43
+
44
+ def commit_stats(commit)
45
+ stats = {}
46
+ [:added, :removed, :modified].each do |key|
47
+ stats[key] = []
48
+ end
49
+
50
+ commit.show.each do |file|
51
+ case
52
+ when added?(file)
53
+ stats[:added] << file.a_path
54
+ when removed?(file)
55
+ stats[:removed] << file.a_path
56
+ when modified?(file)
57
+ stats[:modified] << file.a_path
58
+ end
59
+ end
60
+
61
+ stats.delete_if {|key, value| value.nil? }
62
+ end
63
+
64
+ def added?(file)
65
+ file.new_file == true and file.deleted_file == false
66
+ end
67
+
68
+ def removed?(file)
69
+ file.new_file == false and file.deleted_file == true
70
+ end
71
+
72
+ def modified?(file)
73
+ file.new_file == false and file.deleted_file == false
74
+ end
75
+
76
+ def render_stats(added, deleted, modified)
77
+ stats = {}
78
+ stats[:added] = added unless added.empty?
79
+ stats[:deleted] = deleted unless deleted.empty?
80
+ stats[:modified] = modified unless modified.empty?
81
+ stats
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/git-webhook.rb'}"
9
+ puts "Loading git-webhook gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "GitWebhook" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'git-webhook'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stupid-git-webhook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Roxo Mundim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-29 00:00:00 +04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: grit
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.1
24
+ version:
25
+ description:
26
+ email: lucas.mundim@intelitiva.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION.yml
41
+ - git-webhook.gemspec
42
+ - lib/git-webhook.rb
43
+ - lib/git-webhook/builder.rb
44
+ - lib/git-webhook/core.rb
45
+ - lib/git-webhook/notifier.rb
46
+ - lib/git-webhook/repository.rb
47
+ - script/console
48
+ - spec/git-webhook_spec.rb
49
+ - spec/spec.opts
50
+ - spec/spec_helper.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/lucasmundim/git-webhook
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project: git-webhook
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A github compatible post-receive web hook for git written in Ruby
79
+ test_files:
80
+ - spec/git-webhook_spec.rb
81
+ - spec/spec_helper.rb