lita-gitcamp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27083969a969cd9d217c81485477eb36a2e16a11
4
+ data.tar.gz: 33d41d28088e995ff9c6681ab114e5d26e28caaf
5
+ SHA512:
6
+ metadata.gz: a7188bf47c18f07a1a437ccd1c2f1157aca841bd772e134cb66203cc029bc7b7ce5807d89668d8bddf3140d1570c5534733e6817b4a54f79dd3a33c29972f944
7
+ data.tar.gz: f5299651c03dafec83d2f44833f62111a5f1ac97de564d0b72e88bd9c02168d57d0f2575b8354672852fbb955709bda5f16d4f5d73478a2ef5150e5f3714787f
data/.gitignore ADDED
@@ -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) 2013 Sergeev Peter
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.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # lita-gitcamp
2
+
3
+ Lita-gitcamp handler automaticly closes Basecamp todo when mentioning it Github issue closes.
4
+
5
+ We use the next workflow in our development process. We create todos list in basecamp for our customers, duplicate them in Github with description and link to Basecamp's todo. Using Github semantic commit messages we can close issues on Github but not on Basecamp. Lita-gitcamp is made to fix that issue.
6
+
7
+ ## Installation
8
+
9
+ Add lita-gitcamp to your Lita instance's Gemfile:
10
+
11
+ ``` ruby
12
+ gem "lita-gitcamp"
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ There are few configuration options are available
18
+
19
+ **rooms** - JIDs of rooms to send notification. Default value is :all.
20
+
21
+ **notify_chat** - Enables/disables chat notification when issue and todo are closed. Default: true.
22
+
23
+ **github_token** - Your Github API token
24
+
25
+ **basecamp_login** - Basecamp login. Gem uses basic auth and [bcx](https://github.com/paulspringett/bcx) gem.
26
+
27
+ **basecamp_password** - Basecamp password
28
+
29
+ **basecamp_account** - Basecamp account id
30
+
31
+ ## Usage
32
+
33
+ Next commands will add and remove repositories from gitcamp all-seeing eye
34
+
35
+ ``` ruby
36
+ add gitcamp repo http://github.com/EvercodeLab/maha2
37
+ remove gitcamp repo http://github.com/EvercodeLab/maha2
38
+ ```
39
+
40
+ You also need to setup Hithub hook with /gitcamp path. Handler will listen it.
41
+ ![Github hoob](https://photos-1.dropbox.com/t/0/AAAN2wL_FlUD6wXE_lZ982H8X5iYzdYWEUnDV6-7qY2P5A/12/11190302/png/1024x768/3/1383753600/0/2/Screenshot%202013-11-06%2018.48.40.png/Xf8_lMdwQ2SaZQ_sIeMlXqGzRmELetzy3mGhpCbzV7Q)
42
+
43
+ ## License
44
+
45
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -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,2 @@
1
+ require "lita/handlers/gitcamp"
2
+ require "lita/handlers/receptionist"
@@ -0,0 +1,85 @@
1
+ require "lita"
2
+ require "octokit"
3
+ require "bcx"
4
+
5
+ module Lita
6
+ module Handlers
7
+ class Gitcamp < Handler
8
+ http.post "/gitcamp", :receive
9
+
10
+ def self.default_config(config)
11
+ config.rooms = :all
12
+ config.github_token = nil
13
+ config.notify_chat = true
14
+ config.basecamp_login = nil
15
+ config.basecamp_password = nil
16
+ config.basecamp_account = nil
17
+ end
18
+
19
+ def receive(request, responce)
20
+ if request.params.has_key? "payload"
21
+ payload = JSON.parse(request.params["payload"])
22
+ colsed_issues, owner, repo = parse_payload payload
23
+
24
+ return if colsed_issues.empty?
25
+ tasks = get_todos_numbers(colsed_issues, owner, repo)
26
+ return if tasks.empty?
27
+ finish_basecamp_tasks(tasks)
28
+ responce.reply "Basecamp tasks closed: #{tasks.count}" if Lita.config.handlers.gitcamp.notify_chat
29
+ end
30
+ end
31
+
32
+ def parse_payload(payload)
33
+ issues = []
34
+ if payload.has_key? "commits"
35
+ regex = /(?:close|fix|resolve)\w*?\s\#(\d+)/im
36
+
37
+ messages = payload["commits"].collect {|c| c["message"]}.join(",")
38
+ issues = messages.scan(regex).flatten
39
+
40
+ [issues, payload["repository"]["owner"]["name"], payload["repository"]["name"]]
41
+ end
42
+ end
43
+
44
+ def get_todos_numbers(issues, owner, repo)
45
+ todos = []
46
+ client = Octokit::Client.new access_token: Lita.config.handlers.gitcamp.github_token
47
+ issues.each do |i|
48
+ # GET /repos/:owner/:repo/issues/:number
49
+ issue = client.issue("#{owner}/#{repo}", i)
50
+ todo_id = parse_issue_body(issue.body)
51
+ todos << todo_id unless todo_id.nil?
52
+ end
53
+
54
+ todos
55
+ end
56
+
57
+ def parse_issue_body(body)
58
+ regex = /basecamp.com\/\d+\/projects\/(\d+)(?:-\w*?)\/todos\/(\d+)/mi
59
+ captures = body.match(regex).captures
60
+ {project_id: captures[0], task_id: captures[1]}
61
+ end
62
+
63
+ def finish_basecamp_tasks(tasks)
64
+ client = basecamp_client
65
+
66
+ tasks.each do |t|
67
+ client.projects(t[:project_id]).todos(t[:task_id]).update!(completed: true)
68
+ end
69
+ end
70
+
71
+ def basecamp_client
72
+ Bcx.configure do |config|
73
+ config.account = Lita.config.handlers.gitcamp.basecamp_account
74
+ end
75
+
76
+ Bcx::Client::HTTP.new(
77
+ login: Lita.config.handlers.gitcamp.basecamp_login,
78
+ password: Lita.config.handlers.gitcamp.basecamp_password
79
+ )
80
+ end
81
+ end
82
+
83
+ Lita.register_handler(Gitcamp)
84
+ end
85
+ end
@@ -0,0 +1,34 @@
1
+ require "lita"
2
+
3
+ module Lita
4
+ module Handlers
5
+ class Receptionist < Handler
6
+ route /^add\sgitcamp\srepo\s(?:http|https)\:\/\/github.com\/(?<owner>[a-zA-Z\-]+)\/(?<name>[a-zA-Z\-]+)/, :add_repo
7
+ route /^remove\sgitcamp\srepo\s(?:http|https)\:\/\/github.com\/(?<owner>[a-zA-Z\-]+)\/(?<name>[a-zA-Z\-]+)/, :remove_repo
8
+
9
+ def add_repo(response)
10
+ repo_name = "https://github.com/#{response.matches[0][0]}/#{response.matches[0][1]}"
11
+ repos = redis.get('repos') || []
12
+
13
+ unless repos.include? repo_name
14
+ repos << repo_name
15
+ redis.set('repos', repos)
16
+ response.reply "Repo added"
17
+ end
18
+ end
19
+
20
+ def remove_repo(response)
21
+ repo_name = "https://github.com/#{response.matches[0][0]}/#{response.matches[0][1]}"
22
+ repos = redis.get('repos') || []
23
+
24
+ if repos.include? repo_name
25
+ repos = repos.delete repo_name
26
+ redis.set('repos', repos)
27
+ response.reply "Repo removed"
28
+ end
29
+ end
30
+ end
31
+
32
+ Lita.register_handler(Gitcamp)
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-gitcamp"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Sergeev Peter"]
5
+ spec.email = ["sergeev.peter@gmail.com"]
6
+ spec.description = %q{Gitcamp handler is your magic helper which closes your basecamp todos for you.}
7
+ spec.summary = %q{Your all-seeing eye.}
8
+ spec.homepage = "https://github.com/toothfairy/lita-gitcamp"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", "~> 2.6"
17
+ spec.add_runtime_dependency "bundler", "~> 1.3"
18
+ spec.add_runtime_dependency "octokit", "~> 2.4.0"
19
+ spec.add_runtime_dependency "bcx"
20
+
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec", ">= 2.14"
23
+ spec.add_development_dependency "simplecov"
24
+ spec.add_development_dependency "coveralls"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_runtime_dependency "redis-namespace", "~> 1.3.0"
27
+ end
@@ -0,0 +1,33 @@
1
+ {
2
+ "url": "https://api.github.com/repos/octokitty/testing/issues/1347",
3
+ "html_url": "https://github.com/octokitty/testing/issues/1347",
4
+ "number": 1,
5
+ "state": "open",
6
+ "title": "Devils todo",
7
+ "body": "I'm having a problem with humanity. https://basecamp.com/123123/projects/1-project/todos/2",
8
+ "user": {
9
+ "login": "octocat",
10
+ "id": 1,
11
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
12
+ "gravatar_id": "somehexcode",
13
+ "url": "https://api.github.com/users/octocat"
14
+ },
15
+ "labels": [
16
+ {
17
+ "url": "https://api.github.com/repos/octokitty/testing/labels/bug",
18
+ "name": "bug",
19
+ "color": "f29513"
20
+ }
21
+ ],
22
+ "assignee": {
23
+ "login": "octocat",
24
+ "id": 1,
25
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
26
+ "gravatar_id": "somehexcode",
27
+ "url": "https://api.github.com/users/octocat"
28
+ },
29
+ "comments": 0,
30
+ "closed_at": null,
31
+ "created_at": "2011-04-22T13:33:48Z",
32
+ "updated_at": "2011-04-22T13:33:48Z"
33
+ }
@@ -0,0 +1,144 @@
1
+ {
2
+ "after":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
3
+ "before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
4
+ "commits":[
5
+ {
6
+ "added":[
7
+
8
+ ],
9
+ "author":{
10
+ "email":"lolwut@noway.biz",
11
+ "name":"Garen Torikian",
12
+ "username":"octokitty"
13
+ },
14
+ "committer":{
15
+ "email":"lolwut@noway.biz",
16
+ "name":"Garen Torikian",
17
+ "username":"octokitty"
18
+ },
19
+ "distinct":true,
20
+ "id":"c441029cf673f84c8b7db52d0a5944ee5c52ff89",
21
+ "message":"Close #1: 123",
22
+ "modified":[
23
+ "README.md"
24
+ ],
25
+ "removed":[
26
+
27
+ ],
28
+ "timestamp":"2013-02-22T13:50:07-08:00",
29
+ "url":"https://github.com/octokitty/testing/commit/c441029cf673f84c8b7db52d0a5944ee5c52ff89"
30
+ },
31
+ {
32
+ "added":[
33
+
34
+ ],
35
+ "author":{
36
+ "email":"lolwut@noway.biz",
37
+ "name":"Garen Torikian",
38
+ "username":"octokitty"
39
+ },
40
+ "committer":{
41
+ "email":"lolwut@noway.biz",
42
+ "name":"Garen Torikian",
43
+ "username":"octokitty"
44
+ },
45
+ "distinct":true,
46
+ "id":"36c5f2243ed24de58284a96f2a643bed8c028658",
47
+ "message":"Fix #2: 123",
48
+ "modified":[
49
+ "README.md"
50
+ ],
51
+ "removed":[
52
+
53
+ ],
54
+ "timestamp":"2013-02-22T14:07:13-08:00",
55
+ "url":"https://github.com/octokitty/testing/commit/36c5f2243ed24de58284a96f2a643bed8c028658"
56
+ },
57
+ {
58
+ "added":[
59
+ "words/madame-bovary.txt"
60
+ ],
61
+ "author":{
62
+ "email":"lolwut@noway.biz",
63
+ "name":"Garen Torikian",
64
+ "username":"octokitty"
65
+ },
66
+ "committer":{
67
+ "email":"lolwut@noway.biz",
68
+ "name":"Garen Torikian",
69
+ "username":"octokitty"
70
+ },
71
+ "distinct":true,
72
+ "id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
73
+ "message":"Update #4: Testing",
74
+ "modified":[
75
+
76
+ ],
77
+ "removed":[
78
+ "madame-bovary.txt"
79
+ ],
80
+ "timestamp":"2013-03-12T08:14:29-07:00",
81
+ "url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
82
+ }
83
+ ],
84
+ "compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
85
+ "created":false,
86
+ "deleted":false,
87
+ "forced":false,
88
+ "head_commit":{
89
+ "added":[
90
+ "words/madame-bovary.txt"
91
+ ],
92
+ "author":{
93
+ "email":"lolwut@noway.biz",
94
+ "name":"Garen Torikian",
95
+ "username":"octokitty"
96
+ },
97
+ "committer":{
98
+ "email":"lolwut@noway.biz",
99
+ "name":"Garen Torikian",
100
+ "username":"octokitty"
101
+ },
102
+ "distinct":true,
103
+ "id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
104
+ "message":"Rename madame-bovary.txt to words/madame-bovary.txt",
105
+ "modified":[
106
+
107
+ ],
108
+ "removed":[
109
+ "madame-bovary.txt"
110
+ ],
111
+ "timestamp":"2013-03-12T08:14:29-07:00",
112
+ "url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
113
+ },
114
+ "pusher":{
115
+ "email":"lolwut@noway.biz",
116
+ "name":"Garen Torikian"
117
+ },
118
+ "ref":"refs/heads/master",
119
+ "repository":{
120
+ "created_at":1332977768,
121
+ "description":"",
122
+ "fork":false,
123
+ "forks":0,
124
+ "has_downloads":true,
125
+ "has_issues":true,
126
+ "has_wiki":true,
127
+ "homepage":"",
128
+ "id":3860742,
129
+ "language":"Ruby",
130
+ "master_branch":"master",
131
+ "name":"testing",
132
+ "open_issues":2,
133
+ "owner":{
134
+ "email":"lolwut@noway.biz",
135
+ "name":"octokitty"
136
+ },
137
+ "private":false,
138
+ "pushed_at":1363295520,
139
+ "size":2156,
140
+ "stargazers":1,
141
+ "url":"https://github.com/octocat/donuts",
142
+ "watchers":1
143
+ }
144
+ }
@@ -0,0 +1,118 @@
1
+ {
2
+ "after":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
3
+ "before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
4
+ "commits":[
5
+ {
6
+ "added":[
7
+
8
+ ],
9
+ "author":{
10
+ "email":"lolwut@noway.biz",
11
+ "name":"Garen Torikian",
12
+ "username":"octokitty"
13
+ },
14
+ "committer":{
15
+ "email":"lolwut@noway.biz",
16
+ "name":"Garen Torikian",
17
+ "username":"octokitty"
18
+ },
19
+ "distinct":true,
20
+ "id":"c441029cf673f84c8b7db52d0a5944ee5c52ff89",
21
+ "message":"Close #1: 123",
22
+ "modified":[
23
+ "README.md"
24
+ ],
25
+ "removed":[
26
+
27
+ ],
28
+ "timestamp":"2013-02-22T13:50:07-08:00",
29
+ "url":"https://github.com/octokitty/testing/commit/c441029cf673f84c8b7db52d0a5944ee5c52ff89"
30
+ },
31
+ {
32
+ "added":[
33
+ "words/madame-bovary.txt"
34
+ ],
35
+ "author":{
36
+ "email":"lolwut@noway.biz",
37
+ "name":"Garen Torikian",
38
+ "username":"octokitty"
39
+ },
40
+ "committer":{
41
+ "email":"lolwut@noway.biz",
42
+ "name":"Garen Torikian",
43
+ "username":"octokitty"
44
+ },
45
+ "distinct":true,
46
+ "id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
47
+ "message":"Update #4: Testing",
48
+ "modified":[
49
+
50
+ ],
51
+ "removed":[
52
+ "madame-bovary.txt"
53
+ ],
54
+ "timestamp":"2013-03-12T08:14:29-07:00",
55
+ "url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
56
+ }
57
+ ],
58
+ "compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
59
+ "created":false,
60
+ "deleted":false,
61
+ "forced":false,
62
+ "head_commit":{
63
+ "added":[
64
+ "words/madame-bovary.txt"
65
+ ],
66
+ "author":{
67
+ "email":"lolwut@noway.biz",
68
+ "name":"Garen Torikian",
69
+ "username":"octokitty"
70
+ },
71
+ "committer":{
72
+ "email":"lolwut@noway.biz",
73
+ "name":"Garen Torikian",
74
+ "username":"octokitty"
75
+ },
76
+ "distinct":true,
77
+ "id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
78
+ "message":"Rename madame-bovary.txt to words/madame-bovary.txt",
79
+ "modified":[
80
+
81
+ ],
82
+ "removed":[
83
+ "madame-bovary.txt"
84
+ ],
85
+ "timestamp":"2013-03-12T08:14:29-07:00",
86
+ "url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
87
+ },
88
+ "pusher":{
89
+ "email":"lolwut@noway.biz",
90
+ "name":"Garen Torikian"
91
+ },
92
+ "ref":"refs/heads/master",
93
+ "repository":{
94
+ "created_at":1332977768,
95
+ "description":"",
96
+ "fork":false,
97
+ "forks":0,
98
+ "has_downloads":true,
99
+ "has_issues":true,
100
+ "has_wiki":true,
101
+ "homepage":"",
102
+ "id":3860742,
103
+ "language":"Ruby",
104
+ "master_branch":"master",
105
+ "name":"testing",
106
+ "open_issues":2,
107
+ "owner":{
108
+ "email":"lolwut@noway.biz",
109
+ "name":"octokitty"
110
+ },
111
+ "private":false,
112
+ "pushed_at":1363295520,
113
+ "size":2156,
114
+ "stargazers":1,
115
+ "url":"https://github.com/octocat/donuts",
116
+ "watchers":1
117
+ }
118
+ }
@@ -0,0 +1,102 @@
1
+ require "spec_helper"
2
+ require "hashie"
3
+
4
+ describe Lita::Handlers::Gitcamp, lita_handler: true do
5
+ before do
6
+ stub_request(:get, "https://api.github.com/repos/octokitty/testing/issues/1").
7
+ with(:headers => {'Accept'=>'application/vnd.github.beta+json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Octokit Ruby Gem 2.4.0'}).
8
+ to_return(
9
+ status: 200,
10
+ body: lambda do |request|
11
+ id = request.uri.to_s.match /issues\/(\d+)/
12
+ Hashie::Mash.new(JSON.parse(File.read("./spec/api_data/issue_payload.json")))
13
+ end,
14
+ headers:{})
15
+
16
+ stub_request(:put, "https://basecamp.com/api/v1/projects/1/todos/2.json").
17
+ with(:body => "{\"completed\":true}",
18
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.8.8'}).
19
+ to_return(:status => 200, :body => "", :headers => {})
20
+ end
21
+
22
+ it "routes properly" do
23
+ routes_http(:post, "/gitcamp").to(:receive)
24
+ end
25
+
26
+ describe "receive github payload" do
27
+ let(:response) do
28
+ response = double("Rack::Response.new")
29
+ response.stub(:reply) do |args|
30
+ replies << args
31
+ end
32
+ response
33
+ end
34
+ let(:robot) { double("Lita::Robot") }
35
+
36
+ subject {Lita::Handlers::Gitcamp.new(robot)}
37
+
38
+ context "with valid data" do
39
+ let(:request) do
40
+ request = double("Rack::Request")
41
+ request.stub(:params) {{ "payload" => File.read('./spec/api_data/push_payload_full.json') }}
42
+ request
43
+ end
44
+
45
+ it "assepts some github stuff" do
46
+ expect {
47
+ subject.receive(request, response)
48
+ }.to_not raise_error
49
+ end
50
+
51
+ it "answers with proper todos count" do
52
+ subject.receive(request, response)
53
+ expect(replies.last).to eq("Basecamp tasks closed: 1")
54
+ end
55
+ end
56
+
57
+ context "with invalid data" do
58
+ let(:request) do
59
+ request = double("Rack::Request")
60
+ request.stub(:params) {{}}
61
+ request
62
+ end
63
+
64
+ it "ignores invalid payload" do
65
+ subject.receive(request, response)
66
+ expect(true).to be_true
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "parse closed issues" do
72
+ let(:payload) {JSON.parse(File.read('./spec/api_data/push_payload.json'))}
73
+
74
+ it "returns closed issue numbers" do
75
+ subject.parse_payload(payload).should eq([["1", "2"], "octokitty", "testing"])
76
+ end
77
+
78
+ it "doesnt fail on emtpy payload" do
79
+ subject.parse_payload({}).should eq(nil)
80
+ end
81
+ end
82
+
83
+ describe "todos from issues" do
84
+ let(:issue_body) {"I'm having a problem with humanity. https://basecamp.com/123123/projects/1-project/todos/2"}
85
+
86
+ it "get todos numbers" do
87
+ subject.get_todos_numbers(["1"], "octokitty", "testing").should eq([{project_id: "1", task_id: "2"} ])
88
+ end
89
+
90
+ it "parse todos from issue body" do
91
+ subject.parse_issue_body(issue_body).should eq({project_id: "1", task_id: "2"})
92
+ end
93
+ end
94
+
95
+ describe "basecamp todos" do
96
+ let(:tasks) {[{project_id: "1", task_id: "2"}]}
97
+
98
+ it "close todos" do
99
+ expect{subject.finish_basecamp_tasks(tasks)}.not_to raise_error
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+ require "redis-namespace"
3
+
4
+ REDIS_NAMESPACE = "lita.test:handlers:receptionist"
5
+
6
+ describe Lita::Handlers::Receptionist, lita_handler: true do
7
+ describe "Receptionist" do
8
+ before do
9
+ @repo = "https://github.com/octocat/donuts"
10
+
11
+ @redis ||= begin
12
+ redis = Redis.new
13
+ Redis::Namespace.new(REDIS_NAMESPACE, redis: redis)
14
+ end
15
+
16
+ @redis.flushall
17
+ end
18
+
19
+ context "Add repo" do
20
+ it "registers github repository to handle commits" do
21
+ send_command("add gitcamp repo #{@repo}")
22
+ repos = @redis.get('repos') || []
23
+
24
+ repos.should include(@repo)
25
+ end
26
+
27
+ it "responds positively" do
28
+ send_command("add gitcamp repo #{@repo}")
29
+ expect(replies.last).to eq(
30
+ "Repo added"
31
+ )
32
+ end
33
+ end
34
+
35
+ context "Remove repo" do
36
+ before :each do
37
+ repos = [@repo,]
38
+ @redis.set('repos', repos)
39
+ end
40
+
41
+ it "removes github repository from handled" do
42
+ send_command("remove gitcamp repo #{@repo}")
43
+ repos = @redis.get('repos') || []
44
+
45
+ repos.should_not include(@repo)
46
+ end
47
+
48
+ it "responds positively" do
49
+ send_command("remove gitcamp repo #{@repo}")
50
+ expect(replies.last).to eq(
51
+ "Repo removed"
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ require "lita-gitcamp"
4
+ require "lita/rspec"
5
+ require 'webmock/rspec'
6
+
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
11
+ SimpleCov.start { add_filter "/spec/" }
12
+
13
+ WebMock.disable_net_connect!
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-gitcamp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergeev Peter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-06 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: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
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: :runtime
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: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bcx
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '2.14'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '2.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: redis-namespace
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 1.3.0
153
+ description: Gitcamp handler is your magic helper which closes your basecamp todos
154
+ for you.
155
+ email:
156
+ - sergeev.peter@gmail.com
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - .gitignore
162
+ - Gemfile
163
+ - LICENSE
164
+ - README.md
165
+ - Rakefile
166
+ - lib/lita-gitcamp.rb
167
+ - lib/lita/handlers/gitcamp.rb
168
+ - lib/lita/handlers/receptionist.rb
169
+ - lita-gitcamp.gemspec
170
+ - spec/api_data/issue_payload.json
171
+ - spec/api_data/push_payload.json
172
+ - spec/api_data/push_payload_full.json
173
+ - spec/lita/handlers/gitcamp_spec.rb
174
+ - spec/lita/handlers/receptionist_spec.rb
175
+ - spec/spec_helper.rb
176
+ homepage: https://github.com/toothfairy/lita-gitcamp
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.1.9
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Your all-seeing eye.
200
+ test_files:
201
+ - spec/api_data/issue_payload.json
202
+ - spec/api_data/push_payload.json
203
+ - spec/api_data/push_payload_full.json
204
+ - spec/lita/handlers/gitcamp_spec.rb
205
+ - spec/lita/handlers/receptionist_spec.rb
206
+ - spec/spec_helper.rb