gitlab-flowdock-git-hook 0.4.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f04a6f62e807a2ec59b2aa456c82ac8472d83d2
4
+ data.tar.gz: dc39e47ec6214c8d03dc751012e6d359e38d7698
5
+ SHA512:
6
+ metadata.gz: 2b94ba9e7f920fca84f81a93b957f21d8c792196e04f7a457ea6bdda84890d61cc2fc4ac31c90dfc7e43772db75bce4ff345ad8d5e6eb7ca3b747dc367db71bc
7
+ data.tar.gz: ca33e30435bbac89362d8f33addc395d0fde988c198ab6a6fbb98dcfdfa329d27d0b2765d353e93e92c8a3cf589bf8993122468e135b2946bcf0fbc6564d7c1f
@@ -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 "gitlab-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
@@ -2,9 +2,13 @@
2
2
 
3
3
  Git Post-Receive hook for [Flowdock](http://flowdock.com).
4
4
 
5
+ ## Note
6
+
7
+ Version 1.0. supports only source flow tokens. 0.x versions use a deprecated API which will be removed soon.
8
+
5
9
  ## Installation
6
10
 
7
- First, you need to install this gem. You need to have Ruby 1.8.6 and Rubygems installed in your system.
11
+ First, you need to install this gem. You need to have Ruby and Rubygems installed in your system.
8
12
 
9
13
  $ gem install flowdock-git-hook
10
14
 
@@ -13,9 +17,9 @@ Then, download the post-receive hook file to the hooks directory and make it exe
13
17
  $ wget -O hooks/post-receive https://raw.github.com/flowdock/flowdock-git-hook/master/post-receive
14
18
  $ chmod +x hooks/post-receive
15
19
 
16
- Configure your Flow API tokens to git configuration
20
+ Set the source flow token given to you by the Flowdock git configuration service
17
21
 
18
- $ git config flowdock.token <Flow API token>
22
+ $ git config flowdock.token <source flow token>
19
23
 
20
24
  After this, you should get updates from your git repo every time you push to it.
21
25
 
@@ -23,6 +27,22 @@ After this, you should get updates from your git repo every time you push to it.
23
27
 
24
28
  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
29
 
30
+ ### Permanent references
31
+
32
+ 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.
33
+
34
+ For example to create new threads for each push to the `master` branch and any branch starting with `with-regex-` do this
35
+
36
+ $ git config flowdock.permanent-references "refs/heads/master, refs/heads/with-regex-.*"
37
+
38
+
39
+ ### Repository name
40
+
41
+ The repository name displayed in the inbox message can be set with `repository-name`
42
+
43
+ $ git config flowdock.repository-name "my repo"
44
+
45
+
26
46
  ### Repository URL
27
47
 
28
48
  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 +61,7 @@ The `%s` will be replaced with the commit SHA.
41
61
 
42
62
  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
63
 
44
- $ gitconfig flowdock.diff-url-pattern "http://example.com/mygitviewer/compare/%s...%s"
64
+ $ git config flowdock.diff-url-pattern "http://example.com/mygitviewer/compare/%s...%s"
45
65
 
46
66
  ## Advanced usage
47
67
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 1.0.0
@@ -5,11 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gitlab-flowdock-git-hook"
8
- s.version = "0.4.2.2"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.require_paths = ["lib"]
11
12
  s.authors = ["Ville Lautanala", "Boyan Tabakov"]
12
- s.date = "2013-10-03"
13
+ s.date = "2015-08-11"
13
14
  s.email = "blade@alslayer.net"
14
15
  s.extra_rdoc_files = [
15
16
  "LICENSE.txt",
@@ -29,14 +30,12 @@ Gem::Specification.new do |s|
29
30
  "lib/flowdock/git.rb",
30
31
  "lib/flowdock/git/builder.rb",
31
32
  "post-receive",
32
- "spec/builder_spec.rb",
33
33
  "spec/flowdock_git_spec.rb",
34
34
  "spec/spec_helper.rb"
35
35
  ]
36
36
  s.homepage = "http://github.com/bladealslayer/flowdock-git-hook"
37
37
  s.licenses = ["MIT"]
38
- s.require_paths = ["lib"]
39
- s.rubygems_version = "2.0.5"
38
+ s.rubygems_version = "2.4.1"
40
39
  s.summary = "Git Post-Receive hook for Flowdock. Gem requirements patched for use with Gitlab."
41
40
 
42
41
  if s.respond_to? :specification_version then
@@ -45,6 +44,8 @@ Gem::Specification.new do |s|
45
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
45
  s.add_runtime_dependency(%q<gitlab-grit>, [">= 2.4.1"])
47
46
  s.add_runtime_dependency(%q<multi_json>, [">= 0"])
47
+ s.add_runtime_dependency(%q<flowdock>, ["~> 0.7"])
48
+ s.add_development_dependency(%q<byebug>, [">= 0"])
48
49
  s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
49
50
  s.add_development_dependency(%q<rspec>, ["~> 2.8"])
50
51
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
@@ -54,6 +55,8 @@ Gem::Specification.new do |s|
54
55
  else
55
56
  s.add_dependency(%q<gitlab-grit>, [">= 2.4.1"])
56
57
  s.add_dependency(%q<multi_json>, [">= 0"])
58
+ s.add_dependency(%q<flowdock>, ["~> 0.7"])
59
+ s.add_dependency(%q<byebug>, [">= 0"])
57
60
  s.add_dependency(%q<rdoc>, [">= 2.4.2"])
58
61
  s.add_dependency(%q<rspec>, ["~> 2.8"])
59
62
  s.add_dependency(%q<bundler>, ["~> 1.0"])
@@ -64,6 +67,8 @@ Gem::Specification.new do |s|
64
67
  else
65
68
  s.add_dependency(%q<gitlab-grit>, [">= 2.4.1"])
66
69
  s.add_dependency(%q<multi_json>, [">= 0"])
70
+ s.add_dependency(%q<flowdock>, ["~> 0.7"])
71
+ s.add_dependency(%q<byebug>, [">= 0"])
67
72
  s.add_dependency(%q<rdoc>, [">= 2.4.2"])
68
73
  s.add_dependency(%q<rspec>, ["~> 2.8"])
69
74
  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,140 +1,164 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gitlab-flowdock-git-hook
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 4
8
- - 2
9
- - 2
10
- version: 0.4.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Ville Lautanala
14
8
  - Boyan Tabakov
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2013-10-03 00:00:00 +03:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
12
+ date: 2015-08-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
23
15
  name: gitlab-grit
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 2
31
- - 4
32
- - 1
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
33
20
  version: 2.4.1
34
21
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 2.4.1
28
+ - !ruby/object:Gem::Dependency
37
29
  name: multi_json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
38
36
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- version: "0"
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: flowdock
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '0.7'
46
49
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rdoc
50
50
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 2
57
- - 4
58
- - 2
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '0.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: byebug
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rdoc
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
59
76
  version: 2.4.2
60
77
  type: :development
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: rspec
64
78
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
66
- requirements:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: 2.4.2
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
67
88
  - - ~>
68
- - !ruby/object:Gem::Version
69
- segments:
70
- - 2
71
- - 8
72
- version: "2.8"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.8'
73
91
  type: :development
74
- version_requirements: *id004
75
- - !ruby/object:Gem::Dependency
76
- name: bundler
77
92
  prerelease: false
78
- requirement: &id005 !ruby/object:Gem::Requirement
79
- requirements:
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '2.8'
98
+ - !ruby/object:Gem::Dependency
99
+ name: bundler
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
80
102
  - - ~>
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 1
84
- - 0
85
- version: "1.0"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.0'
86
105
  type: :development
87
- version_requirements: *id005
88
- - !ruby/object:Gem::Dependency
89
- name: jeweler
90
106
  prerelease: false
91
- requirement: &id006 !ruby/object:Gem::Requirement
92
- requirements:
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
93
109
  - - ~>
94
- - !ruby/object:Gem::Version
95
- segments:
96
- - 1
97
- - 8
98
- - 7
110
+ - !ruby/object:Gem::Version
111
+ version: '1.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: jeweler
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
99
118
  version: 1.8.7
100
119
  type: :development
101
- version_requirements: *id006
102
- - !ruby/object:Gem::Dependency
103
- name: webmock
104
120
  prerelease: false
105
- requirement: &id007 !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- segments:
110
- - 1
111
- - 6
112
- - 4
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.8.7
126
+ - !ruby/object:Gem::Dependency
127
+ name: webmock
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
113
132
  version: 1.6.4
114
133
  type: :development
115
- version_requirements: *id007
116
- - !ruby/object:Gem::Dependency
117
- name: jruby-openssl
118
134
  prerelease: false
119
- requirement: &id008 !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- segments:
124
- - 0
125
- version: "0"
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: 1.6.4
140
+ - !ruby/object:Gem::Dependency
141
+ name: jruby-openssl
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
126
147
  type: :development
127
- version_requirements: *id008
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
128
154
  description:
129
155
  email: blade@alslayer.net
130
156
  executables: []
131
-
132
157
  extensions: []
133
-
134
- extra_rdoc_files:
158
+ extra_rdoc_files:
135
159
  - LICENSE.txt
136
160
  - README.md
137
- files:
161
+ files:
138
162
  - .document
139
163
  - .rspec
140
164
  - .travis.yml
@@ -148,38 +172,31 @@ files:
148
172
  - lib/flowdock/git.rb
149
173
  - lib/flowdock/git/builder.rb
150
174
  - post-receive
151
- - spec/builder_spec.rb
152
175
  - spec/flowdock_git_spec.rb
153
176
  - spec/spec_helper.rb
154
- has_rdoc: true
155
177
  homepage: http://github.com/bladealslayer/flowdock-git-hook
156
- licenses:
178
+ licenses:
157
179
  - MIT
180
+ metadata: {}
158
181
  post_install_message:
159
182
  rdoc_options: []
160
-
161
- require_paths:
183
+ require_paths:
162
184
  - lib
163
- required_ruby_version: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- segments:
168
- - 0
169
- version: "0"
170
- required_rubygems_version: !ruby/object:Gem::Requirement
171
- requirements:
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- segments:
175
- - 0
176
- version: "0"
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
177
195
  requirements: []
178
-
179
196
  rubyforge_project:
180
- rubygems_version: 1.3.6
197
+ rubygems_version: 2.0.14
181
198
  signing_key:
182
199
  specification_version: 4
183
- summary: Git Post-Receive hook for Flowdock. Gem requirements patched for use with Gitlab.
200
+ summary: Git Post-Receive hook for Flowdock. Gem requirements patched for use with
201
+ Gitlab.
184
202
  test_files: []
185
-
@@ -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