Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Jun 21, 2011
1 parent 8bf1afa commit 662a0d9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
70 changes: 58 additions & 12 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,19 +1,65 @@
= Flowdock Git Hook

Git Post-Receive hook for Flowdock
Git Post-Receive hook for Flowdock[http://flowdock.com]

== Contributing to flowdock-git-hook
== Installation

* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* 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.
First, you need to install this gem. You need to have Ruby 1.8.6 and Rubygems installed in your system.

== Copyright
gem install flowdock-git-hook

Copyright (c) 2011 Ville Lautanala. See LICENSE.txt for
further details.
Then, download the post-receive hook file to the hooks directory and make it executable

curl -o hooks/post-receive http://github.com/flowdock/flowdock-git-hook/raw/master/post-receive
chmod +x hooks/post-receive

Configure your Flow API tokens to git configuration

git config flowdock.token <Flow API token>

After this, you should get updates from your git repo every time you push to it.

== Advanced usage

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:

git config flowdock.tags git,push

For programmatic control over tagging, you can change how the hook is called in post-receive hook file.

Flowdock::Git.new(ref, before, after, :tags => ["git", "push"])

Note that you can also define token as parameter allowing multiple Flows to be notified.

Flowdock::Git.new(ref, before, after, :token => "flow-token")
Flowdock::Git.new(ref, before, after, :token => "another-flow")

== Example data

The hook uses {GitHub webhook}[http://help.github.com/post-receive-hooks/] format.

payload {
"after": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
"before": "2a445d1d348d9d45217cb9c89c12b67d3767ce42",
"commits": [
{
"added": [],
"author": {
"email": "raine.virta@nodeta.fi",
"name": "Raine Virta"
},
"id": "122b95a8808ea0cf708fb43b400a377c25c35d7f",
"message": "yeah!",
"modified": [
"TEST_FILE"
],
"removed": [],
"timestamp": "2010-08-11T13:46:39+03:00"
}
],
"ref": "refs\/heads\/master",
"ref_name": "master",
"repository": {
"name": "testrepo"
}
}
10 changes: 6 additions & 4 deletions lib/flowdock/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(ref, from, to, options = {})
@token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
end

# Send git push notification to Flowdock
def post
uri = URI.parse("#{API_ENDPOINT}/#{([@token] + tags).join('+')}")
req = Net::HTTP::Post.new(uri.path)
Expand All @@ -33,10 +34,9 @@ def post
http.start { |http| http.request(req) }
end

def payload
Builder.new(repo, @ref, @from, @to).to_hash
end
private

# Flowdock tags attached to the push notification
def tags
if @options[:tags]
@options[:tags]
Expand All @@ -47,7 +47,9 @@ def tags
end
end

private
def payload
Builder.new(repo, @ref, @from, @to).to_hash
end

def repo
@repo ||= Grit::Repo.new(@options[:repo] || Dir.pwd)
Expand Down
1 change: 1 addition & 0 deletions lib/flowdock/git/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Flowdock
class Git
# Class used to build Git payload
class Builder
def initialize(repo, ref, before, after)
@repo = repo
Expand Down
6 changes: 3 additions & 3 deletions spec/flowdock_git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@

describe "Tagging" do
it "reads tags from initializer parameter" do
tags = Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token", :tags => ["foo", "bar"]).tags
tags = Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token", :tags => ["foo", "bar"]).send(:tags)
tags.should include("foo", "bar")
end

it "reads tags from gitconfig as fallback" do
Grit::Config.stub!(:new).and_return({
"flowdock.tags" => "foo,bar"
})
tags = Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token").tags
tags = Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token").send(:tags)
tags.should include("foo", "bar")
end

it "encodes tags suitable for URI" do
Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token", :tags => "foo%bar").tags.should include("foo%25bar")
Flowdock::Git.new("ref", "before", "after", :token => "flowdock-token", :tags => "foo%bar").send(:tags).should include("foo%25bar")
end
end
end
Expand Down

0 comments on commit 662a0d9

Please sign in to comment.