flowdock-git-hook 0.4.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2ZkYjA3YTNkYTY3YjdmNTdmM2M0YjlhZjA0YmE2MjllNjNkNGQ4MQ==
5
- data.tar.gz: !binary |-
6
- MGE0YjMzZTBjNDM2YzMzOGU5MDRkN2QyYjlmOGNhYzlkNzcwNzJlNg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MDljNGM1ZGUwMzc4NzFlNTNmNTM3MjEyYTNmYzIzZDIzZWQxYjRhNzllYzUy
10
- MWJhYWU1MGI2MzkzYzFhZmQxNTM3YjZlYzQyMjgwMmFiYzcwMzg0MTgxZTgw
11
- YTEyY2ZjOTVmZGVkMzU3ODI2OGQxM2QxNWU3ZDIxOTA2ZGNkZDg=
12
- data.tar.gz: !binary |-
13
- ODM0OGY3NDZjODVhZTdiMjJhYjJiYjI5ZWRkMmJjZTY0NzdjNDk4NWNiMzdk
14
- NmQ3Y2EzZmFhNjcyNWFhODNiNmE4ZWJjYzhmNTBmOGNmMGQyMWU5ZjI1YjQw
15
- OWYxMDU5ZjgzZmExYmViYzY1NDE1YTEwOTcwYzI5NzdjNzFlODg=
2
+ SHA1:
3
+ metadata.gz: db9e59fadcdfb7e5c9abdc0833bc16674be85612
4
+ data.tar.gz: 888ac972d310c012029d3aad21942f5f5ebd7eed
5
+ SHA512:
6
+ metadata.gz: e3d7c287e9b62c3a2b7518cf7f04c750e241ac7671f1d02d79f2c13cdae3639f41ff70b8eea87a4e4df1ecf8c0db63a28794f987c8607d3129aae67368bb9389
7
+ data.tar.gz: 6aa623fb9d787a681221747cd627fd768d82abd3f90fba37c28d38fb998af8acb0ea91f929b8d284df6be8e7d2c7369b2bafd8cd1cf0f31dcce6b7846e5d7e64
@@ -1,3 +1,4 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.3
2
+ - 2.0
3
+ - 2.1
4
+ - 2.2
data/Gemfile CHANGED
@@ -2,8 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "grit", ">= 2.4.1"
4
4
  gem "multi_json"
5
-
5
+ gem "flowdock", "~> 0.7"
6
6
  group :development do
7
+ gem "byebug"
7
8
  gem "rdoc", ">= 2.4.2"
8
9
  gem "rspec", "~> 2.8"
9
10
  gem "bundler", "~> 1.0"
data/README.md CHANGED
@@ -4,7 +4,7 @@ Git Post-Receive hook for [Flowdock](http://flowdock.com).
4
4
 
5
5
  ## Installation
6
6
 
7
- First, you need to install this gem. You need to have Ruby 1.8.6 and Rubygems installed in your system.
7
+ First, you need to install this gem. You need to have Ruby and Rubygems installed in your system.
8
8
 
9
9
  $ gem install flowdock-git-hook
10
10
 
@@ -13,9 +13,9 @@ Then, download the post-receive hook file to the hooks directory and make it exe
13
13
  $ wget -O hooks/post-receive https://raw.github.com/flowdock/flowdock-git-hook/master/post-receive
14
14
  $ chmod +x hooks/post-receive
15
15
 
16
- Configure your Flow API tokens to git configuration
16
+ Set the source flow token given to you by the Flowdock git configuration service
17
17
 
18
- $ git config flowdock.token <Flow API token>
18
+ $ git config flowdock.token <source flow token>
19
19
 
20
20
  After this, you should get updates from your git repo every time you push to it.
21
21
 
@@ -23,6 +23,22 @@ After this, you should get updates from your git repo every time you push to it.
23
23
 
24
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
25
 
26
+ ### Permanent references
27
+
28
+ 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.
29
+
30
+ For example to create new threads for each push to the `master` branch and any branch starting with `with-regex-` do this
31
+
32
+ $ git config flowdock.permanent-references "refs/heads/master, refs/heads/with-regex-.*"
33
+
34
+
35
+ ### Repository name
36
+
37
+ The repository name displayed in the inbox message can be set with `repository-name`
38
+
39
+ $ git config flowdock.repository-name "my repo"
40
+
41
+
26
42
  ### Repository URL
27
43
 
28
44
  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`:
@@ -41,7 +57,7 @@ The `%s` will be replaced with the commit SHA.
41
57
 
42
58
  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
59
 
44
- $ gitconfig flowdock.diff-url-pattern "http://example.com/mygitviewer/compare/%s...%s"
60
+ $ git config flowdock.diff-url-pattern "http://example.com/mygitviewer/compare/%s...%s"
45
61
 
46
62
  ## Advanced usage
47
63
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 1.0.0
@@ -2,14 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: flowdock-git-hook 1.0.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "flowdock-git-hook"
8
- s.version = "0.4.2"
9
+ s.version = "1.0.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Ville Lautanala"]
12
- s.date = "2013-09-26"
14
+ s.date = "2015-07-22"
13
15
  s.email = "lautis@gmail.com"
14
16
  s.extra_rdoc_files = [
15
17
  "LICENSE.txt",
@@ -29,14 +31,12 @@ Gem::Specification.new do |s|
29
31
  "lib/flowdock/git.rb",
30
32
  "lib/flowdock/git/builder.rb",
31
33
  "post-receive",
32
- "spec/builder_spec.rb",
33
34
  "spec/flowdock_git_spec.rb",
34
35
  "spec/spec_helper.rb"
35
36
  ]
36
37
  s.homepage = "http://github.com/flowdock/flowdock-git-hook"
37
38
  s.licenses = ["MIT"]
38
- s.require_paths = ["lib"]
39
- s.rubygems_version = "2.0.5"
39
+ s.rubygems_version = "2.4.1"
40
40
  s.summary = "Git Post-Receive hook for Flowdock"
41
41
 
42
42
  if s.respond_to? :specification_version then
@@ -45,6 +45,8 @@ Gem::Specification.new do |s|
45
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
46
  s.add_runtime_dependency(%q<grit>, [">= 2.4.1"])
47
47
  s.add_runtime_dependency(%q<multi_json>, [">= 0"])
48
+ s.add_runtime_dependency(%q<flowdock>, ["~> 0.7"])
49
+ s.add_development_dependency(%q<byebug>, [">= 0"])
48
50
  s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
49
51
  s.add_development_dependency(%q<rspec>, ["~> 2.8"])
50
52
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
@@ -54,6 +56,8 @@ Gem::Specification.new do |s|
54
56
  else
55
57
  s.add_dependency(%q<grit>, [">= 2.4.1"])
56
58
  s.add_dependency(%q<multi_json>, [">= 0"])
59
+ s.add_dependency(%q<flowdock>, ["~> 0.7"])
60
+ s.add_dependency(%q<byebug>, [">= 0"])
57
61
  s.add_dependency(%q<rdoc>, [">= 2.4.2"])
58
62
  s.add_dependency(%q<rspec>, ["~> 2.8"])
59
63
  s.add_dependency(%q<bundler>, ["~> 1.0"])
@@ -64,6 +68,8 @@ Gem::Specification.new do |s|
64
68
  else
65
69
  s.add_dependency(%q<grit>, [">= 2.4.1"])
66
70
  s.add_dependency(%q<multi_json>, [">= 0"])
71
+ s.add_dependency(%q<flowdock>, ["~> 0.7"])
72
+ s.add_dependency(%q<byebug>, [">= 0"])
67
73
  s.add_dependency(%q<rdoc>, [">= 2.4.2"])
68
74
  s.add_dependency(%q<rspec>, ["~> 2.8"])
69
75
  s.add_dependency(%q<bundler>, ["~> 1.0"])
@@ -1,69 +1,52 @@
1
1
  require "multi_json"
2
- require "net/https"
3
2
  require "cgi"
4
-
3
+ require "flowdock"
5
4
  require "flowdock/git/builder"
6
5
 
7
6
  module Flowdock
8
7
  class Git
9
8
  class TokenError < StandardError; end
10
- API_ENDPOINT = "https://api.flowdock.com/v1/git"
11
9
 
12
10
  class << self
13
11
  def post(ref, from, to, options = {})
14
- git = Git.new(options)
15
- git.post(Git::Builder.new(git.repo, ref, from, to))
12
+ Git.new(ref, from, to, options).post
16
13
  end
17
14
 
18
15
  def background_post(ref, from, to, options = {})
19
- git = Git.new(options)
20
- git.background_post(Git::Builder.new(git.repo, ref, from, to))
16
+ Git.new(ref, from, to, options).background_post
21
17
  end
22
18
  end
23
19
 
24
- def initialize(options = {})
20
+ def initialize(ref, from, to, options = {})
21
+ @ref = ref
22
+ @from = from
23
+ @to = to
25
24
  @options = options
26
25
  @token = options[:token] || config["flowdock.token"] || raise(TokenError.new("Flowdock API token not found"))
27
26
  @commit_url = options[:commit_url] || config["flowdock.commit-url-pattern"] || nil
28
27
  @diff_url = options[:diff_url] || config["flowdock.diff-url-pattern"] || nil
29
28
  @repo_url = options[:repo_url] || config["flowdock.repository-url"] || nil
29
+ @repo_name = options[:repo_name] || config["flowdock.repository-name"] || nil
30
+ @permanent_refs = options[:permanent_refs] ||
31
+ (config["flowdock.permanent-references"] || "refs/heads/master")
32
+ .split(",")
33
+ .map(&:strip)
34
+ .map {|exp| Regexp.new(exp) }
30
35
  end
31
36
 
32
37
  # Send git push notification to Flowdock
33
- def post(data)
34
- uri = URI.parse("#{API_ENDPOINT}/#{([@token] + tags).join('+')}")
35
- req = Net::HTTP::Post.new(uri.path)
36
-
37
- payload_hash = data.to_hash
38
- if @repo_url
39
- payload_hash[:repository][:url] = @repo_url
40
- end
41
- if @commit_url
42
- payload_hash[:commits].each do |commit|
43
- commit[:url] = @commit_url % commit[:id]
44
- end
45
- end
46
- if @diff_url
47
- payload_hash[:compare] = @diff_url % [payload_hash[:before], payload_hash[:after]]
38
+ def post
39
+ messages.each do |message|
40
+ Flowdock::Client.new(flow_token: @token).post_to_thread(message)
48
41
  end
49
-
50
- req.set_form_data(:payload => MultiJson.encode(payload_hash))
51
- http = Net::HTTP.new(uri.host, uri.port)
52
-
53
- if uri.scheme == 'https'
54
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
55
- http.use_ssl = true
56
- end
57
-
58
- http.start { |http| http.request(req) }
59
42
  end
60
43
 
61
44
  # Create and post notification in background process. Avoid blocking the push notification.
62
- def background_post(data)
45
+ def background_post
63
46
  pid = Process.fork
64
47
  if pid.nil?
65
48
  Grit::Git.with_timeout(600) do
66
- post(data) # Child
49
+ post
67
50
  end
68
51
  else
69
52
  Process.detach(pid) # Parent
@@ -76,12 +59,27 @@ module Flowdock
76
59
 
77
60
  private
78
61
 
62
+ def messages
63
+ Git::Builder.new(repo: @repo,
64
+ ref: @ref,
65
+ before: @from,
66
+ after: @to,
67
+ commit_url: @commit_url,
68
+ branch_url: @branch_url,
69
+ diff_url: @diff_url,
70
+ repo_url: @repo_url,
71
+ repo_name: @repo_name,
72
+ permanent_refs: @permanent_refs,
73
+ tags: tags
74
+ ).to_hashes
75
+ end
76
+
79
77
  # Flowdock tags attached to the push notification
80
78
  def tags
81
79
  if @options[:tags]
82
80
  @options[:tags]
83
81
  else
84
- config["flowdock.tags"].to_s.split(",")
82
+ config["flowdock.tags"].to_s.split(",").map(&:strip)
85
83
  end.map do |t|
86
84
  CGI.escape(t)
87
85
  end
@@ -1,60 +1,38 @@
1
1
  require "grit"
2
+ require 'cgi'
3
+ require "securerandom"
2
4
 
3
5
  module Flowdock
4
6
  class Git
5
- # Class used to build Git payload
6
- class Builder
7
- def initialize(repo, ref, before, after)
8
- @repo = repo
9
- @ref = ref
10
- @before = before
11
- @after = after
12
- end
13
-
14
- def commits
15
- @repo.commits_between(@before, @after).map do |commit|
16
- {
17
- :id => commit.sha,
18
- :message => commit.message,
19
- :timestamp => commit.authored_date.iso8601,
20
- :author => {
21
- :name => commit.author.name,
22
- :email => commit.author.email
23
- },
24
- :removed => filter(commit.diffs) { |d| d.deleted_file },
25
- :added => filter(commit.diffs) { |d| d.new_file },
26
- :modified => filter(commit.diffs) { |d| !d.deleted_file && !d.new_file }
27
- }
28
- end
29
- end
30
-
31
- def ref_name
32
- @ref.to_s.sub(/\Arefs\/(heads|tags)\//, '')
7
+ class Commit
8
+ def initialize(external_thread_id, thread, tags, commit)
9
+ @commit = commit
10
+ @external_thread_id = external_thread_id
11
+ @thread = thread
12
+ @tags = tags
33
13
  end
34
14
 
35
15
  def to_hash
36
- encode({
37
- :before => @before,
38
- :after => @after,
39
- :ref => @ref,
40
- :commits => commits,
41
- :ref_name => @ref.to_s.sub(/\Arefs\/(heads|tags)\//, ''),
42
- :repository => {
43
- :name => File.basename(@repo.path).sub(/\.git$/,'')
44
- }
45
- }).merge(if @before == "0000000000000000000000000000000000000000"
46
- {:created => true}
47
- elsif @after == "0000000000000000000000000000000000000000"
48
- {:deleted => true}
49
- else
50
- {}
51
- end)
16
+ hash = {
17
+ external_thread_id: @external_thread_id,
18
+ event: "activity",
19
+ author: {
20
+ name: @commit[:author][:name],
21
+ email: @commit[:author][:email]
22
+ },
23
+ title: title,
24
+ thread: @thread,
25
+ body: body
26
+ }
27
+ hash[:tags] = @tags if @tags
28
+ encode(hash)
52
29
  end
53
30
 
54
31
  private
55
32
 
56
- def filter(diffs)
57
- diffs.select { |e| yield e }.map { |diff| diff.b_path }
33
+ def encode(hash)
34
+ return hash unless "".respond_to? :encode
35
+ encode_as_utf8(hash)
58
36
  end
59
37
 
60
38
  # This only works on Ruby 1.9
@@ -72,12 +50,100 @@ module Flowdock
72
50
  obj.force_encoding("ISO-8859-1").encode!(Encoding::UTF_8, :invalid => :replace, :undef => :replace)
73
51
  end
74
52
  end
75
- obj
76
53
  end
77
54
 
78
- def encode(hash)
79
- return hash unless "".respond_to? :encode
80
- encode_as_utf8(hash)
55
+ def body
56
+ content = @commit[:message][first_line.size..-1]
57
+ content.strip! if content
58
+ "<pre>#{content}</pre>" unless content.empty?
59
+ end
60
+
61
+ def first_line
62
+ @first_line ||= (@commit[:message].split("\n")[0] || @commit[:message])
63
+ end
64
+
65
+ def title
66
+ commit_id = @commit[:id][0, 7]
67
+ if @commit[:url]
68
+ "<a href=\"#{@commit[:url]}\">#{commit_id}</a> #{message_title}"
69
+ else
70
+ "#{commit_id} #{message_title}"
71
+ end
72
+ end
73
+
74
+ def message_title
75
+ CGI.escape_html(first_line.strip)
76
+ end
77
+ end
78
+
79
+ # Class used to build Git payload
80
+ class Builder
81
+ def initialize(opts)
82
+ @repo = opts[:repo]
83
+ @ref = opts[:ref]
84
+ @before = opts[:before]
85
+ @after = opts[:after]
86
+ @opts = opts
87
+ end
88
+
89
+ def commits
90
+ @repo.commits_between(@before, @after).map do |commit|
91
+ {
92
+ url: if @opts[:commit_url] then @opts[:commit_url] % [commit.sha] end,
93
+ id: commit.sha,
94
+ message: commit.message,
95
+ author: {
96
+ name: commit.author.name,
97
+ email: commit.author.email
98
+ }
99
+ }
100
+ end
101
+ end
102
+
103
+ def ref_name
104
+ @ref.to_s.sub(/\Arefs\/(heads|tags)\//, '')
105
+ end
106
+
107
+ def to_hashes
108
+ commits.map do |commit|
109
+ Commit.new(external_thread_id, thread, @opts[:tags], commit).to_hash
110
+ end
111
+ end
112
+
113
+ private
114
+
115
+ def thread
116
+ @thread ||= {
117
+ title: thread_title,
118
+ external_url: @opts[:repo_url]
119
+ }
120
+ end
121
+
122
+ def permanent?
123
+ @permanent ||= @opts[:permanent_refs].select do |regex|
124
+ regex.match(@ref)
125
+ end.size > 0
126
+ end
127
+
128
+ def thread_title
129
+ action = if permanent?
130
+ "updated"
131
+ end
132
+ type = if @ref.match(%r(^refs/heads/))
133
+ "branch"
134
+ else
135
+ "tag"
136
+ end
137
+ [@opts[:repo_name], type, ref_name, action].compact.join(" ")
138
+ end
139
+
140
+ def external_thread_id
141
+ @external_thread_id ||=
142
+ if permanent?
143
+ SecureRandom.hex
144
+ else
145
+ @ref
146
+ end
81
147
  end
82
148
  end
83
149
  end
@@ -1,36 +1,69 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Flowdock Git Hook" do
4
+ let(:before) { "611ef32e3eee84b61a7efd496bd71ae1af165823" }
5
+ let(:after) { "3a29fcd42ca69f40c8ed357052843d8e1e549013" }
6
+ let(:commits_in_range) { 8 }
7
+ let(:flowdock_token) { SecureRandom.hex }
8
+ let(:expected_message) {
9
+ {
10
+ event: "activity",
11
+ title: "3f3a5fd Bumped version",
12
+ thread: {
13
+ title: "branch master updated",
14
+ external_url: nil,
15
+ },
16
+ author: {
17
+ name: "Antti Pitkanen",
18
+ email: "antti@flowdock.com"
19
+ },
20
+ body: nil,
21
+ flow_token: flowdock_token
22
+ }
23
+ }
24
+
25
+ let!(:request) do
26
+ stub_request(:post, "https://api.flowdock.com/v1/messages")
27
+ end
28
+
4
29
  it "raises error if git token is not defined" do
5
30
  lambda {
6
- Flowdock::Git.new
31
+ Flowdock::Git.new "ref", "from", "to"
7
32
  }.should raise_error(Flowdock::Git::TokenError)
8
33
  end
9
34
 
10
35
  it "can read token from git config" do
11
36
  Grit::Config.stub!(:new).and_return({
12
- "flowdock.token" => "flowdock-token"
37
+ "flowdock.token" => flowdock_token
13
38
  })
14
39
 
15
40
  lambda {
16
- Flowdock::Git.new
41
+ Flowdock::Git.new "ref", "from", "to"
17
42
  }.should_not raise_error
18
43
  end
19
44
 
20
- it "encodes content as UTF-8" do
21
- @repo = Grit::Repo.new(".")
22
- @before = "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51"
23
- @after = "a66d3ce668ae6f2a42d54d811962724200d5b32b"
24
- @repo.stub!(:path).and_return("/foo/bar/flowdock-git-hook/.git")
25
- @hash = Flowdock::Git::Builder.new(@repo, "refs/heads/master", @before, @after).to_hash
45
+ it "builds payload" do
46
+ Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
47
+ expect(request.with(body: hash_including(expected_message))).to have_been_made
26
48
  end
27
49
 
28
- it "builds payload" do
29
- stub_request(:post, "https://api.flowdock.com/v1/git/flowdock-token")
30
- Flowdock::Git.post("refs/heads/master", "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51", "a1a94ba4bfa5f855676066861604b8edae1a20f5", :token => "flowdock-token")
31
- a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token").with { |req|
32
- req.body.match(/7e32af569ba794b0b1c5e4c38fef1d4e2e56be51/)
33
- }.should have_been_made
50
+ it "adds repo name to title if given" do
51
+ Grit::Config.stub!(:new).and_return(
52
+ "flowdock.repository-name" => "some repo"
53
+ )
54
+ Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
55
+ expect(request.with(body: hash_including(
56
+ thread: expected_message[:thread].merge(title: "some repo branch master updated")))
57
+ ).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
58
+ end
59
+
60
+ it "posts all transient branch updates to same thread" do
61
+ Grit::Config.stub!(:new).and_return(
62
+ "flowdock.permanent-references" => ""
63
+ )
64
+ Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
65
+ expect(request.with(body: hash_including(external_thread_id: "refs/heads/master"))
66
+ ).to have_been_made.times(commits_in_range)
34
67
  end
35
68
 
36
69
  it "builds payload with repo url, diff url and commit urls" do
@@ -40,47 +73,24 @@ describe "Flowdock Git Hook" do
40
73
  "flowdock.diff-url-pattern" => "http://www.example.com/compare/%s...%s",
41
74
  "flowdock.commit-url-pattern" => "http://www.example.com/commit/%s"
42
75
  })
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
-
52
- describe "Tagging" do
53
- it "reads tags from initializer parameter" do
54
- tags = Flowdock::Git.new(:token => "flowdock-token", :tags => ["foo", "bar"]).send(:tags)
55
- tags.should include("foo", "bar")
56
- end
57
-
58
- it "reads tags from gitconfig as fallback" do
59
- Grit::Config.stub!(:new).and_return({
60
- "flowdock.tags" => "foo,bar"
61
- })
62
- tags = Flowdock::Git.new(:token => "flowdock-token").send(:tags)
63
- tags.should include("foo", "bar")
64
- end
65
-
66
- it "encodes tags suitable for URI" do
67
- Flowdock::Git.new(:token => "flowdock-token", :tags => ["foo%bar"]).send(:tags).should include("foo%25bar")
68
- end
69
- end
70
- end
71
-
72
- describe "Flowdock Git Hook", "HTTP Post" do
73
- before :each do
74
- stub_request(:post, "https://api.flowdock.com/v1/git/flowdock-token+foo+bar")
75
- Flowdock::Git.post("origin/refs/master", "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51", "a1a94ba4bfa5f855676066861604b8edae1a20f5", :token => "flowdock-token", :tags => ["foo", "bar"])
76
+ Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
77
+ expect(request.with(body: hash_including(expected_message.merge(
78
+ thread: expected_message[:thread].merge(external_url: "http://www.example.com"),
79
+ title: "<a href=\"http://www.example.com/commit/3f3a5fd37f53970f71adec08c5376ae003ba22a3\">3f3a5fd</a> Bumped version"
80
+ )))
81
+ ).to have_been_made
76
82
  end
77
83
 
78
- it "posts to api.flowdock.com" do
79
- a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token+foo+bar").should have_been_made
84
+ it "attaches tags from configuration" do
85
+ Grit::Config.stub!(:new).and_return({"flowdock.tags" => "git, push, foo%bar"})
86
+ Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token)
87
+ expect(request.with(body: hash_including(tags: ["git", "push", "foo%25bar"]))
88
+ ).to have_been_made.times(7)
80
89
  end
81
90
 
82
- it "sends payload encoded as JSON" do
83
- payload = MultiJson.encode(Flowdock::Git::Builder.new(Grit::Repo.new("."), "origin/refs/master", "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51", "a1a94ba4bfa5f855676066861604b8edae1a20f5").to_hash)
84
- a_request(:post, "https://api.flowdock.com/v1/git/flowdock-token+foo+bar").with(:body => {:payload => payload}).should have_been_made
91
+ it "attaches tags from opts" do
92
+ Flowdock::Git.post("refs/heads/master", before, after, token: flowdock_token, tags: ["git", "push", "foo%bar"])
93
+ expect(request.with(body: hash_including(tags: ["git", "push", "foo%25bar"]))
94
+ ).to have_been_made.times(7)
85
95
  end
86
96
  end
metadata CHANGED
@@ -1,125 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowdock-git-hook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ville Lautanala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-26 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.4.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.4.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: flowdock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rdoc
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - ! '>='
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: 2.4.2
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - ! '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: 2.4.2
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - ~>
87
+ - - "~>"
60
88
  - !ruby/object:Gem::Version
61
89
  version: '2.8'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - ~>
94
+ - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '2.8'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: bundler
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - ~>
101
+ - - "~>"
74
102
  - !ruby/object:Gem::Version
75
103
  version: '1.0'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - ~>
108
+ - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: '1.0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: jeweler
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - ~>
115
+ - - "~>"
88
116
  - !ruby/object:Gem::Version
89
117
  version: 1.8.7
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - ~>
122
+ - - "~>"
95
123
  - !ruby/object:Gem::Version
96
124
  version: 1.8.7
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: webmock
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - ! '>='
129
+ - - ">="
102
130
  - !ruby/object:Gem::Version
103
131
  version: 1.6.4
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - ! '>='
136
+ - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: 1.6.4
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: jruby-openssl
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - ! '>='
143
+ - - ">="
116
144
  - !ruby/object:Gem::Version
117
145
  version: '0'
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - ! '>='
150
+ - - ">="
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
125
153
  description:
@@ -130,9 +158,9 @@ extra_rdoc_files:
130
158
  - LICENSE.txt
131
159
  - README.md
132
160
  files:
133
- - .document
134
- - .rspec
135
- - .travis.yml
161
+ - ".document"
162
+ - ".rspec"
163
+ - ".travis.yml"
136
164
  - Gemfile
137
165
  - LICENSE.txt
138
166
  - README.md
@@ -143,7 +171,6 @@ files:
143
171
  - lib/flowdock/git.rb
144
172
  - lib/flowdock/git/builder.rb
145
173
  - post-receive
146
- - spec/builder_spec.rb
147
174
  - spec/flowdock_git_spec.rb
148
175
  - spec/spec_helper.rb
149
176
  homepage: http://github.com/flowdock/flowdock-git-hook
@@ -156,17 +183,17 @@ require_paths:
156
183
  - lib
157
184
  required_ruby_version: !ruby/object:Gem::Requirement
158
185
  requirements:
159
- - - ! '>='
186
+ - - ">="
160
187
  - !ruby/object:Gem::Version
161
188
  version: '0'
162
189
  required_rubygems_version: !ruby/object:Gem::Requirement
163
190
  requirements:
164
- - - ! '>='
191
+ - - ">="
165
192
  - !ruby/object:Gem::Version
166
193
  version: '0'
167
194
  requirements: []
168
195
  rubyforge_project:
169
- rubygems_version: 2.0.5
196
+ rubygems_version: 2.4.1
170
197
  signing_key:
171
198
  specification_version: 4
172
199
  summary: Git Post-Receive hook for Flowdock
@@ -1,135 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe "Git Payload Builder" do
5
- before :each do
6
- @repo = Grit::Repo.new(".")
7
- @before = "7e32af569ba794b0b1c5e4c38fef1d4e2e56be51"
8
- @after = "a66d3ce668ae6f2a42d54d811962724200d5b32b"
9
- end
10
-
11
- it "parses ref name from head" do
12
- Flowdock::Git::Builder.new(@repo, "refs/heads/master", @before, @after).ref_name.should == "master"
13
- end
14
-
15
- it "parses ref name from tag" do
16
- Flowdock::Git::Builder.new(@repo, "refs/tags/release-1.0", @before, @after).ref_name.should == "release-1.0"
17
- end
18
-
19
- it "detects new branch and sets created=true in data" do
20
- hash = Flowdock::Git::Builder.new(@repo, "refs/heads/master", "0000000000000000000000000000000000000000", @after).to_hash
21
- hash[:created].should eq(true)
22
- hash[:deleted].should_not eq(true)
23
- end
24
-
25
- it "detects deleted branch and sets deleted=true in data" do
26
- hash = Flowdock::Git::Builder.new(@repo, "refs/heads/master", @before, "0000000000000000000000000000000000000000").to_hash
27
- hash[:deleted].should eq(true)
28
- hash[:created].should_not eq(true)
29
- end
30
-
31
- it "doesn't include commits in branch delete" do
32
- hash = Flowdock::Git::Builder.new(@repo, "refs/heads/master", @before, "0000000000000000000000000000000000000000").to_hash
33
- hash[:commits].should be_empty
34
- end
35
-
36
- describe "data hash" do
37
- before :each do
38
- @repo.stub!(:path).and_return("/foo/bar/flowdock-git-hook/.git")
39
- @hash = Flowdock::Git::Builder.new(@repo, "refs/heads/master", @before, @after).to_hash
40
- end
41
-
42
- if RUBY_VERSION > '1.9'
43
- it "properly sets encoding for UTF-8 content" do
44
- builder = Flowdock::Git::Builder.new(@repo, "refs/heads/master", @before, "0000000000000000000000000000000000000000")
45
- builder.stub(:commits).and_return([
46
- {
47
- :id => "0000000000000000000000000000000000000001",
48
- :message => "This message contains UTF-8: ö".force_encoding("ASCII-8BIT"),
49
- :timestamp => Time.now.iso8601,
50
- :author => {
51
- :name => "Föö Bär".force_encoding("ASCII-8BIT"),
52
- :email => "foo@example.com"
53
- },
54
- :removed => [],
55
- :added => [],
56
- :modified => []
57
- }
58
- ])
59
- builder.to_hash[:commits][0][:message].encoding.should eq(Encoding::UTF_8)
60
- builder.to_hash[:commits][0][:message].should == "This message contains UTF-8: ö"
61
- end
62
-
63
- it "encodes ISO-8859-1 to UTF-8" do
64
- builder = Flowdock::Git::Builder.new(@repo, "refs/heads/master", @before, "0000000000000000000000000000000000000000")
65
- builder.stub(:commits).and_return([
66
- {
67
- :id => "0000000000000000000000000000000000000001",
68
- :message => "This message contains UTF-8: ö".encode("ISO-8859-1").force_encoding("ASCII-8BIT"),
69
- :timestamp => Time.now.iso8601,
70
- :author => {
71
- :name => "Föö Bär".encode("ISO-8859-1").force_encoding("ASCII-8BIT"),
72
- :email => "foo@example.com"
73
- },
74
- :removed => [],
75
- :added => [],
76
- :modified => []
77
- }
78
- ])
79
- builder.to_hash[:commits][0][:author][:name].encoding.should eq(Encoding::UTF_8)
80
- builder.to_hash[:commits][0][:author][:name].should == "Föö Bär"
81
- end
82
- end
83
-
84
- it "contains before" do
85
- @hash[:before].should == @before
86
- end
87
-
88
- it "contains after" do
89
- @hash[:after].should == @after
90
- end
91
-
92
- it "contains ref" do
93
- @hash[:ref].should == "refs/heads/master"
94
- end
95
-
96
- it "contains ref name" do
97
- @hash[:ref_name].should == "master"
98
- end
99
-
100
- describe "commits" do
101
- it "contains all changed commits" do
102
- @hash[:commits].should have(2).items
103
- end
104
-
105
- it "has commit author information" do
106
- @hash[:commits].first[:author][:name].should eq("Ville Lautanala")
107
- @hash[:commits].first[:author][:email].should eq("lautis@gmail.com")
108
- end
109
-
110
- it "has commit id" do
111
- @hash[:commits].first[:id].should == "cf4a78c59cf9e06ebd7336900b2a66b85a88b76c"
112
- end
113
-
114
- it "puts deleted files in an array" do
115
- @hash[:commits].first[:removed].should include("spec/flowdock-git-hook_spec.rb")
116
- end
117
-
118
- it "puts added files to an array" do
119
- @hash[:commits].first[:added].should include("lib/flowdock/git.rb")
120
- end
121
-
122
- it "detects modified files" do
123
- @hash[:commits].first[:modified].should_not include("spec/flowdock-git-hook_spec.rb")
124
- @hash[:commits].first[:modified].should_not include("lib/flowdock/git.rb")
125
- @hash[:commits].first[:modified].should include("lib/flowdock-git-hook.rb")
126
- end
127
- end
128
-
129
- describe "repository information" do
130
- it "contains repository name based on file path" do
131
- @hash[:repository][:name] = "flowdock-git-hook"
132
- end
133
- end
134
- end
135
- end