Skip to content
This repository
Browse code

Documentation

  • Loading branch information...
commit 662a0d9f8d6d32da1ba34cf5882b8522f07517f7 1 parent 8bf1afa
Ville Lautanala lautis authored
70 README.rdoc
Source Rendered
... ... @@ -1,19 +1,65 @@
1 1 = Flowdock Git Hook
2 2
3   -Git Post-Receive hook for Flowdock
  3 +Git Post-Receive hook for Flowdock[http://flowdock.com]
4 4
5   -== Contributing to flowdock-git-hook
  5 +== Installation
6 6
7   -* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8   -* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9   -* Fork the project
10   -* Start a feature/bugfix branch
11   -* Commit and push until you are happy with your contribution
12   -* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13   -* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
  7 +First, you need to install this gem. You need to have Ruby 1.8.6 and Rubygems installed in your system.
14 8
15   -== Copyright
  9 + gem install flowdock-git-hook
16 10
17   -Copyright (c) 2011 Ville Lautanala. See LICENSE.txt for
18   -further details.
  11 +Then, download the post-receive hook file to the hooks directory and make it executable
19 12
  13 + curl -o hooks/post-receive http://github.com/flowdock/flowdock-git-hook/raw/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 +== Advanced usage
  23 +
  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 +
  26 + git config flowdock.tags git,push
  27 +
  28 +For programmatic control over tagging, you can change how the hook is called in post-receive hook file.
  29 +
  30 + Flowdock::Git.new(ref, before, after, :tags => ["git", "push"])
  31 +
  32 +Note that you can also define token as parameter allowing multiple Flows to be notified.
  33 +
  34 + Flowdock::Git.new(ref, before, after, :token => "flow-token")
  35 + Flowdock::Git.new(ref, before, after, :token => "another-flow")
  36 +
  37 +== Example data
  38 +
  39 +The hook uses {GitHub webhook}[http://help.github.com/post-receive-hooks/] format.
  40 +
  41 + payload {
  42 + "after": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
  43 + "before": "2a445d1d348d9d45217cb9c89c12b67d3767ce42",
  44 + "commits": [
  45 + {
  46 + "added": [],
  47 + "author": {
  48 + "email": "raine.virta@nodeta.fi",
  49 + "name": "Raine Virta"
  50 + },
  51 + "id": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
  52 + "message": "yeah!",
  53 + "modified": [
  54 + "TEST_FILE"
  55 + ],
  56 + "removed": [],
  57 + "timestamp": "2010-08-11T13:46:39+03:00"
  58 + }
  59 + ],
  60 + "ref": "refs\/heads\/master",
  61 + "ref_name": "master",
  62 + "repository": {
  63 + "name": "testrepo"
  64 + }
  65 + }
10 lib/flowdock/git.rb
@@ -19,6 +19,7 @@ def initialize(ref, from, to, options = {})
19 19 @token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
20 20 end
21 21
  22 + # Send git push notification to Flowdock
22 23 def post
23 24 uri = URI.parse("#{API_ENDPOINT}/#{([@token] + tags).join('+')}")
24 25 req = Net::HTTP::Post.new(uri.path)
@@ -33,10 +34,9 @@ def post
33 34 http.start { |http| http.request(req) }
34 35 end
35 36
36   - def payload
37   - Builder.new(repo, @ref, @from, @to).to_hash
38   - end
  37 + private
39 38
  39 + # Flowdock tags attached to the push notification
40 40 def tags
41 41 if @options[:tags]
42 42 @options[:tags]
@@ -47,7 +47,9 @@ def tags
47 47 end
48 48 end
49 49
50   - private
  50 + def payload
  51 + Builder.new(repo, @ref, @from, @to).to_hash
  52 + end
51 53
52 54 def repo
53 55 @repo ||= Grit::Repo.new(@options[:repo] || Dir.pwd)
1  lib/flowdock/git/builder.rb
@@ -2,6 +2,7 @@
2 2
3 3 module Flowdock
4 4 class Git
  5 + # Class used to build Git payload
5 6 class Builder
6 7 def initialize(repo, ref, before, after)
7 8 @repo = repo
6 spec/flowdock_git_spec.rb
@@ -27,7 +27,7 @@
27 27
28 28 describe "Tagging" do
29 29 it "reads tags from initializer parameter" do
30   - tags = Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token", :tags => ["foo", "bar"]).tags
  30 + tags = Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token", :tags => ["foo", "bar"]).send(:tags)
31 31 tags.should include("foo", "bar")
32 32 end
33 33
@@ -35,12 +35,12 @@
35 35 Grit::Config.stub!(:new).and_return({
36 36 "flowdock.tags" => "foo,bar"
37 37 })
38   - tags = Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token").tags
  38 + tags = Flowdock::Git.new("ref", "before", "after", :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("ref", "before", "after", :token => "flowdock-token", :tags => "foo%bar").tags.should include("foo%25bar")
  43 + Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token", :tags => "foo%bar").send(:tags).should include("foo%25bar")
44 44 end
45 45 end
46 46 end

0 comments on commit 662a0d9

Please sign in to comment.
Something went wrong with that request. Please try again.