push_handler 0.1.0 → 0.2.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/Gemfile CHANGED
@@ -2,6 +2,7 @@ source :rubygems
2
2
 
3
3
  gem 'json'
4
4
  gem 'grit'
5
+ gem 'typhoeus'
5
6
 
6
7
  group :development do
7
8
  gem 'jeweler'
data/README.md CHANGED
@@ -11,54 +11,60 @@ Config
11
11
  4. In `.git/hooks/` directory of your repository, create a file called `post-receive`.
12
12
  5. Add the following text to `post-receive`, filling in your information:
13
13
 
14
- #!/usr/bin/ruby
15
- require 'rubygems'
16
- require 'push_handler'
14
+ ```ruby
15
+ #!/usr/bin/ruby
16
+ require 'rubygems'
17
+ require 'push_handler'
17
18
 
18
- # Through STDIN git passes us: <oldrev> <newrev> <refname>
19
- args = STDIN.readlines.first.split(/\s+/)
19
+ # Through STDIN git passes us: <oldrev> <newrev> <refname>
20
+ args = STDIN.readlines.first.split(/\s+/)
20
21
 
21
- PushHandler.configure do |config|
22
- config.repo = {
23
- # Where to see the repository on the web
24
- 'url' => 'http://git.example.com',
22
+ PushHandler.configure do |config|
23
+ config.repo = {
24
+ # Where to see the repository on the web
25
+ 'url' => 'http://git.example.com',
25
26
 
26
- # Repository name
27
- 'name' => 'Suppa Time',
27
+ # Repository name
28
+ 'name' => 'Suppa Time',
28
29
 
29
- # Directory on the machine where the contents of your .git folder lives
30
- 'working_dir' => '/mnt/suppa_time.git/',
30
+ # Directory on the machine where the contents of your .git folder lives
31
+ 'working_dir' => '/mnt/suppa_time.git/',
31
32
 
32
- # Repository owner contact info
33
- 'owner' => {
34
- 'name' => 'Big Boss Man',
35
- 'email' => 'bbm@example.com'
36
- }
37
- }
33
+ # True if 'working_dir' is pointing to a bare repository
34
+ 'is_bare' => true,
38
35
 
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'
36
+ # Repository owner contact info
37
+ 'owner' => {
38
+ 'name' => 'Big Boss Man',
39
+ 'email' => 'bbm@example.com'
40
+ }
41
+ }
41
42
 
42
- # The url that the github-services server is running.
43
- config.services['url'] = 'http://localhost:8080'
43
+ # Links to objects in your repository. Put the wildcard '%s' where the reference should go.
44
+ config.urls['commit'] = 'http://git.example.com/commits?id=%s' # '%s' will be replaced with the commit sha
45
+ config.urls['branch'] = 'http://git.example.com/branches?id=%s' # '%s' will be the branch name
44
46
 
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
47
+ # The url that the github-services server is running.
48
+ config.services['url'] = 'http://localhost:8080'
54
49
 
55
- PushHandler.send_to_services(*args)
50
+ # This is your configuration for 3rd parties.
51
+ config.services['data'] = {
52
+ 'hipchat' => {
53
+ 'auth_token' => '9082afake90210',
54
+ 'room' => 12345,
55
+ 'notify' => true
56
+ }
57
+ }
58
+ end
56
59
 
60
+ PushHandler.send_to_services(*args)
61
+ ```
57
62
 
58
63
  Note
59
64
  ----
60
65
 
61
66
  To see the parameters that each service requires you'll have to:
67
+
62
68
  1. Go to the `github-services/` directory
63
69
  2. Execute `rake services:config`
64
70
  3. Open `config/services.json` and look up the requirements
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,13 +1,15 @@
1
1
  module PushHandler
2
2
  class Config
3
3
  attr_accessor :repo
4
- attr_accessor :commit_url
4
+ attr_accessor :urls
5
+ attr_accessor :commit_url # DEPRECATED: please use urls['commit'] instead
5
6
  attr_accessor :services
6
7
 
7
8
  def initialize
8
9
  @repo = Hash.new('')
9
10
  @services = Hash.new()
10
11
  @commit_url = ''
12
+ @urls = Hash.new('')
11
13
  end
12
14
  end
13
15
  end
data/lib/push_handler.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'grit'
3
3
  require 'json'
4
+ require 'typhoeus'
4
5
  require 'net/http'
5
6
  require 'uri'
6
7
 
@@ -20,13 +21,15 @@ module PushHandler
20
21
  def send_to_services(old_commit, new_commit, ref_name)
21
22
  payload = construct_payload(old_commit, new_commit, ref_name)
22
23
  config.services['data'].each_pair do |service, data|
23
- puts Net::HTTP.post_form(
24
- URI.parse(config.services['url'] + '/' + service + '/push'),
25
- {
24
+ Typhoeus::Request.post(
25
+ config.services['url'] + '/' + service + '/push',
26
+ :method => :post,
27
+ :params => {
26
28
  'data' => data.to_json,
27
29
  'payload' => payload.to_json
28
- }
29
- ).body
30
+ },
31
+ :disable_ssl_peer_verification => true
32
+ )
30
33
  end
31
34
  end
32
35
 
@@ -35,7 +38,8 @@ module PushHandler
35
38
  hash_to_return = {
36
39
  'after' => new_commit,
37
40
  'before' => old_commit,
38
- 'ref' => ref_name
41
+ 'ref' => ref_name,
42
+ 'branch_url' => config.urls['branch'] % ref_name[/\/([^\/]+)$/, 1]
39
43
  }
40
44
 
41
45
  hash_to_return['repository'] = {
@@ -43,7 +47,7 @@ module PushHandler
43
47
  'name' => config.repo['name'],
44
48
  'owner' => config.repo['owner']
45
49
  }
46
- repo = Grit::Repo.new(config.repo['working_dir'])
50
+ repo = Grit::Repo.new(config.repo['working_dir'], :is_bare => config.repo['is_bare'])
47
51
  commits = Grit::Commit.find_all(
48
52
  repo,
49
53
  "#{old_commit}..#{new_commit}",
@@ -59,7 +63,7 @@ module PushHandler
59
63
  commit_hash['distinct'] = true
60
64
  commit_hash['id'] = commit.sha
61
65
  commit_hash['message'] = commit.message
62
- commit_hash['url'] = config.commit_url % commit.sha
66
+ commit_hash['url'] = (config.urls['commit'] || config.commit_url) % commit.sha
63
67
  commit_hash['author'] = {
64
68
  'name' => commit.author.name,
65
69
  'email' => commit.author.email
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{push_handler}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Lavrisha"]
12
+ s.date = %q{2011-09-20}
13
+ s.description = %q{This gem is for integreting a privately hosted repository with the open source Github services project.}
14
+ s.email = %q{michael.lavrisha@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Guardfile",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/push_handler.rb",
28
+ "lib/push_handler/config.rb",
29
+ "push_handler.gemspec",
30
+ "spec/push_handler_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/vrish88/push_handler}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.4.2}
37
+ s.summary = %q{Format push data in a format that Github services understands.}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<json>, [">= 0"])
44
+ s.add_runtime_dependency(%q<grit>, [">= 0"])
45
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
46
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>, [">= 0"])
48
+ s.add_development_dependency(%q<rake>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, [">= 0"])
50
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<json>, [">= 0"])
53
+ s.add_dependency(%q<grit>, [">= 0"])
54
+ s.add_dependency(%q<typhoeus>, [">= 0"])
55
+ s.add_dependency(%q<jeweler>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, [">= 0"])
57
+ s.add_dependency(%q<rake>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, [">= 0"])
59
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<json>, [">= 0"])
63
+ s.add_dependency(%q<grit>, [">= 0"])
64
+ s.add_dependency(%q<typhoeus>, [">= 0"])
65
+ s.add_dependency(%q<jeweler>, [">= 0"])
66
+ s.add_dependency(%q<bundler>, [">= 0"])
67
+ s.add_dependency(%q<rake>, [">= 0"])
68
+ s.add_dependency(%q<rspec>, [">= 0"])
69
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
70
+ end
71
+ end
72
+
@@ -10,9 +10,13 @@ describe PushHandler do
10
10
  'name' => 'Joe Schmoe',
11
11
  'email' => 'schmoe@example.com'
12
12
  },
13
- 'working_dir' => File.expand_path(File.dirname(__FILE__) + '/example_git_repo/')
13
+ 'working_dir' => File.expand_path(File.dirname(__FILE__) + '/example_git_repo/'),
14
+ 'is_bare' => false
15
+ } }
16
+ let(:urls) { {
17
+ 'branch' => 'http://example.com/%s',
18
+ 'commit' => 'http://example.com/master/commit?id=%s'
14
19
  } }
15
- let(:commit_url) { 'http://example.com/master/commit?id=%s'}
16
20
 
17
21
  let(:old_commit_hash) { '1afa4eba68c883738af4536f7e04d978964bb523' }
18
22
  let(:new_commit_hash) { '4e1b47e950a2f5d6afa6744fa92f3fce5d606e1b' }
@@ -21,7 +25,8 @@ describe PushHandler do
21
25
  before :all do
22
26
  PushHandler.configure do |config|
23
27
  config.repo = repo
24
- config.commit_url = commit_url
28
+ config.urls['commit'] = urls['commit']
29
+ config.urls['branch'] = urls['branch']
25
30
  config.services['url'] = 'http://localhost:8080'
26
31
  end
27
32
  end
@@ -50,6 +55,11 @@ describe PushHandler do
50
55
  should include_hash('ref' => ref_name)
51
56
  end
52
57
 
58
+ # NOT IN THE GITHUB SPECIFICATION
59
+ specify 'branch_url should have the branch name put into the url["branch"] string' do
60
+ should include_hash('branch_url' => urls['branch'] % 'master')
61
+ end
62
+
53
63
  specify 'before should be the old commit hash' do
54
64
  should include_hash('before' => old_commit_hash)
55
65
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push_handler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Lavrisha
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-15 00:00:00 -06:00
18
+ date: 2011-09-20 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -48,8 +48,8 @@ dependencies:
48
48
  requirement: *id002
49
49
  - !ruby/object:Gem::Dependency
50
50
  prerelease: false
51
- name: jeweler
52
- type: :development
51
+ name: typhoeus
52
+ type: :runtime
53
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
@@ -62,7 +62,7 @@ dependencies:
62
62
  requirement: *id003
63
63
  - !ruby/object:Gem::Dependency
64
64
  prerelease: false
65
- name: bundler
65
+ name: jeweler
66
66
  type: :development
67
67
  version_requirements: &id004 !ruby/object:Gem::Requirement
68
68
  none: false
@@ -76,7 +76,7 @@ dependencies:
76
76
  requirement: *id004
77
77
  - !ruby/object:Gem::Dependency
78
78
  prerelease: false
79
- name: rake
79
+ name: bundler
80
80
  type: :development
81
81
  version_requirements: &id005 !ruby/object:Gem::Requirement
82
82
  none: false
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirement: *id005
91
91
  - !ruby/object:Gem::Dependency
92
92
  prerelease: false
93
- name: rspec
93
+ name: rake
94
94
  type: :development
95
95
  version_requirements: &id006 !ruby/object:Gem::Requirement
96
96
  none: false
@@ -104,7 +104,7 @@ dependencies:
104
104
  requirement: *id006
105
105
  - !ruby/object:Gem::Dependency
106
106
  prerelease: false
107
- name: ruby-debug
107
+ name: rspec
108
108
  type: :development
109
109
  version_requirements: &id007 !ruby/object:Gem::Requirement
110
110
  none: false
@@ -116,6 +116,20 @@ dependencies:
116
116
  - 0
117
117
  version: "0"
118
118
  requirement: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ prerelease: false
121
+ name: ruby-debug
122
+ type: :development
123
+ version_requirements: &id008 !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ requirement: *id008
119
133
  description: This gem is for integreting a privately hosted repository with the open source Github services project.
120
134
  email: michael.lavrisha@gmail.com
121
135
  executables: []
@@ -135,6 +149,7 @@ files:
135
149
  - VERSION
136
150
  - lib/push_handler.rb
137
151
  - lib/push_handler/config.rb
152
+ - push_handler.gemspec
138
153
  - spec/push_handler_spec.rb
139
154
  - spec/spec_helper.rb
140
155
  has_rdoc: true