push_handler 0.1.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'json'
4
+ gem 'grit'
5
+
6
+ group :development do
7
+ gem 'jeweler'
8
+ gem 'bundler'
9
+ gem 'rake'
10
+ gem 'rspec'
11
+ gem 'ruby-debug'
12
+ end
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2, :cli => '-d' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
14
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+ watch('config/routes.rb') { "spec/routing" }
17
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
18
+ # Capybara request specs
19
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
20
+ end
21
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Michael Lavrisha
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/README.md ADDED
@@ -0,0 +1,64 @@
1
+ PushHandler
2
+ ===========
3
+
4
+ PushHandler takes push information and converts it into a format that [Github Services](https://github.com/github/github-services) can read and distribute.
5
+
6
+ Config
7
+ ------
8
+ 1. Download and install [Github Services](https://github.com/github/github-services)
9
+ 2. Start the Sinatra server by running `ruby github-services.rb`
10
+ 3. Install the gem `gem install push-handler`
11
+ 4. In `.git/hooks/` directory of your repository, create a file called `post-receive`.
12
+ 5. Add the following text to `post-receive`, filling in your information:
13
+
14
+ #!/usr/bin/ruby
15
+ require 'rubygems'
16
+ require 'push_handler'
17
+
18
+ # Through STDIN git passes us: <oldrev> <newrev> <refname>
19
+ args = STDIN.readlines.first.split(/\s+/)
20
+
21
+ PushHandler.configure do |config|
22
+ config.repo = {
23
+ # Where to see the repository on the web
24
+ 'url' => 'http://git.example.com',
25
+
26
+ # Repository name
27
+ 'name' => 'Suppa Time',
28
+
29
+ # Directory on the machine where the contents of your .git folder lives
30
+ 'working_dir' => '/mnt/suppa_time.git/',
31
+
32
+ # Repository owner contact info
33
+ 'owner' => {
34
+ 'name' => 'Big Boss Man',
35
+ 'email' => 'bbm@example.com'
36
+ }
37
+ }
38
+
39
+ # This is the link to the commit. Put the wildcard '%s' where the commit sha should go.
40
+ config.commit_url = 'http://git.example.com/commits?id=%s'
41
+
42
+ # The url that the github-services server is running.
43
+ config.services['url'] = 'http://localhost:8080'
44
+
45
+ # This is your configuration for 3rd parties.
46
+ config.services['data'] = {
47
+ 'hipchat' => {
48
+ 'auth_token' => '9082afake90210',
49
+ 'room' => 12345,
50
+ 'notify' => true
51
+ }
52
+ }
53
+ end
54
+
55
+ PushHandler.send_to_services(*args)
56
+
57
+
58
+ Note
59
+ ----
60
+
61
+ To see the parameters that each service requires you'll have to:
62
+ 1. Go to the `github-services/` directory
63
+ 2. Execute `rake services:config`
64
+ 3. Open `config/services.json` and look up the requirements
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'jeweler'
16
+
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = "push_handler"
20
+ gem.homepage = "http://github.com/vrish88/push_handler"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Format push data in a format that Github services understands.}
23
+ gem.description = %Q{This gem is for integreting a privately hosted repository with the open source Github services project.}
24
+ gem.email = "michael.lavrisha@gmail.com"
25
+ gem.authors = ["Michael Lavrisha"]
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec'
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,13 @@
1
+ module PushHandler
2
+ class Config
3
+ attr_accessor :repo
4
+ attr_accessor :commit_url
5
+ attr_accessor :services
6
+
7
+ def initialize
8
+ @repo = Hash.new('')
9
+ @services = Hash.new()
10
+ @commit_url = ''
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'grit'
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ require File.expand_path(File.dirname(__FILE__) + '/push_handler/config')
8
+
9
+ module PushHandler
10
+ extend self
11
+ attr_accessor :config
12
+
13
+ # this configure method implementation is taken
14
+ # from https://github.com/andrew/split/blob/master/lib/split.rb
15
+ def configure
16
+ self.config ||= Config.new
17
+ yield(self.config)
18
+ end
19
+
20
+ def send_to_services(old_commit, new_commit, ref_name)
21
+ payload = construct_payload(old_commit, new_commit, ref_name)
22
+ config.services['data'].each_pair do |service, data|
23
+ puts Net::HTTP.post_form(
24
+ URI.parse(config.services['url'] + '/' + service + '/push'),
25
+ {
26
+ 'data' => data.to_json,
27
+ 'payload' => payload.to_json
28
+ }
29
+ ).body
30
+ end
31
+ end
32
+
33
+ def construct_payload(old_commit, new_commit, ref_name)
34
+ hash_to_return = Hash.new({})
35
+ hash_to_return = {
36
+ 'after' => new_commit,
37
+ 'before' => old_commit,
38
+ 'ref' => ref_name
39
+ }
40
+
41
+ hash_to_return['repository'] = {
42
+ 'url' => config.repo['url'],
43
+ 'name' => config.repo['name'],
44
+ 'owner' => config.repo['owner']
45
+ }
46
+ repo = Grit::Repo.new(config.repo['working_dir'])
47
+ commits = Grit::Commit.find_all(
48
+ repo,
49
+ "#{old_commit}..#{new_commit}",
50
+ :'no-merges' => true
51
+ ).reverse
52
+
53
+ unless commits.empty?
54
+ hash_to_return['pusher'] = {
55
+ 'name' => commits.first.author.name
56
+ }
57
+ hash_to_return['commits'] = commits.collect do |commit|
58
+ Hash.new.tap do |commit_hash|
59
+ commit_hash['distinct'] = true
60
+ commit_hash['id'] = commit.sha
61
+ commit_hash['message'] = commit.message
62
+ commit_hash['url'] = config.commit_url % commit.sha
63
+ commit_hash['author'] = {
64
+ 'name' => commit.author.name,
65
+ 'email' => commit.author.email
66
+ }
67
+
68
+ # accomodate the odd formatting they have in their timestamp
69
+ timestamp = commit.authored_date.gmtime.strftime('%FT%T%z')
70
+ commit_hash['timestamp'] = timestamp[0..-3] + ':' + timestamp[-2..-1]
71
+
72
+ # figure out what, if any files should be added to the
73
+ # removed, added, or modified arrays
74
+ commit_hash['removed'] = []
75
+ commit_hash['added'] = []
76
+ commit_hash['modified'] = []
77
+ commit.diffs.each do |diff|
78
+ commit_hash['removed'] << diff.a_path if diff.deleted_file
79
+ commit_hash['added'] << diff.b_path if diff.new_file
80
+ commit_hash['modified'] << diff.a_path if !diff.new_file && !diff.deleted_file
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ hash_to_return
87
+ end
88
+ end
@@ -0,0 +1,142 @@
1
+ require 'push_handler'
2
+
3
+ describe PushHandler do
4
+ include PushHandler
5
+
6
+ let(:repo) { {
7
+ 'url' => 'http://example.com/repo.git',
8
+ 'name' => 'Just a test repo',
9
+ 'owner' => {
10
+ 'name' => 'Joe Schmoe',
11
+ 'email' => 'schmoe@example.com'
12
+ },
13
+ 'working_dir' => File.expand_path(File.dirname(__FILE__) + '/example_git_repo/')
14
+ } }
15
+ let(:commit_url) { 'http://example.com/master/commit?id=%s'}
16
+
17
+ let(:old_commit_hash) { '1afa4eba68c883738af4536f7e04d978964bb523' }
18
+ let(:new_commit_hash) { '4e1b47e950a2f5d6afa6744fa92f3fce5d606e1b' }
19
+ let(:ref_name) { 'refs/heads/master' }
20
+
21
+ before :all do
22
+ PushHandler.configure do |config|
23
+ config.repo = repo
24
+ config.commit_url = commit_url
25
+ config.services['url'] = 'http://localhost:8080'
26
+ end
27
+ end
28
+
29
+ describe '.send_to_services' do
30
+ context 'for each service configuration provided' do
31
+ it 'should send a request to that corresponding url'
32
+
33
+ it 'should send along the corresponding payload'
34
+ end
35
+ end
36
+
37
+ describe '.construct_payload' do
38
+ # repo info
39
+ let!(:result) do
40
+ PushHandler.construct_payload(old_commit_hash, new_commit_hash, ref_name)
41
+ end
42
+
43
+ context 'should return a payload with the following' do
44
+ subject { result }
45
+ specify 'after should be the new commit hash' do
46
+ should include_hash('after' => new_commit_hash)
47
+ end
48
+
49
+ specify 'ref should be the ref name' do
50
+ should include_hash('ref' => ref_name)
51
+ end
52
+
53
+ specify 'before should be the old commit hash' do
54
+ should include_hash('before' => old_commit_hash)
55
+ end
56
+
57
+ context 'repository info is specified in a config call' do
58
+ subject { result['repository'] }
59
+
60
+ specify 'should load the repo name' do
61
+ should include_hash('name' => repo['name'])
62
+ end
63
+
64
+ specify 'should load the repo url' do
65
+ should include_hash('url' => repo['url'])
66
+ end
67
+
68
+ context "the owner's" do
69
+ subject { result['repository']['owner']}
70
+ specify "name" do
71
+ should include_hash('name' => repo['owner']['name'])
72
+ end
73
+ specify "email" do
74
+ should include_hash('email' => repo['owner']['email'])
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'pusher' do
80
+
81
+ subject { result['pusher'] }
82
+
83
+ it 'should be the author of the latest commit' do
84
+ should include_hash('name' => 'Joe Schmoe')
85
+ end
86
+ end
87
+
88
+ context 'commits' do
89
+ context 'each commit should have the following info' do
90
+ subject { result['commits'].first }
91
+
92
+ it "should have distinct marked true (distinct to the branch? I'm not sure)" do
93
+ should include_hash('distinct' => true)
94
+ end
95
+ context 'removed' do
96
+ it "should return an array of file that were removed (if any)" do
97
+ should include_hash('removed' => [])
98
+ end
99
+ end
100
+ context 'added' do
101
+ it "should return an array of file that were added (if any)" do
102
+ should include_hash('added' => [])
103
+ end
104
+ end
105
+ context 'modified' do
106
+ it "should return an array of file that were modified (if any)" do
107
+ should include_hash('modified' => ['README'])
108
+ end
109
+ end
110
+ it "should have the commit message in 'message'" do
111
+ should include_hash('message' => 'add some more')
112
+ end
113
+ it "should have the timestamp in 'timestamp'" do
114
+ should include_hash('timestamp' => '2011-06-20T01:13:11-07:00')
115
+ end
116
+ it "should have the url in 'url'" do
117
+ should include_hash('url' => 'http://example.com/master/commit?id=f7e495a93758c74589acc28f8bc0893e4c89e7e8')
118
+ end
119
+ context 'author should be a hash with the keys' do
120
+ subject { result['commits'].first['author'] }
121
+ specify 'name' do
122
+ should include_hash('name' => 'Joe Schmoe')
123
+ end
124
+ specify 'email' do
125
+ should include_hash('email' => 'schmoe@example.com')
126
+ end
127
+ end
128
+ it "should specify the commit id in 'id'" do
129
+ should include_hash('id' => 'f7e495a93758c74589acc28f8bc0893e4c89e7e8')
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ RSpec::Matchers.define :include_hash do |expected|
138
+ match do |actual|
139
+ expected.keys.all?{|key| actual.has_key?(key)} &&
140
+ actual.fetch(expected.keys.first) == expected.values.first
141
+ end
142
+ end
@@ -0,0 +1 @@
1
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: push_handler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Michael Lavrisha
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-15 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: json
24
+ type: :runtime
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: grit
38
+ type: :runtime
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ name: jeweler
52
+ type: :development
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ name: bundler
66
+ type: :development
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirement: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ prerelease: false
79
+ name: rake
80
+ type: :development
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirement: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ prerelease: false
93
+ name: rspec
94
+ type: :development
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirement: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ prerelease: false
107
+ name: ruby-debug
108
+ type: :development
109
+ version_requirements: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirement: *id007
119
+ description: This gem is for integreting a privately hosted repository with the open source Github services project.
120
+ email: michael.lavrisha@gmail.com
121
+ executables: []
122
+
123
+ extensions: []
124
+
125
+ extra_rdoc_files:
126
+ - LICENSE.txt
127
+ - README.md
128
+ files:
129
+ - .document
130
+ - Gemfile
131
+ - Guardfile
132
+ - LICENSE.txt
133
+ - README.md
134
+ - Rakefile
135
+ - VERSION
136
+ - lib/push_handler.rb
137
+ - lib/push_handler/config.rb
138
+ - spec/push_handler_spec.rb
139
+ - spec/spec_helper.rb
140
+ has_rdoc: true
141
+ homepage: http://github.com/vrish88/push_handler
142
+ licenses:
143
+ - MIT
144
+ post_install_message:
145
+ rdoc_options: []
146
+
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ requirements: []
168
+
169
+ rubyforge_project:
170
+ rubygems_version: 1.4.2
171
+ signing_key:
172
+ specification_version: 3
173
+ summary: Format push data in a format that Github services understands.
174
+ test_files: []
175
+