flowdock-git-hook 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -8
- data/VERSION +1 -1
- data/flowdock-git-hook.gemspec +72 -0
- data/lib/flowdock/git.rb +20 -17
- data/post-receive +2 -2
- data/spec/builder_spec.rb +1 -1
- data/spec/flowdock_git_spec.rb +9 -11
- metadata +36 -52
data/README.rdoc
CHANGED
@@ -6,16 +6,16 @@ Git Post-Receive hook for Flowdock[http://flowdock.com]
|
|
6
6
|
|
7
7
|
First, you need to install this gem. You need to have Ruby 1.8.6 and Rubygems installed in your system.
|
8
8
|
|
9
|
-
gem install flowdock-git-hook
|
9
|
+
$ gem install flowdock-git-hook
|
10
10
|
|
11
11
|
Then, download the post-receive hook file to the hooks directory and make it executable
|
12
12
|
|
13
|
-
|
14
|
-
chmod +x hooks/post-receive
|
13
|
+
$ wget -O hooks/post-receive https://raw.github.com/flowdock/flowdock-git-hook/master/post-receive
|
14
|
+
$ chmod +x hooks/post-receive
|
15
15
|
|
16
16
|
Configure your Flow API tokens to git configuration
|
17
17
|
|
18
|
-
git config flowdock.token <Flow API token>
|
18
|
+
$ git config flowdock.token <Flow API token>
|
19
19
|
|
20
20
|
After this, you should get updates from your git repo every time you push to it.
|
21
21
|
|
@@ -23,16 +23,16 @@ After this, you should get updates from your git repo every time you push to it.
|
|
23
23
|
|
24
24
|
The git hook allows Flowdock tags to be attached to push messages. If you only need static tags, e.g. git repo name as tag, this can be configured in git config:
|
25
25
|
|
26
|
-
git config flowdock.tags git,push
|
26
|
+
$ git config flowdock.tags git,push
|
27
27
|
|
28
28
|
For programmatic control over tagging, you can change how the hook is called in post-receive hook file.
|
29
29
|
|
30
|
-
Flowdock::Git.
|
30
|
+
Flowdock::Git.background_post(ref, before, after, :tags => ["git", "push"])
|
31
31
|
|
32
32
|
Note that you can also define token as parameter allowing multiple Flows to be notified.
|
33
33
|
|
34
|
-
Flowdock::Git.
|
35
|
-
Flowdock::Git.
|
34
|
+
Flowdock::Git.background_post(ref, before, after, :token => "flow-token")
|
35
|
+
Flowdock::Git.background_post(ref, before, after, :token => "another-flow")
|
36
36
|
|
37
37
|
== Example data
|
38
38
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -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{flowdock-git-hook}
|
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 = ["Ville Lautanala"]
|
12
|
+
s.date = %q{2011-08-23}
|
13
|
+
s.email = %q{lautis@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE.txt",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".rspec",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"flowdock-git-hook.gemspec",
|
27
|
+
"lib/flowdock-git-hook.rb",
|
28
|
+
"lib/flowdock/git.rb",
|
29
|
+
"lib/flowdock/git/builder.rb",
|
30
|
+
"post-receive",
|
31
|
+
"spec/builder_spec.rb",
|
32
|
+
"spec/flowdock_git_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/flowdock/flowdock-git-hook}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.6}
|
39
|
+
s.summary = %q{Git Post-Receive hook for Flowdock}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<grit>, [">= 2.4.1"])
|
47
|
+
s.add_runtime_dependency(%q<multi_json>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
51
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<webmock>, [">= 1.6.4"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<grit>, [">= 2.4.1"])
|
55
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
s.add_dependency(%q<webmock>, [">= 1.6.4"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<grit>, [">= 2.4.1"])
|
64
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
68
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
69
|
+
s.add_dependency(%q<webmock>, [">= 1.6.4"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
data/lib/flowdock/git.rb
CHANGED
@@ -9,21 +9,28 @@ module Flowdock
|
|
9
9
|
class TokenError < StandardError; end
|
10
10
|
API_ENDPOINT = "https://api.flowdock.com/v1/git"
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
class << self
|
13
|
+
def post(ref, from, to, options = {})
|
14
|
+
git = Git.new(options)
|
15
|
+
git.post(Git::Builder.new(git.repo, ref, from, to))
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
+
def background_post(ref, from, to, options = {})
|
19
|
+
git = Git.new(options)
|
20
|
+
git.background_post(Git::Builder.new(git.repo, ref, from, to))
|
21
|
+
end
|
22
|
+
end
|
18
23
|
|
24
|
+
def initialize(options = {})
|
25
|
+
@options = options
|
19
26
|
@token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
|
20
27
|
end
|
21
28
|
|
22
29
|
# Send git push notification to Flowdock
|
23
|
-
def post
|
30
|
+
def post(data)
|
24
31
|
uri = URI.parse("#{API_ENDPOINT}/#{([@token] + tags).join('+')}")
|
25
32
|
req = Net::HTTP::Post.new(uri.path)
|
26
|
-
req.set_form_data(:payload => MultiJson.encode(
|
33
|
+
req.set_form_data(:payload => MultiJson.encode(data.to_hash))
|
27
34
|
http = Net::HTTP.new(uri.host, uri.port)
|
28
35
|
|
29
36
|
if uri.scheme == 'https'
|
@@ -35,17 +42,21 @@ module Flowdock
|
|
35
42
|
end
|
36
43
|
|
37
44
|
# Create and post notification in background process. Avoid blocking the push notification.
|
38
|
-
def background_post
|
45
|
+
def background_post(data)
|
39
46
|
pid = Process.fork
|
40
47
|
if pid.nil?
|
41
48
|
Grit::Git.with_timeout(600) do
|
42
|
-
post # Child
|
49
|
+
post(data) # Child
|
43
50
|
end
|
44
51
|
else
|
45
52
|
Process.detach(pid) # Parent
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
56
|
+
def repo
|
57
|
+
@repo ||= Grit::Repo.new(@options[:repo] || Dir.pwd)
|
58
|
+
end
|
59
|
+
|
49
60
|
private
|
50
61
|
|
51
62
|
# Flowdock tags attached to the push notification
|
@@ -59,14 +70,6 @@ module Flowdock
|
|
59
70
|
end
|
60
71
|
end
|
61
72
|
|
62
|
-
def payload
|
63
|
-
Builder.new(repo, @ref, @from, @to).to_hash
|
64
|
-
end
|
65
|
-
|
66
|
-
def repo
|
67
|
-
@repo ||= Grit::Repo.new(@options[:repo] || Dir.pwd)
|
68
|
-
end
|
69
|
-
|
70
73
|
def config
|
71
74
|
@config ||= Grit::Config.new(repo)
|
72
75
|
end
|
data/post-receive
CHANGED
data/spec/builder_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe "Git Payload Builder" do
|
|
4
4
|
before :each do
|
5
5
|
@repo = Grit::Repo.new(".")
|
6
6
|
@before = "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51"
|
7
|
-
@after = "
|
7
|
+
@after = "a66d3ce668ae6f2a42d54d811962724200d5b32b"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "parses ref name from head" do
|
data/spec/flowdock_git_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "Flowdock Git Hook" do
|
4
4
|
it "raises error if git token is not defined" do
|
5
5
|
lambda {
|
6
|
-
Flowdock::Git.new
|
6
|
+
Flowdock::Git.new
|
7
7
|
}.should raise_error(Flowdock::Git::TokenError)
|
8
8
|
end
|
9
9
|
|
@@ -13,13 +13,13 @@ describe "Flowdock Git Hook" do
|
|
13
13
|
})
|
14
14
|
|
15
15
|
lambda {
|
16
|
-
Flowdock::Git.new
|
16
|
+
Flowdock::Git.new
|
17
17
|
}.should_not raise_error
|
18
18
|
end
|
19
19
|
|
20
20
|
it "builds payload" do
|
21
21
|
stub_request(:post, "https://api.flowdock.com/v1/git/flowdock-token")
|
22
|
-
Flowdock::Git.
|
22
|
+
Flowdock::Git.post("refs/heads/master", "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51", "a1a94ba4bfa5f855676066861604b8edae1a20f5", :token => "flowdock-token")
|
23
23
|
a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token").with { |req|
|
24
24
|
req.body.match(/7e32af569ba794b0b1c5e4c38fef1d4e2e56be51/)
|
25
25
|
}.should have_been_made
|
@@ -27,7 +27,7 @@ describe "Flowdock Git Hook" do
|
|
27
27
|
|
28
28
|
describe "Tagging" do
|
29
29
|
it "reads tags from initializer parameter" do
|
30
|
-
tags = Flowdock::Git.new(
|
30
|
+
tags = Flowdock::Git.new(:token => "flowdock-token", :tags => ["foo", "bar"]).send(:tags)
|
31
31
|
tags.should include("foo", "bar")
|
32
32
|
end
|
33
33
|
|
@@ -35,30 +35,28 @@ describe "Flowdock Git Hook" do
|
|
35
35
|
Grit::Config.stub!(:new).and_return({
|
36
36
|
"flowdock.tags" => "foo,bar"
|
37
37
|
})
|
38
|
-
tags = Flowdock::Git.new(
|
38
|
+
tags = Flowdock::Git.new(:token => "flowdock-token").send(:tags)
|
39
39
|
tags.should include("foo", "bar")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "encodes tags suitable for URI" do
|
43
|
-
Flowdock::Git.new(
|
43
|
+
Flowdock::Git.new(:token => "flowdock-token", :tags => "foo%bar").send(:tags).should include("foo%25bar")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "Flowdock Git Hook", "HTTP Post" do
|
49
49
|
before :each do
|
50
|
-
@notifier = Flowdock::Git.new("origin/refs/master", "random-hash", "random-hash", :token => "flowdock-token", :tags => ["foo", "bar"])
|
51
|
-
@notifier.stub(:payload) { {} }
|
52
50
|
stub_request(:post, "https://api.flowdock.com/v1/git/flowdock-token+foo+bar")
|
51
|
+
Flowdock::Git.post("origin/refs/master", "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51", "a1a94ba4bfa5f855676066861604b8edae1a20f5", :token => "flowdock-token", :tags => ["foo", "bar"])
|
53
52
|
end
|
54
53
|
|
55
54
|
it "posts to api.flowdock.com" do
|
56
|
-
@notifier.post
|
57
55
|
a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token+foo+bar").should have_been_made
|
58
56
|
end
|
59
57
|
|
60
58
|
it "sends payload encoded as JSON" do
|
61
|
-
|
62
|
-
a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token+foo+bar").with(:body => {:payload =>
|
59
|
+
payload = MultiJson.encode(Flowdock::Git::Builder.new(Grit::Repo.new("."), "origin/refs/master", "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51", "a1a94ba4bfa5f855676066861604b8edae1a20f5").to_hash)
|
60
|
+
a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token+foo+bar").with(:body => {:payload => payload}).should have_been_made
|
63
61
|
end
|
64
62
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flowdock-git-hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
7
|
+
- 2
|
9
8
|
- 0
|
10
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Ville Lautanala
|
@@ -15,116 +14,103 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-08-23 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
21
22
|
type: :runtime
|
22
|
-
|
23
|
-
|
23
|
+
name: grit
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
27
|
-
hash: 29
|
28
28
|
segments:
|
29
29
|
- 2
|
30
30
|
- 4
|
31
31
|
- 1
|
32
32
|
version: 2.4.1
|
33
|
-
|
34
|
-
version_requirements: *id001
|
35
|
-
name: grit
|
33
|
+
requirement: *id001
|
36
34
|
- !ruby/object:Gem::Dependency
|
35
|
+
prerelease: false
|
37
36
|
type: :runtime
|
38
|
-
|
39
|
-
|
37
|
+
name: multi_json
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
39
|
requirements:
|
41
40
|
- - ">="
|
42
41
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
42
|
segments:
|
45
43
|
- 0
|
46
44
|
version: "0"
|
47
|
-
|
48
|
-
version_requirements: *id002
|
49
|
-
name: multi_json
|
45
|
+
requirement: *id002
|
50
46
|
- !ruby/object:Gem::Dependency
|
47
|
+
prerelease: false
|
51
48
|
type: :development
|
52
|
-
|
53
|
-
|
49
|
+
name: rspec
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - ~>
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 23
|
58
54
|
segments:
|
59
55
|
- 2
|
60
56
|
- 6
|
61
57
|
- 0
|
62
58
|
version: 2.6.0
|
63
|
-
|
64
|
-
version_requirements: *id003
|
65
|
-
name: rspec
|
59
|
+
requirement: *id003
|
66
60
|
- !ruby/object:Gem::Dependency
|
61
|
+
prerelease: false
|
67
62
|
type: :development
|
68
|
-
|
69
|
-
|
63
|
+
name: bundler
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
65
|
requirements:
|
71
66
|
- - ~>
|
72
67
|
- !ruby/object:Gem::Version
|
73
|
-
hash: 23
|
74
68
|
segments:
|
75
69
|
- 1
|
76
70
|
- 0
|
77
71
|
- 0
|
78
72
|
version: 1.0.0
|
79
|
-
|
80
|
-
version_requirements: *id004
|
81
|
-
name: bundler
|
73
|
+
requirement: *id004
|
82
74
|
- !ruby/object:Gem::Dependency
|
75
|
+
prerelease: false
|
83
76
|
type: :development
|
84
|
-
|
85
|
-
|
77
|
+
name: jeweler
|
78
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
79
|
requirements:
|
87
80
|
- - ~>
|
88
81
|
- !ruby/object:Gem::Version
|
89
|
-
hash: 11
|
90
82
|
segments:
|
91
83
|
- 1
|
92
84
|
- 6
|
93
85
|
- 2
|
94
86
|
version: 1.6.2
|
95
|
-
|
96
|
-
version_requirements: *id005
|
97
|
-
name: jeweler
|
87
|
+
requirement: *id005
|
98
88
|
- !ruby/object:Gem::Dependency
|
89
|
+
prerelease: false
|
99
90
|
type: :development
|
100
|
-
|
101
|
-
|
91
|
+
name: rcov
|
92
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
102
93
|
requirements:
|
103
94
|
- - ">="
|
104
95
|
- !ruby/object:Gem::Version
|
105
|
-
hash: 3
|
106
96
|
segments:
|
107
97
|
- 0
|
108
98
|
version: "0"
|
109
|
-
|
110
|
-
version_requirements: *id006
|
111
|
-
name: rcov
|
99
|
+
requirement: *id006
|
112
100
|
- !ruby/object:Gem::Dependency
|
101
|
+
prerelease: false
|
113
102
|
type: :development
|
114
|
-
|
115
|
-
|
103
|
+
name: webmock
|
104
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
116
105
|
requirements:
|
117
106
|
- - ">="
|
118
107
|
- !ruby/object:Gem::Version
|
119
|
-
hash: 7
|
120
108
|
segments:
|
121
109
|
- 1
|
122
110
|
- 6
|
123
111
|
- 4
|
124
112
|
version: 1.6.4
|
125
|
-
|
126
|
-
version_requirements: *id007
|
127
|
-
name: webmock
|
113
|
+
requirement: *id007
|
128
114
|
description:
|
129
115
|
email: lautis@gmail.com
|
130
116
|
executables: []
|
@@ -142,6 +128,7 @@ files:
|
|
142
128
|
- README.rdoc
|
143
129
|
- Rakefile
|
144
130
|
- VERSION
|
131
|
+
- flowdock-git-hook.gemspec
|
145
132
|
- lib/flowdock-git-hook.rb
|
146
133
|
- lib/flowdock/git.rb
|
147
134
|
- lib/flowdock/git/builder.rb
|
@@ -149,6 +136,7 @@ files:
|
|
149
136
|
- spec/builder_spec.rb
|
150
137
|
- spec/flowdock_git_spec.rb
|
151
138
|
- spec/spec_helper.rb
|
139
|
+
has_rdoc: true
|
152
140
|
homepage: http://github.com/flowdock/flowdock-git-hook
|
153
141
|
licenses:
|
154
142
|
- MIT
|
@@ -158,27 +146,23 @@ rdoc_options: []
|
|
158
146
|
require_paths:
|
159
147
|
- lib
|
160
148
|
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
149
|
requirements:
|
163
150
|
- - ">="
|
164
151
|
- !ruby/object:Gem::Version
|
165
|
-
hash: 3
|
166
152
|
segments:
|
167
153
|
- 0
|
168
154
|
version: "0"
|
169
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
-
none: false
|
171
156
|
requirements:
|
172
157
|
- - ">="
|
173
158
|
- !ruby/object:Gem::Version
|
174
|
-
hash: 3
|
175
159
|
segments:
|
176
160
|
- 0
|
177
161
|
version: "0"
|
178
162
|
requirements: []
|
179
163
|
|
180
164
|
rubyforge_project:
|
181
|
-
rubygems_version: 1.
|
165
|
+
rubygems_version: 1.3.6
|
182
166
|
signing_key:
|
183
167
|
specification_version: 3
|
184
168
|
summary: Git Post-Receive hook for Flowdock
|