lita-bitbucket-pullrequest 0.0.1

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: 13117e2a575fde6ab46e9223d4ca741f902dd918
4
+ data.tar.gz: e7bde34b57c459f0079fd903c1562153466609c5
5
+ SHA512:
6
+ metadata.gz: ef4c174c19b62ca2caa759e2fa2603021980d0554a12b58d2790a262b7d0542f1ea11c796dd3cda564769a9d446f21c897f36c185c7d979a910fc6666e8a795a
7
+ data.tar.gz: 649d3283dca99fe3c638f5d791fb4598ab5bf9f4bc5d1f5413e9cc15f09f2e841f3326666cb8fc91a9fa4f22f9a2a35dd28eddd98d9c4a048c2369152b32bef1
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 f440
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # lita-bitbucket-pullrequest
2
+
3
+ lita-bitbucket-pullrequest is a handler for [Lita](https://github.com/jimmycuadra/lita) that aimed at receiving pull request messages from [Bitbucket](hhttps://bitbucket.org).
4
+
5
+ ## Installation
6
+
7
+ Add lita-bitbucket-pullrequest to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-bitbucket-pullrequest"
11
+ ```
12
+
13
+
14
+ ## Usage
15
+
16
+ You will need to add a BitBucket Pull Request Post hook that points to: `http://example.com/bitbucket_pullrequest?room=xxxxxx`
17
+
18
+ `room` - The plugin sends messages in this room.
19
+
20
+ ## License
21
+
22
+ [MIT](http://opensource.org/licenses/MIT)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/bitbucket_pullrequest"
@@ -0,0 +1,72 @@
1
+ module Lita
2
+ module Handlers
3
+ class BitbucketPullrequest < Handler
4
+ http.post "/bitbucket_pullrequest", :receive
5
+
6
+ def receive(request, response)
7
+ I18n.locale = Lita.config.robot.locale
8
+
9
+ room = request.params['room']
10
+ target = Source.new(room: room)
11
+ data = parse(request.body.read)
12
+ message = format(data)
13
+ return if message.nil?
14
+ robot.send_message(target, message)
15
+ end
16
+
17
+ private
18
+
19
+ def parse(json)
20
+ MultiJson.load(json, symbolize_keys: true)
21
+ rescue MultiJson::ParseError => exception
22
+ exception.data
23
+ exception.cause
24
+ end
25
+
26
+ def format(data)
27
+ type, content = data.first
28
+ case type
29
+ when :pullrequest_approve
30
+ when :pullrequest_unapprove
31
+ # These can't recognize the repository name.
32
+ # ref. [Pull Request POST hook does not include links to related objects (BB-9535)t](https://bitbucket.org/site/master/issue/8340/pull-request-post-hook-does-not-include)
33
+
34
+ when :pullrequest_comment_created
35
+ t("pullrequest_comment_created",
36
+ name: content[:user][:display_name],
37
+ url: content[:links][:html][:href].sub(/api\./, ''))
38
+ when :pullrequest_comment_deleted
39
+ t("pullrequest_comment_deleted",
40
+ name: content[:user][:display_name],
41
+ url: content[:links][:html][:href].sub(/api\./, ''))
42
+ when :pullrequest_comment_updated
43
+ t("pullrequest_comment_deleted",
44
+ name: content[:user][:display_name],
45
+ url: content[:links][:html][:href].sub(/api\./, ''))
46
+ when :pullrequest_created
47
+ t("pullrequest_created",
48
+ name: content[:author][:display_name],
49
+ title: content[:title],
50
+ url: "https://bitbucket.org/#{content[:destination][:repository][:full_name]}/pull-request/#{content[:id]}/")
51
+ when :pullrequest_merged
52
+ t("pullrequest_merged",
53
+ name: content[:author][:display_name],
54
+ title: content[:title],
55
+ url: "https://bitbucket.org/#{content[:destination][:repository][:full_name]}/branch/#{content[:destination][:branch][:name]}")
56
+ when :pullrequest_declined
57
+ t("pullrequest_declined",
58
+ name: content[:author][:display_name],
59
+ title: content[:title],
60
+ url: "https://bitbucket.org/#{content[:destination][:repository][:full_name]}/pull-requests?displaystatus=declined")
61
+ when :pullrequest_updated
62
+ t("pullrequest_updated",
63
+ name: content[:author][:display_name],
64
+ title: content[:title],
65
+ url: "https://bitbucket.org/#{content[:destination][:repository][:full_name]}/pull-request/")
66
+ end
67
+ end
68
+ end
69
+
70
+ Lita.register_handler(BitbucketPullrequest)
71
+ end
72
+ end
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-bitbucket-pullrequest"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["f440"]
5
+ spec.email = ["freq440@gmail.com"]
6
+ spec.description = %q{A Lita handler for receiving Bitbucket pull request hook.}
7
+ spec.summary = %q{A Lita handler for receiving Bitbucket pull request hook.}
8
+ spec.homepage = "https://github.com/f440/lita-bitbucket-pullrequest"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 3.2"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
22
+ end
@@ -0,0 +1,11 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ bitbucket_pullrequest:
5
+ pullrequest_comment_created: "%{name} commented %{url}"
6
+ pullrequest_comment_deleted: "%{name} deleted a comment %{url}"
7
+ pullrequest_comment_updated: "%{name} changed a comment %{url}"
8
+ pullrequest_created: "%{name} created a pull request : %{title} %{url}"
9
+ pullrequest_merged: "%{name} the a pull request : %{title} %{url}"
10
+ pullrequest_declined: "%{name} declined a pull request : %{title} %{url}"
11
+ pullrequest_updated: "%{name} updated a pull request: %{title} %{url}"
@@ -0,0 +1,11 @@
1
+ ja:
2
+ lita:
3
+ handlers:
4
+ bitbucket_pullrequest:
5
+ pullrequest_comment_created: "%{name} がコメントを追加しました %{url}"
6
+ pullrequest_comment_deleted: "%{name} がコメントを削除しました %{url}"
7
+ pullrequest_comment_updated: "%{name} がコメントを変更しました %{url}"
8
+ pullrequest_created: "%{name} がプルリクエストを作成しました: %{title} %{url}"
9
+ pullrequest_merged: "%{name} がプルリクエストをマージしました: %{title} %{url}"
10
+ pullrequest_declined: "%{name} がプルリクエストをとりさげました: %{title} %{url}"
11
+ pullrequest_updated: "%{name} がプルリクエストを変更しました: %{title} %{url}"
@@ -0,0 +1,32 @@
1
+ {
2
+ "pullrequest_comment_created": {
3
+ "id": 2049816,
4
+ "updated_on": "2014-06-04T14:34:02.756635+00:00",
5
+ "user": {
6
+ "links": {
7
+ "avatar": {
8
+ "href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Jul/19/f440-avatar-2607955360-3_avatar.png"
9
+ },
10
+ "self": {
11
+ "href": "https://api.bitbucket.org/2.0/users/f440"
12
+ }
13
+ },
14
+ "display_name": "f440",
15
+ "username": "f440"
16
+ },
17
+ "created_on": "2014-06-04T14:34:02.754427+00:00",
18
+ "content": {
19
+ "html": "<p>efsf</p>",
20
+ "markup": "markdown",
21
+ "raw": "efsf"
22
+ },
23
+ "links": {
24
+ "html": {
25
+ "href": "https://api.bitbucket.org/f440/sandbox/pull-request/5/_/diff#comment-2049816"
26
+ },
27
+ "self": {
28
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/5/comments/2049816"
29
+ }
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,107 @@
1
+ {
2
+ "pullrequest_created": {
3
+ "closed_by": null,
4
+ "merge_commit": null,
5
+ "updated_on": "2014-06-04T02:53:52.373507+00:00",
6
+ "participants": [],
7
+ "created_on": "2014-06-04T02:53:52.350615+00:00",
8
+ "author": {
9
+ "links": {
10
+ "avatar": {
11
+ "href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Jul/19/f440-avatar-2607955360-3_avatar.png"
12
+ },
13
+ "self": {
14
+ "href": "https://api.bitbucket.org/2.0/users/f440"
15
+ }
16
+ },
17
+ "display_name": "f440",
18
+ "username": "f440"
19
+ },
20
+ "reason": "",
21
+ "source": {
22
+ "repository": {
23
+ "name": "sandbox",
24
+ "links": {
25
+ "avatar": {
26
+ "href": "https://d3oaxc4q5k2d6q.cloudfront.net/m/4f5af239a3af/img/language-avatars/ruby_16.png"
27
+ },
28
+ "self": {
29
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox"
30
+ }
31
+ },
32
+ "full_name": "f440/sandbox"
33
+ },
34
+ "branch": {
35
+ "name": "foo"
36
+ },
37
+ "commit": {
38
+ "links": {
39
+ "self": {
40
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/commit/070f8153f55f"
41
+ }
42
+ },
43
+ "hash": "070f8153f55f"
44
+ }
45
+ },
46
+ "description": "",
47
+ "links": {
48
+ "approve": {
49
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3/approve"
50
+ },
51
+ "decline": {
52
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3/decline"
53
+ },
54
+ "commits": {
55
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3/commits"
56
+ },
57
+ "self": {
58
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3"
59
+ },
60
+ "comments": {
61
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3/comments"
62
+ },
63
+ "merge": {
64
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3/merge"
65
+ },
66
+ "html": {
67
+ "href": "https://api.bitbucket.org/f440/sandbox/pull-request/3"
68
+ },
69
+ "activity": {
70
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3/activity"
71
+ },
72
+ "diff": {
73
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/pullrequests/3/diff"
74
+ }
75
+ },
76
+ "title": "asdf",
77
+ "close_source_branch": true,
78
+ "reviewers": [],
79
+ "destination": {
80
+ "repository": {
81
+ "name": "sandbox",
82
+ "links": {
83
+ "avatar": {
84
+ "href": "https://d3oaxc4q5k2d6q.cloudfront.net/m/4f5af239a3af/img/language-avatars/ruby_16.png"
85
+ },
86
+ "self": {
87
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox"
88
+ }
89
+ },
90
+ "full_name": "f440/sandbox"
91
+ },
92
+ "branch": {
93
+ "name": "master"
94
+ },
95
+ "commit": {
96
+ "links": {
97
+ "self": {
98
+ "href": "https://api.bitbucket.org/2.0/repositories/f440/sandbox/commit/232aab073088"
99
+ }
100
+ },
101
+ "hash": "232aab073088"
102
+ }
103
+ },
104
+ "state": "OPEN",
105
+ "id": 3
106
+ }
107
+ }
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::BitbucketPullrequest, lita_handler: true do
4
+ it { routes_http(:post, "/bitbucket_pullrequest").to(:receive) }
5
+
6
+ describe "#receive" do
7
+ before do
8
+ Lita.config.robot.locale = :en
9
+ end
10
+
11
+ let(:request) do
12
+ request = double("Rack::Request")
13
+ allow(request).to receive(:params).and_return(params)
14
+ allow(request).to receive(:body).and_return(body)
15
+ request
16
+ end
17
+ let(:response) { Rack::Response.new }
18
+ let(:params) { {} }
19
+ let(:body) { StringIO.new }
20
+
21
+ context "create pull request" do
22
+ before do
23
+ allow(params).to receive(:[]).with('room').and_return('foo')
24
+ allow(request).to receive(:body).and_return(StringIO.new(fixture('pullrequest_created')))
25
+ end
26
+ it "responds when a pull request is created" do
27
+ expect(robot).to receive(:send_message) do |target, message|
28
+ expect(target.room).to eq('foo')
29
+ expect(message).to include "created a pull request"
30
+ end
31
+ subject.receive(request, response)
32
+ end
33
+ end
34
+
35
+ context "create comment" do
36
+ before do
37
+ Lita.config.robot.locale = :en
38
+ allow(params).to receive(:[]).with('room').and_return('foo')
39
+ allow(request).to receive(:body).and_return(StringIO.new(fixture('pullrequest_comment_created')))
40
+ end
41
+ it "responds when someone comment about pull request" do
42
+ expect(robot).to receive(:send_message) do |target, message|
43
+ expect(target.room).to eq('foo')
44
+ expect(message).to include "commented"
45
+ end
46
+ subject.receive(request, response)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-bitbucket-pullrequest"
2
+ require "lita/rspec"
3
+
4
+ def fixture(filename)
5
+ File.read(File.join(__dir__, "fixtures", "#{filename}.json"))
6
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-bitbucket-pullrequest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - f440
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0.beta2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0.beta2
69
+ description: A Lita handler for receiving Bitbucket pull request hook.
70
+ email:
71
+ - freq440@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - lib/lita-bitbucket-pullrequest.rb
82
+ - lib/lita/handlers/bitbucket_pullrequest.rb
83
+ - lita-bitbucket-pullrequest.gemspec
84
+ - locales/en.yml
85
+ - locales/ja.yml
86
+ - spec/fixtures/pullrequest_comment_created.json
87
+ - spec/fixtures/pullrequest_created.json
88
+ - spec/lita/handlers/bitbucket_pullrequest_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/f440/lita-bitbucket-pullrequest
91
+ licenses:
92
+ - MIT
93
+ metadata:
94
+ lita_plugin_type: handler
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: A Lita handler for receiving Bitbucket pull request hook.
115
+ test_files:
116
+ - spec/fixtures/pullrequest_comment_created.json
117
+ - spec/fixtures/pullrequest_created.json
118
+ - spec/lita/handlers/bitbucket_pullrequest_spec.rb
119
+ - spec/spec_helper.rb
120
+ has_rdoc: