gitlab-flowdock-git-hook-1.0.1/ 0000755 0001756 0001757 00000000000 12632607674 015356 5 ustar pravi pravi gitlab-flowdock-git-hook-1.0.1/spec/ 0000755 0001756 0001757 00000000000 12632607674 016310 5 ustar pravi pravi gitlab-flowdock-git-hook-1.0.1/spec/spec_helper.rb 0000644 0001756 0001757 00000000604 12632607674 021126 0 ustar pravi pravi $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'webmock/rspec'
require 'flowdock-git-hook'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
end
gitlab-flowdock-git-hook-1.0.1/spec/flowdock_git_spec.rb 0000644 0001756 0001757 00000007236 12632607674 022332 0 ustar pravi pravi require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Flowdock Git Hook" do
let(:before) { "611ef32e3eee84b61a7efd496bd71ae1af165823" }
let(:after) { "3a29fcd42ca69f40c8ed357052843d8e1e549013" }
let(:commits_in_range) { 8 }
let(:flowdock_token) { SecureRandom.hex }
let(:expected_message) {
{
event: "activity",
title: "3f3a5fd Bumped version",
thread: {
title: "branch master updated",
external_url: nil,
},
author: {
name: "Antti Pitkanen",
email: "antti@flowdock.com"
},
body: nil,
flow_token: flowdock_token
}
}
let!(:request) do
stub_request(:post, "https://api.flowdock.com/v1/messages")
end
it "raises error if git token is not defined" do
lambda {
Flowdock::Git.new "ref", "from", "to"
}.should raise_error(Flowdock::Git::TokenError)
end
it "can read token from git config" do
Grit::Config.stub!(:new).and_return({
"flowdock.token" => flowdock_token
})
lambda {
Flowdock::Git.new "ref", "from", "to"
}.should_not raise_error
end
it "builds payload" do
Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
expect(request.with(body: hash_including(expected_message))).to have_been_made
end
it "adds repo name to title if given" do
Grit::Config.stub!(:new).and_return(
"flowdock.repository-name" => "some repo"
)
Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
expect(request.with(body: hash_including(
thread: expected_message[:thread].merge(title: "some repo branch master updated")))
).to have_been_made.times(commits_in_range - 1) # da fuq. if you figure out why 139fdb4 does not generate a hit please do tell me
end
it "posts all transient branch updates to same thread" do
Grit::Config.stub!(:new).and_return(
"flowdock.permanent-references" => ""
)
Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
expect(request.with(body: hash_including(external_thread_id: "refs/heads/master"))
).to have_been_made.times(commits_in_range)
end
it "builds payload with repo url, diff url and commit urls" do
Grit::Config.stub!(:new).and_return({
"flowdock.token" => "flowdock-token",
"flowdock.repository-url" => "http://www.example.com",
"flowdock.diff-url-pattern" => "http://www.example.com/compare/%s...%s",
"flowdock.commit-url-pattern" => "http://www.example.com/commit/%s"
})
Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
expect(request.with(body: hash_including(expected_message.merge(
thread: expected_message[:thread].merge(external_url: "http://www.example.com"),
title: "3f3a5fd Bumped version"
)))
).to have_been_made
end
it "attaches tags from configuration" do
Grit::Config.stub!(:new).and_return({"flowdock.tags" => "git, push, foo%bar"})
Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
expect(request.with(body: hash_including(tags: ["git", "push", "foo%25bar"]))
).to have_been_made.times(7)
end
it "attaches tags from opts" do
Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token, tags: ["git", "push", "foo%bar"])
expect(request.with(body: hash_including(tags: ["git", "push", "foo%25bar"]))
).to have_been_made.times(7)
end
end
gitlab-flowdock-git-hook-1.0.1/LICENSE.txt 0000644 0001756 0001757 00000002041 12632607674 017176 0 ustar pravi pravi Copyright (c) 2011 Flowdock Ltd.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
gitlab-flowdock-git-hook-1.0.1/VERSION 0000644 0001756 0001757 00000000005 12632607674 016421 0 ustar pravi pravi 1.0.1 gitlab-flowdock-git-hook-1.0.1/.rspec 0000644 0001756 0001757 00000000010 12632607674 016462 0 ustar pravi pravi --color
gitlab-flowdock-git-hook-1.0.1/.travis.yml 0000644 0001756 0001757 00000000035 12632607674 017465 0 ustar pravi pravi rvm:
- 2.0
- 2.1
- 2.2
gitlab-flowdock-git-hook-1.0.1/post-receive 0000755 0001756 0001757 00000000226 12632607674 017711 0 ustar pravi pravi #!/usr/bin/env ruby
require 'rubygems'
require 'flowdock-git-hook'
before, after, ref = gets.split
Flowdock::Git.background_post(ref, before, after)
gitlab-flowdock-git-hook-1.0.1/gitlab-flowdock-git-hook.gemspec 0000644 0001756 0001757 00000005553 12632607674 023522 0 ustar pravi pravi # Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
# stub: gitlab-flowdock-git-hook 1.0.1 ruby lib
Gem::Specification.new do |s|
s.name = "gitlab-flowdock-git-hook"
s.version = "1.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Ville Lautanala", "Boyan Tabakov"]
s.date = "2015-08-13"
s.email = "blade@alslayer.net"
s.extra_rdoc_files = [
"LICENSE.txt",
"README.md"
]
s.files = [
".document",
".rspec",
".travis.yml",
"Gemfile",
"LICENSE.txt",
"README.md",
"Rakefile",
"VERSION",
"gitlab-flowdock-git-hook.gemspec",
"lib/flowdock-git-hook.rb",
"lib/flowdock/git.rb",
"lib/flowdock/git/builder.rb",
"post-receive",
"spec/flowdock_git_spec.rb",
"spec/spec_helper.rb"
]
s.homepage = "http://github.com/bladealslayer/flowdock-git-hook"
s.licenses = ["MIT"]
s.rubygems_version = "2.4.1"
s.summary = "Git Post-Receive hook for Flowdock. Gem requirements patched for use with Gitlab."
if s.respond_to? :specification_version then
s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q, [">= 2.4.1"])
s.add_runtime_dependency(%q, [">= 0"])
s.add_runtime_dependency(%q, ["~> 0.7"])
s.add_development_dependency(%q, [">= 0"])
s.add_development_dependency(%q, [">= 2.4.2"])
s.add_development_dependency(%q, ["~> 2.8"])
s.add_development_dependency(%q, ["~> 1.0"])
s.add_development_dependency(%q, ["~> 1.8.7"])
s.add_development_dependency(%q, [">= 1.6.4"])
s.add_development_dependency(%q, [">= 0"])
else
s.add_dependency(%q, [">= 2.4.1"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, ["~> 0.7"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, [">= 2.4.2"])
s.add_dependency(%q, ["~> 2.8"])
s.add_dependency(%q, ["~> 1.0"])
s.add_dependency(%q, ["~> 1.8.7"])
s.add_dependency(%q, [">= 1.6.4"])
s.add_dependency(%q, [">= 0"])
end
else
s.add_dependency(%q, [">= 2.4.1"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, ["~> 0.7"])
s.add_dependency(%q, [">= 0"])
s.add_dependency(%q, [">= 2.4.2"])
s.add_dependency(%q, ["~> 2.8"])
s.add_dependency(%q, ["~> 1.0"])
s.add_dependency(%q, ["~> 1.8.7"])
s.add_dependency(%q, [">= 1.6.4"])
s.add_dependency(%q, [">= 0"])
end
end
gitlab-flowdock-git-hook-1.0.1/.document 0000644 0001756 0001757 00000000066 12632607674 017177 0 ustar pravi pravi lib/**/*.rb
bin/*
-
features/**/*.feature
LICENSE.txt
gitlab-flowdock-git-hook-1.0.1/README.md 0000644 0001756 0001757 00000011213 12632607674 016633 0 ustar pravi pravi # Flowdock Git Hook
Git Post-Receive hook for [Flowdock](http://flowdock.com).
## Note
Version 1.0. supports only source flow tokens. 0.x versions use a deprecated API which will be removed soon.
## Installation
First, you need to install this gem. You need to have Ruby and Rubygems installed in your system.
$ gem install flowdock-git-hook
Then, download the post-receive hook file to the hooks directory and make it executable
$ wget -O hooks/post-receive https://raw.github.com/flowdock/flowdock-git-hook/master/post-receive
$ chmod +x hooks/post-receive
Set the source flow token given to you by the Flowdock git configuration service
$ git config flowdock.token
After this, you should get updates from your git repo every time you push to it.
## Configuration
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).
### Permanent references
By default each push to the `master` branch will generate a new thread containing just the commits that were pushed. Pushes to other branches or tags will be grouped to a single thread containing all the pushed commits. You can configure this behaviour by setting the `permanent-reference` git variable. The value of that configuration parameter should be a comma separated list of regular expressions.
For example to create new threads for each push to the `master` branch and any branch starting with `with-regex-` do this
$ git config flowdock.permanent-references "refs/heads/master, refs/heads/with-regex-.*"
### Repository name
The repository name displayed in the inbox message can be set with `repository-name`
$ git config flowdock.repository-name "my repo"
### Repository URL
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`:
$ git config flowdock.repository-url "http://example.com/mygitviewer/repo"
### Commit URLs
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`:
$ git config flowdock.commit-url-pattern "http://example.com/mygitviewer/commits/%s"
The `%s` will be replaced with the commit SHA.
### Diff URL
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`:
$ git config flowdock.diff-url-pattern "http://example.com/mygitviewer/compare/%s...%s"
## 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.background_post(ref, before, after, :tags => ["git", "push"])
Note that you can also define token as parameter allowing multiple Flows to be notified.
Flowdock::Git.background_post(ref, before, after, :token => "flow-token")
Flowdock::Git.background_post(ref, before, after, :token => "another-flow")
### Usage as a library
You can use the gem as a library from an application, without the need to set configuration parameters on the Git repository. You can pass the required parameters directly like so:
Flowdock::Git.post(ref, before, after, :token => "flow-token",
:repo => "/path/to/repo",
:repo_url => "http://example.com/mygitviewer/repo",
:commit_url => "http://example.com/mygitviewer/repo/commit/%s",
:diff_url => "http://example.com/mygitviewer/repo/compare/%s...%s")
## 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"
}
}
gitlab-flowdock-git-hook-1.0.1/Gemfile 0000644 0001756 0001757 00000000521 12632607674 016647 0 ustar pravi pravi source "http://rubygems.org"
gem "gitlab-grit", ">= 2.4.1"
gem "multi_json"
gem "flowdock", "~> 0.7"
group :development do
gem "byebug"
gem "rdoc", ">= 2.4.2"
gem "rspec", "~> 2.8"
gem "bundler", "~> 1.0"
gem "jeweler", "~> 1.8.7"
gem "webmock", ">= 1.6.4"
gem "jruby-openssl", :platforms => :jruby, :require => false
end
gitlab-flowdock-git-hook-1.0.1/metadata.yml 0000644 0001756 0001757 00000011426 12632607674 017665 0 ustar pravi pravi --- !ruby/object:Gem::Specification
name: gitlab-flowdock-git-hook
version: !ruby/object:Gem::Version
version: 1.0.1
platform: ruby
authors:
- Ville Lautanala
- Boyan Tabakov
autorequire:
bindir: bin
cert_chain: []
date: 2015-08-13 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: gitlab-grit
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 2.4.1
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 2.4.1
- !ruby/object:Gem::Dependency
name: multi_json
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: flowdock
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '0.7'
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '0.7'
- !ruby/object:Gem::Dependency
name: byebug
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: rdoc
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 2.4.2
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 2.4.2
- !ruby/object:Gem::Dependency
name: rspec
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '2.8'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '2.8'
- !ruby/object:Gem::Dependency
name: bundler
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
- !ruby/object:Gem::Dependency
name: jeweler
requirement: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: 1.8.7
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ~>
- !ruby/object:Gem::Version
version: 1.8.7
- !ruby/object:Gem::Dependency
name: webmock
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 1.6.4
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 1.6.4
- !ruby/object:Gem::Dependency
name: jruby-openssl
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
description:
email: blade@alslayer.net
executables: []
extensions: []
extra_rdoc_files:
- LICENSE.txt
- README.md
files:
- .document
- .rspec
- .travis.yml
- Gemfile
- LICENSE.txt
- README.md
- Rakefile
- VERSION
- gitlab-flowdock-git-hook.gemspec
- lib/flowdock-git-hook.rb
- lib/flowdock/git.rb
- lib/flowdock/git/builder.rb
- post-receive
- spec/flowdock_git_spec.rb
- spec/spec_helper.rb
homepage: http://github.com/bladealslayer/flowdock-git-hook
licenses:
- MIT
metadata: {}
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project:
rubygems_version: 2.0.14
signing_key:
specification_version: 4
summary: Git Post-Receive hook for Flowdock. Gem requirements patched for use with
Gitlab.
test_files: []
gitlab-flowdock-git-hook-1.0.1/lib/ 0000755 0001756 0001757 00000000000 12632607674 016124 5 ustar pravi pravi gitlab-flowdock-git-hook-1.0.1/lib/flowdock-git-hook.rb 0000644 0001756 0001757 00000000027 12632607674 021777 0 ustar pravi pravi require 'flowdock/git'
gitlab-flowdock-git-hook-1.0.1/lib/flowdock/ 0000755 0001756 0001757 00000000000 12632607674 017734 5 ustar pravi pravi gitlab-flowdock-git-hook-1.0.1/lib/flowdock/git/ 0000755 0001756 0001757 00000000000 12632607674 020517 5 ustar pravi pravi gitlab-flowdock-git-hook-1.0.1/lib/flowdock/git/builder.rb 0000644 0001756 0001757 00000007046 12632607674 022501 0 ustar pravi pravi require "grit"
require 'cgi'
require "securerandom"
module Flowdock
class Git
class Commit
def initialize(external_thread_id, thread, tags, commit)
@commit = commit
@external_thread_id = external_thread_id
@thread = thread
@tags = tags
end
def to_hash
hash = {
external_thread_id: @external_thread_id,
event: "activity",
author: {
name: @commit[:author][:name],
email: @commit[:author][:email]
},
title: title,
thread: @thread,
body: body
}
hash[:tags] = @tags if @tags
encode(hash)
end
private
def encode(hash)
return hash unless "".respond_to? :encode
encode_as_utf8(hash)
end
# This only works on Ruby 1.9
def encode_as_utf8(obj)
if obj.is_a? Hash
obj.each_pair do |key, val|
encode_as_utf8(val)
end
elsif obj.is_a?(Array)
obj.each do |val|
encode_as_utf8(val)
end
elsif obj.is_a?(String) && obj.encoding != Encoding::UTF_8
if !obj.force_encoding("UTF-8").valid_encoding?
obj.force_encoding("ISO-8859-1").encode!(Encoding::UTF_8, :invalid => :replace, :undef => :replace)
end
end
end
def body
content = @commit[:message][first_line.size..-1]
content.strip! if content
"
#{content}
" unless content.empty?
end
def first_line
@first_line ||= (@commit[:message].split("\n")[0] || @commit[:message])
end
def title
commit_id = @commit[:id][0, 7]
if @commit[:url]
"#{commit_id} #{message_title}"
else
"#{commit_id} #{message_title}"
end
end
def message_title
CGI.escape_html(first_line.strip)
end
end
# Class used to build Git payload
class Builder
def initialize(opts)
@repo = opts[:repo]
@ref = opts[:ref]
@before = opts[:before]
@after = opts[:after]
@opts = opts
end
def commits
@repo.commits_between(@before, @after).map do |commit|
{
url: if @opts[:commit_url] then @opts[:commit_url] % [commit.sha] end,
id: commit.sha,
message: commit.message,
author: {
name: commit.author.name,
email: commit.author.email
}
}
end
end
def ref_name
@ref.to_s.sub(/\Arefs\/(heads|tags)\//, '')
end
def to_hashes
commits.map do |commit|
Commit.new(external_thread_id, thread, @opts[:tags], commit).to_hash
end
end
private
def thread
@thread ||= {
title: thread_title,
external_url: @opts[:repo_url]
}
end
def permanent?
@permanent ||= @opts[:permanent_refs].select do |regex|
regex.match(@ref)
end.size > 0
end
def thread_title
action = if permanent?
"updated"
end
type = if @ref.match(%r(^refs/heads/))
"branch"
else
"tag"
end
[@opts[:repo_name], type, ref_name, action].compact.join(" ")
end
def external_thread_id
@external_thread_id ||=
if permanent?
SecureRandom.hex
else
@ref
end
end
end
end
end
gitlab-flowdock-git-hook-1.0.1/lib/flowdock/git.rb 0000644 0001756 0001757 00000005274 12632607674 021054 0 ustar pravi pravi require "multi_json"
require "cgi"
require "flowdock"
require "flowdock/git/builder"
module Flowdock
class Git
class TokenError < StandardError; end
class << self
def post(ref, from, to, options = {})
Git.new(ref, from, to, options).post
end
def background_post(ref, from, to, options = {})
Git.new(ref, from, to, options).background_post
end
end
def initialize(ref, from, to, options = {})
@ref = ref
@from = from
@to = to
@options = options
@token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
@commit_url = options[:commit_url] || config["flowdock.commit-url-pattern"] || nil
@diff_url = options[:diff_url] || config["flowdock.diff-url-pattern"] || nil
@repo_url = options[:repo_url] || config["flowdock.repository-url"] || nil
@repo_name = options[:repo_name] || config["flowdock.repository-name"] || nil
@permanent_refs = options[:permanent_refs] ||
(config["flowdock.permanent-references"] || "refs/heads/master")
.split(",")
.map(&:strip)
.map {|exp| Regexp.new(exp) }
end
# Send git push notification to Flowdock
def post
messages.each do |message|
Flowdock::Client.new(flow_token: @token).post_to_thread(message)
end
end
# Create and post notification in background process. Avoid blocking the push notification.
def background_post
pid = Process.fork
if pid.nil?
Grit::Git.with_timeout(600) do
post
end
else
Process.detach(pid) # Parent
end
end
def repo
@repo ||= Grit::Repo.new(
@options[:repo] || Dir.pwd,
is_bare: @options[:is_bare] || false
)
end
private
def messages
Git::Builder.new(repo: @repo,
ref: @ref,
before: @from,
after: @to,
commit_url: @commit_url,
branch_url: @branch_url,
diff_url: @diff_url,
repo_url: @repo_url,
repo_name: @repo_name,
permanent_refs: @permanent_refs,
tags: tags
).to_hashes
end
# Flowdock tags attached to the push notification
def tags
if @options[:tags]
@options[:tags]
else
config["flowdock.tags"].to_s.split(",").map(&:strip)
end.map do |t|
CGI.escape(t)
end
end
def config
@config ||= Grit::Config.new(repo)
end
end
end
gitlab-flowdock-git-hook-1.0.1/Rakefile 0000644 0001756 0001757 00000002174 12632607674 017027 0 ustar pravi pravi # encoding: utf-8
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "flowdock-git-hook"
gem.homepage = "http://github.com/flowdock/flowdock-git-hook"
gem.license = "MIT"
gem.summary = %Q{Git Post-Receive hook for Flowdock}
gem.email = "lautis@gmail.com"
gem.authors = ["Ville Lautanala"]
# dependencies defined in Gemfile
end
Jeweler::RubygemsDotOrgTasks.new
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
task :default => :spec
require 'rdoc/task'
RDoc::Task.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "flowdock #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end