lita-github 0.0.1 → 0.0.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc3526e11e2ee29500e53d039037b006f74137b9
4
- data.tar.gz: f66a2729e9335198069b8b88fa45e46d3cfb57f7
3
+ metadata.gz: 83ef88d9ef27a589ab808c94f5acbee5c45890f3
4
+ data.tar.gz: 72f83141ec52828b41e684fce7a60371ef0f1270
5
5
  SHA512:
6
- metadata.gz: 0404f2c6e7846c9ae078809738d894c0a18a4a5ddb134c8e1626abd84c3a2c2cd1459ae91599e458cee909e3ec4d385d57226dd32280bcbf764351267f29092a
7
- data.tar.gz: a2bc91f92334ae48fc92c630903eb5edbeecc06b63a7c2534722bc94f3c7b6b0b3c453d3e2e9e3c94bc5ad0d46e830d17cfdae6f84c51ec5efa0b19dceda25f7
6
+ metadata.gz: 299cbb26470c5d2d99d3eaaf34bf61b5d5de8e88b6a0b701a24e09d02eb492b4e7db75e3642a729a4a6326f75635c4fe0c933a725ed1dfa1ad3c94c0c5ffca65
7
+ data.tar.gz: 3ca05325963bcc50abb0f39bb91f54acee4147699b513a3d06d272d4f8ed473b6d4d60292ab6b45877267387239a3c3ccb68b9833b9bba7710eaca892269f394
data/.gitignore CHANGED
@@ -29,6 +29,7 @@ build/
29
29
  # Gemfile.lock
30
30
  # .ruby-version
31
31
  # .ruby-gemset
32
+ Gemfile.lock
32
33
 
33
34
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
35
  .rvmrc
@@ -1,6 +1,7 @@
1
1
  branches:
2
2
  only:
3
3
  - master
4
+ env: CODECLIMATE_REPO_TOKEN=3ffc4d9148b686fd07872259719fc6458a5521213e73e1f7b9db8546292f622a
4
5
  services:
5
6
  - redis-server
6
7
  language: ruby
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  lita-github
2
2
  ===========
3
+ [![Build Status](https://img.shields.io/travis/PagerDuty/lita-github/master.svg)](https://travis-ci.org/PagerDuty/lita-github)
4
+ [![MIT License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
5
+ [![RubyGems :: lita-github Gem Version](http://img.shields.io/gem/v/lita-github.svg)](https://rubygems.org/gems/lita-github)
6
+ [![Code Climate Quality](https://img.shields.io/codeclimate/github/PagerDuty/lita-github.svg)](https://codeclimate.com/github/PagerDuty/lita-github)
7
+ [![Code Climate Coverage](http://img.shields.io/codeclimate/coverage/github/PagerDuty/lita-github.svg)](https://codeclimate.com/github/PagerDuty/lita-github)
8
+
3
9
  Copyright 2014 PagerDuty, Inc.
4
10
 
5
11
  Lita handler for GitHub-related operations. This include administrative management of organizations and repository management/operations.
@@ -22,3 +22,4 @@ Lita.load_locales Dir[File.expand_path(
22
22
 
23
23
  require 'lita-github/version'
24
24
  require 'lita/handlers/github'
25
+ require 'lita/handlers/github_repo'
@@ -0,0 +1,24 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module LitaGithub
18
+ # Github handler common-use method filters
19
+ module Filters
20
+ def func_disabled?(method)
21
+ config.send("#{method}_enabled".to_sym) ? false : true
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module LitaGithub
18
+ # Github handler common-use Organization methods
19
+ module Org
20
+ def organization(name)
21
+ name.nil? || name.empty? ? config.default_org : name
22
+ end
23
+ end
24
+ end
@@ -22,9 +22,9 @@ module LitaGithub
22
22
 
23
23
  # option regex, letting you scan the command string of things like:
24
24
  # key1:value key2:value, etc.
25
- OPT_REGEX ||= /((?:\s+?[a-zA-Z0-9_]+?):(?:[a-zA-Z0-9_]+))(?:\s+?)?/
25
+ OPT_REGEX ||= /((?:\s+?[a-zA-Z0-9_]+?):(?:[a-zA-Z0-9_]+))/
26
26
 
27
27
  # regex matcher for: Org/repo
28
- REPO_REGEX = '(?:(?<org>\w+)(?:\s+?)?\/)?(?:\s+?)?(?<repo>\w+)'
28
+ REPO_REGEX = '(?:(?<org>[a-zA-Z0-9_\-]+)(?:\s+?)?\/)?(?:\s+?)?(?<repo>[a-zA-Z0-9_\-]+)'
29
29
  end
30
30
  end
@@ -0,0 +1,28 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module LitaGithub
18
+ # Github handler common-use Repository methods
19
+ module Repo
20
+ def rpo(org, repo)
21
+ "#{org}/#{repo}"
22
+ end
23
+
24
+ def repo?(r)
25
+ octo.repository?(r)
26
+ end
27
+ end
28
+ end
@@ -16,6 +16,6 @@
16
16
 
17
17
  # Administer your Hub of Gits with Lita!
18
18
  module LitaGithub
19
- VERSION = '0.0.1'
19
+ VERSION = '0.0.2'
20
20
  MAJ, MIN, REV = VERSION.split('.').map(&:to_i)
21
21
  end
@@ -14,7 +14,6 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require 'octokit'
18
17
  require 'lita-github/version'
19
18
  require 'lita-github/r'
20
19
  require 'lita-github/config'
@@ -49,6 +48,8 @@ module Lita
49
48
  )
50
49
 
51
50
  def self.default_config(config)
51
+ # when setting default configuration values please remember one thing:
52
+ # secure and safe by default
52
53
  config.repo_delete_enabled = false
53
54
  config.repo_private_default = true
54
55
  end
@@ -0,0 +1,191 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 PagerDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'lita-github/r'
18
+ require 'lita-github/config'
19
+ require 'lita-github/octo'
20
+ require 'lita-github/org'
21
+ require 'lita-github/repo'
22
+ require 'lita-github/filters'
23
+
24
+ module Lita
25
+ # Lita Handler
26
+ module Handlers
27
+ # GitHub Lita Handler
28
+ class GithubRepo < Handler
29
+ include LitaGithub::Config # Github handler Lita configuration methods
30
+ include LitaGithub::Octo # Github handler common-use Octokit methods
31
+ include LitaGithub::Org # Github handler common-use Organization methods
32
+ include LitaGithub::Repo # Github handler common-use Repository methods
33
+ include LitaGithub::Filters # Github handler common-use method filters
34
+
35
+ on :loaded, :setup_octo # from LitaGithub::Octo
36
+
37
+ route(
38
+ /#{LitaGithub::R::A_REG}repo\s+?(?:create|new)\s+?#{LitaGithub::R::REPO_REGEX}.*$/,
39
+ :repo_create,
40
+ command: true,
41
+ help: {
42
+ 'gh repo create PagerDuty/lita-github private:true team:heckman' =>
43
+ 'Create the PagerDuty/lita-github repo, make it private, use team with "heckman" slug',
44
+ 'gh repo new PagerDuty/lita-github' =>
45
+ 'create new repo using the default privacy/team settings'
46
+ }
47
+ )
48
+
49
+ route(
50
+ /#{LitaGithub::R::A_REG}repo\s+?delete\s+?#{LitaGithub::R::REPO_REGEX}/,
51
+ :repo_delete, command: true, confirmation: true,
52
+ help: {
53
+ 'gh repo delete PagerDuty/lita-github' => 'Delete the PagerDuty/lita-github repo'
54
+ }
55
+ )
56
+
57
+ route(
58
+ /#{LitaGithub::R::A_REG}repo\s+?info\s+?#{LitaGithub::R::REPO_REGEX}/,
59
+ :repo_info,
60
+ command: true,
61
+ help: {
62
+ 'gh repo info PagerDuty/lita-github' => 'Display some information about the repo'
63
+ }
64
+ )
65
+
66
+ def repo_create(response)
67
+ org, repo = repo_match(response)
68
+
69
+ if repo?(rpo(org, repo))
70
+ return response.reply(t('repo_create.exists', org: org, repo: repo))
71
+ end
72
+
73
+ opts = extrapolate_create_opts(command_opts(response.args.join(' ')), org)
74
+
75
+ response.reply(create_repo(org, repo, opts))
76
+ end
77
+
78
+ def repo_delete(response)
79
+ return response.reply(t('method_disabled')) if func_disabled?(__method__)
80
+
81
+ org, repo = repo_match(response)
82
+
83
+ return response.reply(t('repo_delete.not_found', org: org, repo: repo)) unless repo?(rpo(org, repo))
84
+
85
+ response.reply(delete_repo(org, repo))
86
+ end
87
+
88
+ def repo_info(response)
89
+ org, repo = repo_match(response)
90
+ opts = {}
91
+ r_obj = octo.repository(rpo(org, repo))
92
+ p_obj = octo.pull_requests(rpo(org, repo))
93
+
94
+ opts[:repo] = r_obj[:full_name]
95
+ opts[:description] = r_obj[:description]
96
+ opts[:private] = r_obj[:private]
97
+ opts[:url] = r_obj[:html_url]
98
+ opts[:raw_issues_count] = r_obj[:open_issues_count]
99
+ opts[:pr_count] = p_obj.length
100
+ opts[:issues_count] = opts[:raw_issues_count] - opts[:pr_count]
101
+
102
+ response.reply(t('repo_info.reply', opts))
103
+ end
104
+
105
+ private
106
+
107
+ def command_opts(cmd)
108
+ o = {}
109
+ cmd.scan(LitaGithub::R::OPT_REGEX).flatten.compact.each do |opt|
110
+ k, v = opt.strip.split(':')
111
+ k = k.to_sym
112
+ o[k] = v unless o.key?(k)
113
+ end
114
+ o
115
+ end
116
+
117
+ def repo_match(response)
118
+ md = response.match_data
119
+ [organization(md['org']), md['repo']]
120
+ end
121
+
122
+ def extrapolate_create_opts(opts, org)
123
+ opts[:organization] = org
124
+
125
+ if opts.key?(:team)
126
+ opts[:team_id] = team_by_slug(opts[:team], org) || team_by_slug(config.default_team_slug, org)
127
+ else
128
+ opts[:team_id] = team_by_slug(config.default_team_slug, org)
129
+ end unless opts.key?(:team_id)
130
+ opts
131
+ end
132
+
133
+ def team_by_slug(slug, org)
134
+ octo.organization_teams(org).each do |team|
135
+ return team[:id] if team[:slug] == slug
136
+ end
137
+ nil
138
+ end
139
+
140
+ def should_repo_be_private?(value)
141
+ if value.nil? || value.empty?
142
+ config.repo_private_default
143
+ else
144
+ privacy_decider(value)
145
+ end
146
+ end
147
+
148
+ def privacy_decider(value)
149
+ case value.downcase
150
+ when 'true'
151
+ true
152
+ when 'false'
153
+ false
154
+ else # when some invalud value...
155
+ config.repo_private_default
156
+ end
157
+ end
158
+
159
+ def create_repo(org, repo, opts)
160
+ reply = nil
161
+ begin
162
+ octo.create_repository(repo, opts)
163
+ ensure
164
+ if repo?(rpo(org, repo))
165
+ repo_url = "https://github.com/#{rpo(org, repo)}"
166
+ reply = t('repo_create.pass', org: org, repo: repo, repo_url: repo_url)
167
+ else
168
+ reply = t('repo_create.fail', org: org, repo: repo)
169
+ end
170
+ end
171
+ reply
172
+ end
173
+
174
+ def delete_repo(org, repo)
175
+ reply = nil
176
+ begin
177
+ octo.delete_repository(rpo(org, repo))
178
+ ensure
179
+ if repo?(rpo(org, repo))
180
+ reply = t('repo_delete.fail', org: org, repo: repo)
181
+ else
182
+ reply = t('repo_delete.pass', org: org, repo: repo)
183
+ end
184
+ end
185
+ reply
186
+ end
187
+ end
188
+
189
+ Lita.register_handler(GithubRepo)
190
+ end
191
+ end
@@ -40,8 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency 'rubocop', '~> 0.25.0'
41
41
  s.add_development_dependency 'rspec', '~> 3.0'
42
42
  s.add_development_dependency 'fuubar', '~> 2.0'
43
- s.add_development_dependency 'coveralls', '~> 0.7'
44
- s.add_development_dependency 'simplecov', '~> 0.9'
43
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4', '>= 0.4.0'
45
44
 
46
45
  s.add_runtime_dependency 'lita', '~> 3.3'
47
46
  s.add_runtime_dependency 'octokit', '~> 3.3'
@@ -15,6 +15,7 @@ en:
15
15
  repo_delete:
16
16
  pass: "Deleted %{org}/%{repo}"
17
17
  fail: "Unable to delete %{org}/%{repo}"
18
+ not_found: "That repo (%{org}/%{repo}) does not exist"
18
19
  repo_info:
19
20
  reply: "%{repo} (private:%{private}) :: %{url}\nDesc: %{description}\nIssues: %{issues_count} PRs: %{pr_count}"
20
21
  github_pr:
@@ -16,12 +16,8 @@
16
16
 
17
17
  require 'rspec'
18
18
  require 'lita/rspec'
19
- # require 'coveralls'
20
- # require 'simplecov'
19
+ require 'codeclimate-test-reporter'
21
20
 
22
- # SimpleCov.formatter = Coveralls::SimpleCov::Formatter
23
- # SimpleCov.start do
24
- # add_filter 'spec/'
25
- # end
21
+ CodeClimate::TestReporter.start
26
22
 
27
23
  require 'lita-github'
@@ -0,0 +1,31 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe LitaGithub::Filters do
6
+ include LitaGithub::Filters
7
+
8
+ describe '.func_disabled?' do
9
+ before do
10
+ @cfg = double('Lita::Configuration', test_enabled: true)
11
+ allow(self).to receive(:config).and_return(@cfg)
12
+ end
13
+
14
+ context 'when enabled' do
15
+ it 'should return false' do
16
+ expect(func_disabled?(:test)).to be_falsey
17
+ end
18
+ end
19
+
20
+ context 'when disabled' do
21
+ before do
22
+ @cfg = double('Lita::Configuration', test_enabled: false)
23
+ allow(self).to receive(:config).and_return(@cfg)
24
+ end
25
+
26
+ it 'should return true' do
27
+ expect(func_disabled?(:test)).to be_truthy
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe LitaGithub::Org do
6
+ include LitaGithub::Org
7
+
8
+ describe '.organization' do
9
+ before do
10
+ @cfg = double('Lita::Config', default_org: 'GrapeDuty')
11
+ allow(self).to receive(:config).and_return(@cfg)
12
+ end
13
+
14
+ context 'when name provided is nil' do
15
+ it 'should use the default' do
16
+ expect(organization(nil)).to eql 'GrapeDuty'
17
+ end
18
+ end
19
+
20
+ context 'when name provided is empty string ("")' do
21
+ it 'should use the default' do
22
+ expect(organization('')).to eql 'GrapeDuty'
23
+ end
24
+ end
25
+
26
+ context 'when name provided is not nil or not empty string' do
27
+ it 'should use the name provided' do
28
+ expect(organization('testing')).to eql 'testing'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -46,25 +46,41 @@ describe LitaGithub::R do
46
46
 
47
47
  context 'it should match' do
48
48
  it 'test:pass' do
49
- expect(subject.match(' test:pass')).to_not be_nil
49
+ s = ' test:pass'
50
+ m = s.scan(subject).flatten.compact
51
+ expect(m).to eql [' test:pass']
50
52
  end
51
53
 
52
54
  it 'test7_pass:pAss_test' do
53
- expect(subject.match(' test7_pass:pAss_test')).to_not be_nil
55
+ s = ' test7_pass:pAss_test'
56
+ m = s.scan(subject).flatten.compact
57
+ expect(m).to eql [' test7_pass:pAss_test']
58
+ end
59
+
60
+ it 'test:pass bacon:always test:coverage' do
61
+ s = ' test:pass bacon:always test:coverage'
62
+ m = s.scan(subject).flatten.compact
63
+ expect(m).to eql [' test:pass', ' bacon:always', ' test:coverage']
54
64
  end
55
65
  end
56
66
 
57
67
  context 'it should not match' do
58
68
  it 'test-stuff:fail' do
59
- expect(subject.match(' test-stuff:fail')).to be_nil
69
+ s = ' test-stuff:fail'
70
+ m = s.scan(subject).flatten.compact
71
+ expect(m).to be_empty
60
72
  end
61
73
 
62
74
  it 'test: fail' do
63
- expect(subject.match(' test: fail')).to be_nil
75
+ s = ' test: fail'
76
+ m = s.scan(subject).flatten.compact
77
+ expect(m).to be_empty
64
78
  end
65
79
 
66
- it 'test:fail' do
67
- expect(subject.match('test:fail')).to be_nil
80
+ it 'test:fail (no leading space)' do
81
+ s = 'test:fail'
82
+ m = s.scan(subject).flatten.compact
83
+ expect(m).to be_empty
68
84
  end
69
85
  end
70
86
  end
@@ -0,0 +1,37 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe LitaGithub::Repo do
6
+ include LitaGithub::Repo
7
+
8
+ describe '.rpo' do
9
+ it 'should return the provided arguments in a Repo-like string' do
10
+ org = 'GrapeDuty'
11
+ repo = 'lita-test'
12
+ expect(rpo(org, repo)).to eql "#{org}/#{repo}"
13
+ end
14
+ end
15
+
16
+ describe '.repo?' do
17
+ before do
18
+ @octo = double('Octokit::Client', repository?: true)
19
+ allow(self).to receive(:octo).and_return(@octo)
20
+ end
21
+
22
+ context 'when repo exists' do
23
+ subject { repo?('GrapeDuty/lita-test') }
24
+ it { should be_truthy }
25
+ end
26
+
27
+ context 'when repo does not exist' do
28
+ before do
29
+ @octo = double('Octokit::Client', repository?: false)
30
+ allow(self).to receive(:octo).and_return(@octo)
31
+ end
32
+
33
+ subject { repo?('GrapeDuty/lita-test') }
34
+ it { should be_falsey }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,326 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright 2014 GrapeDuty, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'spec_helper'
18
+
19
+ describe Lita::Handlers::GithubRepo, lita_handler: true do
20
+ # repo_create command routing
21
+ it { routes_command('gh repo create GrapeDuty/lita-test').to(:repo_create) }
22
+ it { routes_command('gh repo new GrapeDuty/lita-test').to(:repo_create) }
23
+ it { routes_command('gh repo new lita-test').to(:repo_create) }
24
+ it { routes_command('gh repo new GrapeDuty/lita-test private:true team:heckman').to(:repo_create) }
25
+ it { routes_command('gh repo new GrapeDuty/lita-test private:true randomunparseabletext ').to(:repo_create) }
26
+
27
+ # repo_delete command routing
28
+ it { routes_command('gh repo delete GrapeDuty/lita-test').to(:repo_delete) }
29
+ it { routes_command('gh repo delete lita-test').to(:repo_delete) }
30
+
31
+ # repo_info command routing
32
+ it { routes_command('gh repo info GrapeDuty/lita-test').to(:repo_info) }
33
+ it { routes_command('gh repo info lita-test').to(:repo_info) }
34
+
35
+ let(:github_repo) { Lita::Handlers::GithubRepo.new('robot') }
36
+ let(:github_org) { 'GrapeDuty' }
37
+ let(:disabled_reply) { 'Sorry, this function has been disabled in the config' }
38
+
39
+ ####
40
+ # Helper Methods
41
+ ####
42
+ describe '.privacy_decider' do
43
+ before do
44
+ c_obj = double('Lita::Configuration', repo_private_default: :dummyvalue)
45
+ allow(github_repo).to receive(:config).and_return(c_obj)
46
+ end
47
+
48
+ it 'should return true when value is "true"' do
49
+ expect(github_repo.send(:privacy_decider, 'true')).to be_truthy
50
+ end
51
+
52
+ it 'should return true when value is "True"' do
53
+ expect(github_repo.send(:privacy_decider, 'True')).to be_truthy
54
+ end
55
+
56
+ it 'should return false when value is "false"' do
57
+ expect(github_repo.send(:privacy_decider, 'false')).to be_falsey
58
+ end
59
+
60
+ it 'should return the default when the value is something unknown' do
61
+ expect(github_repo.send(:privacy_decider, 'something')).to eql :dummyvalue
62
+ end
63
+ end
64
+
65
+ describe '.should_repo_be_private?' do
66
+ before do
67
+ @c_obj = double('Lita::Configuration', repo_private_default: true)
68
+ allow(github_repo).to receive(:config).and_return(@c_obj)
69
+ end
70
+
71
+ it 'should return the default if value nil' do
72
+ expect(@c_obj).to receive(:repo_private_default).and_return(:dummyvalue)
73
+ expect(github_repo.send(:should_repo_be_private?, nil)).to eql :dummyvalue
74
+ end
75
+
76
+ it 'should return the default if value empty string ("")' do
77
+ expect(@c_obj).to receive(:repo_private_default).and_return(:dummyvalue)
78
+ expect(github_repo.send(:should_repo_be_private?, '')).to eql :dummyvalue
79
+ end
80
+
81
+ it 'should call privacy_decider() with the value if not nil or empty' do
82
+ expect(github_repo).to receive(:privacy_decider).with('ohai').and_return(:dummyvalue)
83
+ expect(github_repo.send(:should_repo_be_private?, 'ohai')).to eql :dummyvalue
84
+ end
85
+ end
86
+
87
+ describe '.team_by_slug' do
88
+ before do
89
+ @teams = [
90
+ { id: 1, slug: 'hi' },
91
+ { id: 42, slug: 'heckman' },
92
+ { id: 84, slug: 'orwell' }
93
+ ]
94
+ @octo_obj = double('Octokit::Client', organization_teams: @teams)
95
+ allow(github_repo).to receive(:octo).and_return(@octo_obj)
96
+ end
97
+
98
+ it 'should return the team id of the team matching the slug' do
99
+ expect(@octo_obj).to receive(:organization_teams).with(github_org).and_return(@teams)
100
+ expect(github_repo.send(:team_by_slug, 'heckman', github_org)).to eql 42
101
+ expect(github_repo.send(:team_by_slug, 'orwell', github_org)).to eql 84
102
+ expect(github_repo.send(:team_by_slug, 'unknown', github_org)).to be_nil
103
+ end
104
+
105
+ it 'should return nil if unknown' do
106
+ expect(github_repo.send(:team_by_slug, 'unknown', 'x')).to be_nil
107
+ end
108
+ end
109
+
110
+ describe '.extrapolate_create_opts' do
111
+ before do
112
+ @eco_opts = {}
113
+ @c_obj = double('Lita::Configuration', default_team_slug: 'h3ckman')
114
+ allow(github_repo).to receive(:config).and_return(@c_obj)
115
+ allow(github_repo).to receive(:team_by_slug).and_return(42)
116
+ end
117
+
118
+ it 'should set the :organization key and :team_id key' do
119
+ h = { organization: github_org, team_id: 42 }
120
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
121
+ end
122
+
123
+ context 'when options contains :team and no :team_id' do
124
+ context 'when given a valid slug' do
125
+ before { @eco_opts = { team: 'heckman' } }
126
+
127
+ it 'should set the :team_id key' do
128
+ h = { organization: github_org, team_id: 84 }.merge!(@eco_opts)
129
+ expect(github_repo).to receive(:team_by_slug).with('heckman', github_org).and_return(84)
130
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
131
+ end
132
+ end
133
+
134
+ context 'when given an invalid slug' do
135
+ it 'should set the team to the default' do
136
+ h = { organization: github_org, team_id: 42 }.merge!(@eco_opts)
137
+ expect(github_repo).to receive(:team_by_slug).with('h3ckman', github_org).and_return(42)
138
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'when there is a :team_id key' do
144
+ before { @eco_opts = { team_id: 44 } }
145
+
146
+ it 'should just leave it alone...' do
147
+ h = { organization: github_org }.merge!(@eco_opts)
148
+ expect(github_repo).not_to receive(:team_by_slug)
149
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
150
+ end
151
+ end
152
+ end
153
+
154
+ describe '.repo_match' do
155
+ let(:resp_obj) do
156
+ md_mock = { 'org' => github_org, 'repo' => 'lita-test' }
157
+ double('Lita::Response', match_data: md_mock)
158
+ end
159
+
160
+ it 'should return the Org/Repo match' do
161
+ expect(github_repo.send(:repo_match, resp_obj)).to eql [github_org, 'lita-test']
162
+ end
163
+ end
164
+
165
+ describe '.command_opts' do
166
+ it 'should find the valid options' do
167
+ o = ' private:true team:heckman bacon:always bacon:sometimes'
168
+ co = github_repo.send(:command_opts, o)
169
+ expect(co).to be_an_instance_of Hash
170
+ expect(co[:private]).to eql 'true'
171
+ expect(co[:team]).to eql 'heckman'
172
+ expect(co[:bacon]).to eql 'always' # of course it's always
173
+ end
174
+ end
175
+
176
+ describe '.create_repo' do
177
+ before do
178
+ allow(github_repo).to receive(:octo).and_return(double('Octokit::Client', create_repository: nil))
179
+ end
180
+
181
+ context 'when repo created' do
182
+ before do
183
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
184
+ end
185
+
186
+ it 'should confirm succesfful creation' do
187
+ opts = { private: true, team_id: 42, organization: github_org }
188
+ expect(github_repo.send(:create_repo, github_org, 'lita-test', opts))
189
+ .to eql 'Created GrapeDuty/lita-test: https://github.com/GrapeDuty/lita-test'
190
+ end
191
+ end
192
+
193
+ context 'when repo not created' do
194
+ before do
195
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
196
+ end
197
+
198
+ it 'should confirm failure' do
199
+ opts = { private: true, team_id: 42, organization: github_org }
200
+ expect(github_repo.send(:create_repo, github_org, 'lita-test', opts))
201
+ .to eql 'Unable to create GrapeDuty/lita-test'
202
+ end
203
+ end
204
+ end
205
+
206
+ describe '.delete_repo' do
207
+ before do
208
+ allow(github_repo).to receive(:octo).and_return(double('Octokit::Client', delete_repository: nil))
209
+ end
210
+
211
+ context 'when repo deleted' do
212
+ before do
213
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
214
+ end
215
+
216
+ it 'should confirm successful delete' do
217
+ expect(github_repo.send(:delete_repo, github_org, 'lita-test'))
218
+ .to eql 'Deleted GrapeDuty/lita-test'
219
+ end
220
+ end
221
+
222
+ context 'when repo not deleted' do
223
+ before do
224
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
225
+ end
226
+
227
+ it 'should reply with failure message' do
228
+ expect(github_repo.send(:delete_repo, github_org, 'lita-test'))
229
+ .to eql 'Unable to delete GrapeDuty/lita-test'
230
+ end
231
+ end
232
+ end
233
+
234
+ ####
235
+ # Handlers
236
+ ####
237
+ describe '.repo_info' do
238
+ before do
239
+ repo = {
240
+ full_name: "#{github_org}/lita-test",
241
+ description: 'unit testing',
242
+ private: true,
243
+ html_url: "https://stubbed.github.com/#{github_org}/lita-test",
244
+ open_issues_count: 10
245
+ }
246
+ pr = [nil, nil, nil, nil, nil]
247
+ @octo_obj = double('Octokit::Client', repository: repo, pull_requests: pr)
248
+ allow(github_repo).to receive(:octo).and_return(@octo_obj)
249
+ end
250
+
251
+ it 'should return some repo info' do
252
+ send_command('gh repo info GrapeDuty/lita-test')
253
+ r = "GrapeDuty/lita-test (private:true) :: https://stubbed.github.com/#{github_org}/lita-test\n" \
254
+ "Desc: unit testing\n" \
255
+ 'Issues: 5 PRs: 5'
256
+ expect(replies.last).to eql r
257
+ end
258
+ end
259
+
260
+ describe '.repo_delete' do
261
+ before do
262
+ allow(github_repo).to receive(:func_disabled?).and_return(false)
263
+ allow(github_repo).to receive(:delete_repo).and_return('hello there')
264
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
265
+ end
266
+
267
+ it 'reply with the return from delete_repo()' do
268
+ send_command("gh repo delete #{github_org}/lita-test")
269
+ expect(replies.last).to eql 'hello there'
270
+ end
271
+
272
+ context 'when command disabled' do
273
+ before do
274
+ allow(github_repo).to receive(:func_disabled?).and_return(true)
275
+ end
276
+
277
+ it 'should no-op and say such if the command is disabled' do
278
+ send_command("gh repo delete #{github_org}/lita-test")
279
+ expect(replies.last).to eql disabled_reply
280
+ end
281
+ end
282
+
283
+ context 'when repo not found' do
284
+ before do
285
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
286
+ end
287
+
288
+ it 'should no-op informing you that the repo is not there' do
289
+ send_command("gh repo delete #{github_org}/lita-test")
290
+ expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) does not exist'
291
+ end
292
+ end
293
+ end
294
+
295
+ describe '.repo_create' do
296
+ before do
297
+ @opts = { private: true, team_id: 42, organization: github_org }
298
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
299
+ allow(github_repo).to receive(:extrapolate_create_opts).and_return(@opts)
300
+ allow(github_repo).to receive(:create_repo).and_return('hello from PAX prime!')
301
+ end
302
+
303
+ context 'when repo already exists' do
304
+ before do
305
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
306
+ end
307
+
308
+ it 'should tell you it already exists' do
309
+ send_command("gh repo create #{github_org}/lita-test")
310
+ expect(replies.last).to eql 'Unable to create GrapeDuty/lita-test as it already exists'
311
+ end
312
+ end
313
+
314
+ context 'when repo does not exist' do
315
+ before do
316
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
317
+ end
318
+
319
+ it 'should reply with the return of create_repo()' do
320
+ expect(github_repo).to receive(:extrapolate_create_opts).and_return(@opts)
321
+ send_command("gh repo create #{github_org}/lita-test")
322
+ expect(replies.last).to eql 'hello from PAX prime!'
323
+ end
324
+ end
325
+ end
326
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heckman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,33 +81,25 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: coveralls
84
+ name: codeclimate-test-reporter
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.7'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.7'
97
- - !ruby/object:Gem::Dependency
98
- name: simplecov
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
89
+ version: '0.4'
90
+ - - ">="
102
91
  - !ruby/object:Gem::Version
103
- version: '0.9'
92
+ version: 0.4.0
104
93
  type: :development
105
94
  prerelease: false
106
95
  version_requirements: !ruby/object:Gem::Requirement
107
96
  requirements:
108
97
  - - "~>"
109
98
  - !ruby/object:Gem::Version
110
- version: '0.9'
99
+ version: '0.4'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.4.0
111
103
  - !ruby/object:Gem::Dependency
112
104
  name: lita
113
105
  requirement: !ruby/object:Gem::Requirement
@@ -162,23 +154,30 @@ files:
162
154
  - ".rubocop.yml"
163
155
  - ".travis.yml"
164
156
  - Gemfile
165
- - Gemfile.lock
166
157
  - LICENSE
167
158
  - README.md
168
159
  - Rakefile
169
160
  - lib/lita-github.rb
170
161
  - lib/lita-github/config.rb
162
+ - lib/lita-github/filters.rb
171
163
  - lib/lita-github/octo.rb
164
+ - lib/lita-github/org.rb
172
165
  - lib/lita-github/r.rb
166
+ - lib/lita-github/repo.rb
173
167
  - lib/lita-github/version.rb
174
168
  - lib/lita/handlers/github.rb
169
+ - lib/lita/handlers/github_repo.rb
175
170
  - lita-github.gemspec
176
171
  - locales/en.yml
177
172
  - spec/spec_helper.rb
178
173
  - spec/unit/lita-github/config_spec.rb
174
+ - spec/unit/lita-github/filters_spec.rb
179
175
  - spec/unit/lita-github/octo_spec.rb
176
+ - spec/unit/lita-github/org_spec.rb
180
177
  - spec/unit/lita-github/r_spec.rb
178
+ - spec/unit/lita-github/repo_spec.rb
181
179
  - spec/unit/lita-github/version_spec.rb
180
+ - spec/unit/lita/handlers/github_repo_spec.rb
182
181
  - spec/unit/lita/handlers/github_spec.rb
183
182
  homepage: https://github.com/PagerDuty/lita-github
184
183
  licenses:
@@ -208,7 +207,11 @@ summary: GitHub repo/org management in Lita; handler not ready for production
208
207
  test_files:
209
208
  - spec/spec_helper.rb
210
209
  - spec/unit/lita-github/config_spec.rb
210
+ - spec/unit/lita-github/filters_spec.rb
211
211
  - spec/unit/lita-github/octo_spec.rb
212
+ - spec/unit/lita-github/org_spec.rb
212
213
  - spec/unit/lita-github/r_spec.rb
214
+ - spec/unit/lita-github/repo_spec.rb
213
215
  - spec/unit/lita-github/version_spec.rb
216
+ - spec/unit/lita/handlers/github_repo_spec.rb
214
217
  - spec/unit/lita/handlers/github_spec.rb
@@ -1,113 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- lita-github (0.0.1)
5
- lita (~> 3.3)
6
- lita-confirmation
7
- octokit (~> 3.3)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- addressable (2.3.6)
13
- ast (2.0.0)
14
- coveralls (0.7.0)
15
- multi_json (~> 1.3)
16
- rest-client
17
- simplecov (>= 0.7)
18
- term-ansicolor
19
- thor
20
- diff-lcs (1.2.5)
21
- docile (1.1.5)
22
- faraday (0.9.0)
23
- multipart-post (>= 1.2, < 3)
24
- fuubar (2.0.0)
25
- rspec (~> 3.0)
26
- ruby-progressbar (~> 1.4)
27
- http_router (0.11.1)
28
- rack (>= 1.0.0)
29
- url_mount (~> 0.2.1)
30
- i18n (0.6.11)
31
- ice_nine (0.11.0)
32
- lita (3.3.1)
33
- bundler (>= 1.3)
34
- faraday (>= 0.8.7)
35
- http_router (>= 0.11.1)
36
- i18n (>= 0.6.9)
37
- ice_nine (>= 0.11.0)
38
- multi_json (>= 1.7.7)
39
- puma (>= 2.7.1)
40
- rack (>= 1.5.2)
41
- rb-readline (>= 0.5.1)
42
- redis-namespace (>= 1.3.0)
43
- thor (>= 0.18.1)
44
- lita-confirmation (0.0.1)
45
- lita (>= 3.3)
46
- mime-types (2.3)
47
- multi_json (1.10.1)
48
- multipart-post (2.0.0)
49
- netrc (0.7.7)
50
- octokit (3.3.1)
51
- sawyer (~> 0.5.3)
52
- parser (2.2.0.pre.4)
53
- ast (>= 1.1, < 3.0)
54
- slop (~> 3.4, >= 3.4.5)
55
- powerpack (0.0.9)
56
- puma (2.9.0)
57
- rack (>= 1.1, < 2.0)
58
- rack (1.5.2)
59
- rainbow (2.0.0)
60
- rake (10.3.2)
61
- rb-readline (0.5.1)
62
- redis (3.1.0)
63
- redis-namespace (1.5.1)
64
- redis (~> 3.0, >= 3.0.4)
65
- rest-client (1.7.2)
66
- mime-types (>= 1.16, < 3.0)
67
- netrc (~> 0.7)
68
- rspec (3.0.0)
69
- rspec-core (~> 3.0.0)
70
- rspec-expectations (~> 3.0.0)
71
- rspec-mocks (~> 3.0.0)
72
- rspec-core (3.0.4)
73
- rspec-support (~> 3.0.0)
74
- rspec-expectations (3.0.4)
75
- diff-lcs (>= 1.2.0, < 2.0)
76
- rspec-support (~> 3.0.0)
77
- rspec-mocks (3.0.4)
78
- rspec-support (~> 3.0.0)
79
- rspec-support (3.0.4)
80
- rubocop (0.25.0)
81
- parser (>= 2.2.0.pre.4, < 3.0)
82
- powerpack (~> 0.0.6)
83
- rainbow (>= 1.99.1, < 3.0)
84
- ruby-progressbar (~> 1.4)
85
- ruby-progressbar (1.5.1)
86
- sawyer (0.5.5)
87
- addressable (~> 2.3.5)
88
- faraday (~> 0.8, < 0.10)
89
- simplecov (0.9.0)
90
- docile (~> 1.1.0)
91
- multi_json
92
- simplecov-html (~> 0.8.0)
93
- simplecov-html (0.8.0)
94
- slop (3.6.0)
95
- term-ansicolor (1.3.0)
96
- tins (~> 1.0)
97
- thor (0.19.1)
98
- tins (1.3.0)
99
- url_mount (0.2.1)
100
- rack
101
-
102
- PLATFORMS
103
- ruby
104
-
105
- DEPENDENCIES
106
- bundler (~> 1.5)
107
- coveralls (~> 0.7)
108
- fuubar (~> 2.0)
109
- lita-github!
110
- rake (~> 10.2)
111
- rspec (~> 3.0)
112
- rubocop (~> 0.25.0)
113
- simplecov (~> 0.9)