flowdock-git-hook 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Flowdock Git Hook
2
+
3
+ Git Post-Receive hook for [Flowdock](http://flowdock.com).
4
+
5
+ ## Installation
6
+
7
+ First, you need to install this gem. You need to have Ruby 1.8.6 and Rubygems installed in your system.
8
+
9
+ $ gem install flowdock-git-hook
10
+
11
+ Then, download the post-receive hook file to the hooks directory and make it executable
12
+
13
+ $ wget -O hooks/post-receive https://raw.github.com/flowdock/flowdock-git-hook/master/post-receive
14
+ $ chmod +x hooks/post-receive
15
+
16
+ Configure your Flow API tokens to git configuration
17
+
18
+ $ git config flowdock.token <Flow API token>
19
+
20
+ After this, you should get updates from your git repo every time you push to it.
21
+
22
+ ## Configuration
23
+
24
+ Service specific instructions for [Gitlab](https://github.com/flowdock/flowdock-git-hook/wiki/Gitlab) and [Redmine](https://github.com/flowdock/flowdock-git-hook/wiki/Redmine) can be found in [Wiki](https://github.com/flowdock/flowdock-git-hook/wiki).
25
+
26
+ ### Repository URL
27
+
28
+ Each Team Inbox item sent from the post-receive hook can link back to the repository. To configure the URL for the repository, configure a `repository-url`:
29
+
30
+ $ git config flowdock.repository-url "http://example.com/mygitviewer/repo"
31
+
32
+ ### Commit URLs
33
+
34
+ Commit SHAs links in the Team Inbox of Flowdock can be made clickable to view the change on the web. To configure the URL for viewing commits, configure a `commit-url-pattern`:
35
+
36
+ $ git config flowdock.commit-url-pattern "http://example.com/mygitviewer/commits/%s"
37
+
38
+ The `%s` will be replaced with the commit SHA.
39
+
40
+ ### Diff URL
41
+
42
+ Commit messages in Team Inbox can have a action for viewing the commit diff. To enable the Diff action for comparing commits, configure a `diff-url-pattern`:
43
+
44
+ $ gitconfig flowdock.diff-url-pattern "http://example.com/mygitviewer/compare/%s...%s"
45
+
46
+ ## Advanced usage
47
+
48
+ 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:
49
+
50
+ $ git config flowdock.tags git,push
51
+
52
+ For programmatic control over tagging, you can change how the hook is called in post-receive hook file.
53
+
54
+ Flowdock::Git.background_post(ref, before, after, :tags => ["git", "push"])
55
+
56
+ Note that you can also define token as parameter allowing multiple Flows to be notified.
57
+
58
+ Flowdock::Git.background_post(ref, before, after, :token => "flow-token")
59
+ Flowdock::Git.background_post(ref, before, after, :token => "another-flow")
60
+
61
+ ## Example data
62
+
63
+ The hook uses [GitHub webhook](http://help.github.com/post-receive-hooks/) format.
64
+
65
+ payload {
66
+ "after": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
67
+ "before": "2a445d1d348d9d45217cb9c89c12b67d3767ce42",
68
+ "commits": [
69
+ {
70
+ "added": [],
71
+ "author": {
72
+ "email": "raine.virta@nodeta.fi",
73
+ "name": "Raine Virta"
74
+ },
75
+ "id": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
76
+ "message": "yeah!",
77
+ "modified": [
78
+ "TEST_FILE"
79
+ ],
80
+ "removed": [],
81
+ "timestamp": "2010-08-11T13:46:39+03:00"
82
+ }
83
+ ],
84
+ "ref": "refs\/heads\/master",
85
+ "ref_name": "master",
86
+ "repository": {
87
+ "name": "testrepo"
88
+ }
89
+ }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -5,15 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "flowdock-git-hook"
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ville Lautanala"]
12
- s.date = "2012-10-18"
12
+ s.date = "2013-01-13"
13
13
  s.email = "lautis@gmail.com"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
16
- "README.rdoc"
16
+ "README.md"
17
17
  ]
18
18
  s.files = [
19
19
  ".document",
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  ".travis.yml",
22
22
  "Gemfile",
23
23
  "LICENSE.txt",
24
- "README.rdoc",
24
+ "README.md",
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "flowdock-git-hook.gemspec",
data/lib/flowdock/git.rb CHANGED
@@ -25,6 +25,8 @@ module Flowdock
25
25
  @options = options
26
26
  @token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
27
27
  @commit_url = config["flowdock.commit-url-pattern"] || nil
28
+ @diff_url = config["flowdock.diff-url-pattern"] || nil
29
+ @repo_url = config["flowdock.repository-url"] || nil
28
30
  end
29
31
 
30
32
  # Send git push notification to Flowdock
@@ -33,11 +35,17 @@ module Flowdock
33
35
  req = Net::HTTP::Post.new(uri.path)
34
36
 
35
37
  payload_hash = data.to_hash
38
+ if @repo_url
39
+ payload_hash[:repository][:url] = @repo_url
40
+ end
36
41
  if @commit_url
37
42
  payload_hash[:commits].each do |commit|
38
43
  commit[:url] = @commit_url % commit[:id]
39
44
  end
40
45
  end
46
+ if @diff_url
47
+ payload_hash[:compare] = @diff_url % [payload_hash[:before], payload_hash[:after]]
48
+ end
41
49
 
42
50
  req.set_form_data(:payload => MultiJson.encode(payload_hash))
43
51
  http = Net::HTTP.new(uri.host, uri.port)
@@ -33,6 +33,22 @@ describe "Flowdock Git Hook" do
33
33
  }.should have_been_made
34
34
  end
35
35
 
36
+ it "builds payload with repo url, diff url and commit urls" do
37
+ Grit::Config.stub!(:new).and_return({
38
+ "flowdock.token" => "flowdock-token",
39
+ "flowdock.repository-url" => "http://www.example.com",
40
+ "flowdock.diff-url-pattern" => "http://www.example.com/compare/%s...%s",
41
+ "flowdock.commit-url-pattern" => "http://www.example.com/commit/%s"
42
+ })
43
+ stub_request(:post, "https://api.flowdock.com/v1/git/flowdock-token")
44
+ Flowdock::Git.post("refs/heads/master", "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51", "a1a94ba4bfa5f855676066861604b8edae1a20f5", :token => "flowdock-token")
45
+ a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token").with { |req|
46
+ body = CGI.unescape(req.body)
47
+ body.match("http://www.example.com/") &&
48
+ body.match("http://www.example.com/compare/7e32af569ba794b0b1c5e4c38fef1d4e2e56be51...a1a94ba4bfa5f855676066861604b8edae1a20f5")
49
+ }.should have_been_made
50
+ end
51
+
36
52
  describe "Tagging" do
37
53
  it "reads tags from initializer parameter" do
38
54
  tags = Flowdock::Git.new(:token => "flowdock-token", :tags => ["foo", "bar"]).send(:tags)
metadata CHANGED
@@ -1,158 +1,158 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowdock-git-hook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
4
  prerelease:
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ville Lautanala
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-18 00:00:00.000000000 Z
12
+ date: 2013-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: grit
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.4.1
20
+ none: false
22
21
  type: :runtime
23
- prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.4.1
27
+ none: false
28
+ prerelease: false
29
+ name: grit
30
30
  - !ruby/object:Gem::Dependency
31
- name: multi_json
32
31
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
32
  requirements:
35
33
  - - ! '>='
36
34
  - !ruby/object:Gem::Version
37
35
  version: '0'
36
+ none: false
38
37
  type: :runtime
39
- prerelease: false
40
38
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
39
  requirements:
43
40
  - - ! '>='
44
41
  - !ruby/object:Gem::Version
45
42
  version: '0'
43
+ none: false
44
+ prerelease: false
45
+ name: multi_json
46
46
  - !ruby/object:Gem::Dependency
47
- name: rdoc
48
47
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
48
  requirements:
51
49
  - - ! '>='
52
50
  - !ruby/object:Gem::Version
53
51
  version: 2.4.2
52
+ none: false
54
53
  type: :development
55
- prerelease: false
56
54
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
55
  requirements:
59
56
  - - ! '>='
60
57
  - !ruby/object:Gem::Version
61
58
  version: 2.4.2
59
+ none: false
60
+ prerelease: false
61
+ name: rdoc
62
62
  - !ruby/object:Gem::Dependency
63
- name: rspec
64
63
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
65
  - - ~>
68
66
  - !ruby/object:Gem::Version
69
67
  version: '2.8'
68
+ none: false
70
69
  type: :development
71
- prerelease: false
72
70
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
71
  requirements:
75
72
  - - ~>
76
73
  - !ruby/object:Gem::Version
77
74
  version: '2.8'
75
+ none: false
76
+ prerelease: false
77
+ name: rspec
78
78
  - !ruby/object:Gem::Dependency
79
- name: bundler
80
79
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
80
  requirements:
83
81
  - - ~>
84
82
  - !ruby/object:Gem::Version
85
83
  version: '1.0'
84
+ none: false
86
85
  type: :development
87
- prerelease: false
88
86
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
87
  requirements:
91
88
  - - ~>
92
89
  - !ruby/object:Gem::Version
93
90
  version: '1.0'
91
+ none: false
92
+ prerelease: false
93
+ name: bundler
94
94
  - !ruby/object:Gem::Dependency
95
- name: jeweler
96
95
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
96
  requirements:
99
97
  - - ~>
100
98
  - !ruby/object:Gem::Version
101
99
  version: 1.6.2
100
+ none: false
102
101
  type: :development
103
- prerelease: false
104
102
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
103
  requirements:
107
104
  - - ~>
108
105
  - !ruby/object:Gem::Version
109
106
  version: 1.6.2
107
+ none: false
108
+ prerelease: false
109
+ name: jeweler
110
110
  - !ruby/object:Gem::Dependency
111
- name: webmock
112
111
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
112
  requirements:
115
113
  - - ! '>='
116
114
  - !ruby/object:Gem::Version
117
115
  version: 1.6.4
116
+ none: false
118
117
  type: :development
119
- prerelease: false
120
118
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
119
  requirements:
123
120
  - - ! '>='
124
121
  - !ruby/object:Gem::Version
125
122
  version: 1.6.4
123
+ none: false
124
+ prerelease: false
125
+ name: webmock
126
126
  - !ruby/object:Gem::Dependency
127
- name: jruby-openssl
128
127
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
128
  requirements:
131
129
  - - ! '>='
132
130
  - !ruby/object:Gem::Version
133
131
  version: '0'
132
+ none: false
134
133
  type: :development
135
- prerelease: false
136
134
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
135
  requirements:
139
136
  - - ! '>='
140
137
  - !ruby/object:Gem::Version
141
138
  version: '0'
139
+ none: false
140
+ prerelease: false
141
+ name: jruby-openssl
142
142
  description:
143
143
  email: lautis@gmail.com
144
144
  executables: []
145
145
  extensions: []
146
146
  extra_rdoc_files:
147
147
  - LICENSE.txt
148
- - README.rdoc
148
+ - README.md
149
149
  files:
150
150
  - .document
151
151
  - .rspec
152
152
  - .travis.yml
153
153
  - Gemfile
154
154
  - LICENSE.txt
155
- - README.rdoc
155
+ - README.md
156
156
  - Rakefile
157
157
  - VERSION
158
158
  - flowdock-git-hook.gemspec
@@ -171,20 +171,20 @@ rdoc_options: []
171
171
  require_paths:
172
172
  - lib
173
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
- none: false
175
174
  requirements:
176
175
  - - ! '>='
177
176
  - !ruby/object:Gem::Version
177
+ hash: -2102498903876344140
178
178
  version: '0'
179
179
  segments:
180
180
  - 0
181
- hash: 3361873183891229684
182
- required_rubygems_version: !ruby/object:Gem::Requirement
183
181
  none: false
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
183
  requirements:
185
184
  - - ! '>='
186
185
  - !ruby/object:Gem::Version
187
186
  version: '0'
187
+ none: false
188
188
  requirements: []
189
189
  rubyforge_project:
190
190
  rubygems_version: 1.8.23
data/README.rdoc DELETED
@@ -1,79 +0,0 @@
1
- = Flowdock Git Hook
2
-
3
- Git Post-Receive hook for Flowdock[http://flowdock.com]
4
-
5
- == Installation
6
-
7
- First, you need to install this gem. You need to have Ruby 1.8.6 and Rubygems installed in your system.
8
-
9
- $ gem install flowdock-git-hook
10
-
11
- Then, download the post-receive hook file to the hooks directory and make it executable
12
-
13
- $ wget -O hooks/post-receive https://raw.github.com/flowdock/flowdock-git-hook/master/post-receive
14
- $ chmod +x hooks/post-receive
15
-
16
- Configure your Flow API tokens to git configuration
17
-
18
- $ git config flowdock.token <Flow API token>
19
-
20
- After this, you should get updates from your git repo every time you push to it.
21
-
22
- == Commit URLs
23
-
24
- Commit SHAs links in the Team Inbox of Flowdock can be made clickable to view the change on the web. To configure the URL for viewing commits, configure a <tt>commit-url-pattern</tt>:
25
-
26
- $ config flowdock.commit-url-pattern "http://example.com/mygitviewer/commits/%s"
27
-
28
- The <tt>%s</tt> will be replaced with the commit SHA.
29
-
30
- Example for Redmine:
31
-
32
- $ git config flowdock.commit-url-pattern "http://developer.example.com/projects/myproject/repository/revisions/%s"
33
-
34
- Replace 'myproject' with the project the Git repository is associated with.
35
-
36
- == Advanced usage
37
-
38
- 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:
39
-
40
- $ git config flowdock.tags git,push
41
-
42
- For programmatic control over tagging, you can change how the hook is called in post-receive hook file.
43
-
44
- Flowdock::Git.background_post(ref, before, after, :tags => ["git", "push"])
45
-
46
- Note that you can also define token as parameter allowing multiple Flows to be notified.
47
-
48
- Flowdock::Git.background_post(ref, before, after, :token => "flow-token")
49
- Flowdock::Git.background_post(ref, before, after, :token => "another-flow")
50
-
51
- == Example data
52
-
53
- The hook uses {GitHub webhook}[http://help.github.com/post-receive-hooks/] format.
54
-
55
- payload {
56
- "after": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
57
- "before": "2a445d1d348d9d45217cb9c89c12b67d3767ce42",
58
- "commits": [
59
- {
60
- "added": [],
61
- "author": {
62
- "email": "raine.virta@nodeta.fi",
63
- "name": "Raine Virta"
64
- },
65
- "id": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
66
- "message": "yeah!",
67
- "modified": [
68
- "TEST_FILE"
69
- ],
70
- "removed": [],
71
- "timestamp": "2010-08-11T13:46:39+03:00"
72
- }
73
- ],
74
- "ref": "refs\/heads\/master",
75
- "ref_name": "master",
76
- "repository": {
77
- "name": "testrepo"
78
- }
79
- }