lita-github 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e0d281bcf8adc83548ac483d406f19672414bde
4
- data.tar.gz: 0324546f1f50adb9f70c9836ded9df84a18aaeba
3
+ metadata.gz: 2def5b26a94d3e8cc55f5c8da28109c7c04283a6
4
+ data.tar.gz: 019e7d005d5fa98459bd5fb36fcc24e1b36d34b9
5
5
  SHA512:
6
- metadata.gz: 4203c3537cd0084bb131f74ba86fc11f8dc01f2e0f6b8c319fb5e7d602e5999d2e206b123fb8f50aa4ee909d2f0492c7d0a7fb5e78755d698d0deb57317a711b
7
- data.tar.gz: 257b7734d642160b36f18fa567183da9bf2fb650d6f88efaad8b18d4e49c8d3d0beeec618e2569fd0dcf5261537641621e73ffad58dda3a96f53fc4fae7cde25
6
+ metadata.gz: 6afe9d22373957f410bb03af8530a367d00f81ebca9ec55d3cb5d698ae50d6cb55b89c05f85076ce21399d45200e5a95045f09e3dfa52c1c2fc610832a2dfa2f
7
+ data.tar.gz: bc8bf0a906252b8fc026e10ef798ac65a110c6be0ab99ccfdd664c688a2f43d4f244b106b2e3c66eabd220865a6671ef46f0cc236f2deb39f94c647e009a64a7
data/.travis.yml CHANGED
@@ -1,14 +1,13 @@
1
1
  branches:
2
2
  only:
3
3
  - master
4
+ sudo: false
4
5
  env: CODECLIMATE_REPO_TOKEN=3ffc4d9148b686fd07872259719fc6458a5521213e73e1f7b9db8546292f622a
5
6
  services:
6
7
  - redis-server
7
8
  language: ruby
8
9
  rvm:
10
+ - 2.2.2
11
+ - 2.2.1
9
12
  - 2.1.5
10
13
  - 2.1.4
11
- - 2.1.3
12
- - 2.1.2
13
- - 2.1.1
14
- - 2.1.0
data/README.md CHANGED
@@ -22,14 +22,14 @@ Configuration
22
22
  The configuration options will get their own in-depth doc a little further down the line. Here are the important ones for now:
23
23
 
24
24
  * `config.handlers.github.access_token = ''`
25
- * Your GitHUb access token (generated from Settings > Security > Personal Applications)
25
+ * Your GitHub access token (generated from Settings > Security > Personal Applications)
26
26
  * This is an administrative utility, so the token will need pretty wide access to leverage this plugin fully
27
27
  * `config.handlers.github.default_org = ''`
28
28
  * Your company may only have one organization, the handler will allow you to type just the repo name (`lita-github`) instead of `PagerDuty/lita-github`.
29
- * `config.handlers.github.default_team_slug = ''`
30
- * if no team is provided when adding a repo, it uses this team by default -- if unset, only owners can access repo
31
- * the default team that should be added to a repo based on the slug name:
32
- * When clicking on a team in your org you can use the URL to get the slug: https://github.com/orgs/<ORG>/teams/[slug]
29
+ * `config.handlers.github.default_team_slugs = ['']`
30
+ * if no team is provided when adding a repo, it uses these teams by default -- if unset, only owners can access repo
31
+ * the default teams that should be added to a repo based on the slug name:
32
+ * When clicking on a team in your org you can use the URL to get the slug: https://github.com/orgs/<ORG>/teams/[slug]
33
33
 
34
34
  Commands
35
35
  --------
data/Rakefile CHANGED
@@ -14,6 +14,7 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require 'bundler/gem_tasks'
17
18
  require 'rspec/core/rake_task'
18
19
  require 'rubocop/rake_task'
19
20
 
@@ -21,7 +21,7 @@
21
21
  # @author Tim Heckman <tim@pagerduty.com>
22
22
  module LitaGithub
23
23
  # lita-github version
24
- VERSION = '0.1.2'
24
+ VERSION = '0.2.0'
25
25
 
26
26
  # lita-github version split amongst different revisions
27
27
  MAJOR_VERSION, MINOR_VERSION, REVISION = VERSION.split('.').map(&:to_i)
@@ -68,7 +68,7 @@ module Lita
68
68
  def self.default_config(config)
69
69
  # when setting default configuration values please remember one thing:
70
70
  # secure and safe by default
71
- config.default_team_slug = nil
71
+ config.default_team_slugs = nil
72
72
  config.repo_private_default = true
73
73
  config.org_team_add_allowed_perms = %w(pull)
74
74
 
@@ -277,11 +277,14 @@ module Lita
277
277
  def extrapolate_create_opts(opts, org)
278
278
  opts[:organization] = org
279
279
 
280
- if opts.key?(:team)
281
- t_id = team_id_by_slug(opts[:team], org) || default_team(org)
282
- opts[:team_id] = t_id unless t_id.nil?
283
- else
284
- t_id = default_team(org)
280
+ first_team, other_teams = filter_teams(default_teams(org))
281
+
282
+ begin
283
+ t_id = team_id_by_slug(opts.fetch(:team), org)
284
+ rescue KeyError
285
+ t_id = first_team
286
+ opts[:other_teams] = other_teams unless other_teams.empty?
287
+ ensure
285
288
  opts[:team_id] = t_id unless t_id.nil?
286
289
  end unless opts.key?(:team_id)
287
290
 
@@ -290,8 +293,17 @@ module Lita
290
293
  opts
291
294
  end
292
295
 
293
- def default_team(org)
294
- config.default_team_slug.nil? ? nil : team_id_by_slug(config.default_team_slug, org)
296
+ def filter_teams(teams)
297
+ [teams.first, teams[1..-1].reject(&:nil?)] # Filter invalid team IDs
298
+ end
299
+
300
+ def default_teams(org)
301
+ teams = config.default_team_slugs
302
+ # If default_team_slugs is either a non-array (e.g. nil) or an empty
303
+ # array, return an array containing nil
304
+ return [nil] if !teams.is_a?(Array) || teams.empty?
305
+ # If it's a populated array, return an array of corresponding team IDs
306
+ teams.map { |team| team_id_by_slug(team, org) }
295
307
  end
296
308
 
297
309
  def should_repo_be_private?(value)
@@ -308,7 +320,7 @@ module Lita
308
320
  true
309
321
  when 'false'
310
322
  false
311
- else # when some invalud value...
323
+ else # when some invalid value...
312
324
  config.repo_private_default
313
325
  end
314
326
  end
@@ -318,6 +330,9 @@ module Lita
318
330
  reply = nil
319
331
  begin
320
332
  octo.create_repository(repo, opts)
333
+ opts[:other_teams].each do |team|
334
+ add_team_to_repo(full_name, team)
335
+ end if opts.key?(:other_teams)
321
336
  ensure
322
337
  if repo?(full_name)
323
338
  repo_url = "https://github.com/#{full_name}"
@@ -97,9 +97,9 @@ describe Lita::Handlers::GithubIssues, lita_handler: true do
97
97
  }
98
98
  ]
99
99
  @octo_obj = double('Octokit::Client', list_issues: issues)
100
- allow(github_issues).to receive(:octo).and_return(@octo_obj)
101
- allow(github_issues).to receive(:repo?).and_return(true)
102
- allow(github_issues).to receive(:validate_list_opts).and_return('')
100
+ allow_any_instance_of(Lita::Handlers::GithubIssues).to receive(:octo).and_return(@octo_obj)
101
+ allow_any_instance_of(Lita::Handlers::GithubIssues).to receive(:repo?).and_return(true)
102
+ allow_any_instance_of(Lita::Handlers::GithubIssues).to receive(:validate_list_opts).and_return('')
103
103
  end
104
104
 
105
105
  context 'when all goes well' do
@@ -123,7 +123,9 @@ GrapeDuty/lita-test #84: 'YZYZYZYZ' opened by theckman :: https://github.com/Gra
123
123
  end
124
124
 
125
125
  context 'when there is an option that fails validation' do
126
- before { allow(github_issues).to receive(:validate_list_opts).and_return('sadpanda') }
126
+ before do
127
+ allow_any_instance_of(Lita::Handlers::GithubIssues).to receive(:validate_list_opts).and_return('sadpanda')
128
+ end
127
129
 
128
130
  it 'should reply with the response from .validate_list_opts' do
129
131
  send_command('gh issues GrapeDuty/lita-test')
@@ -132,7 +134,9 @@ GrapeDuty/lita-test #84: 'YZYZYZYZ' opened by theckman :: https://github.com/Gra
132
134
  end
133
135
 
134
136
  context 'when the repo is not found' do
135
- before { allow(github_issues).to receive(:repo?).and_return(false) }
137
+ before do
138
+ allow_any_instance_of(Lita::Handlers::GithubIssues).to receive(:repo?).and_return(false)
139
+ end
136
140
 
137
141
  it 'should reply with response indicating repo not found' do
138
142
  send_command('gh issues GrapeDuty/lita-test')
@@ -141,7 +145,9 @@ GrapeDuty/lita-test #84: 'YZYZYZYZ' opened by theckman :: https://github.com/Gra
141
145
  end
142
146
 
143
147
  context 'when an option passes validation, but fails from GitHub' do
144
- before { allow(@octo_obj).to receive(:list_issues).and_raise(Octokit::UnprocessableEntity.new) }
148
+ before do
149
+ allow(@octo_obj).to receive(:list_issues).and_raise(Octokit::UnprocessableEntity.new)
150
+ end
145
151
 
146
152
  it 'should reply indicating an issue was hit and include the exception message' do
147
153
  send_command('gh issues GrapeDuty/lita-test')
@@ -151,7 +157,9 @@ Octokit::UnprocessableEntity"
151
157
  end
152
158
 
153
159
  context 'when there is a general error when calling GitHub' do
154
- before { allow(@octo_obj).to receive(:list_issues).and_raise(StandardError.new) }
160
+ before do
161
+ allow(@octo_obj).to receive(:list_issues).and_raise(StandardError.new)
162
+ end
155
163
 
156
164
  it 'should reply indicating an issue was hit and include the exception message' do
157
165
  send_command('gh issues GrapeDuty/lita-test')
@@ -135,8 +135,8 @@ describe Lita::Handlers::GithubOrg, lita_handler: true do
135
135
  ]
136
136
  conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty')
137
137
  @octo_obj = double('Octokit::Client', organization_teams: @teams)
138
- allow(github_org).to receive(:config).and_return(conf_obj)
139
- allow(github_org).to receive(:octo).and_return(@octo_obj)
138
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:config).and_return(conf_obj)
139
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:octo).and_return(@octo_obj)
140
140
  end
141
141
 
142
142
  context 'when provided a valid org' do
@@ -169,9 +169,9 @@ Name: HeckmanTest, Slug: heckmantest, ID: 42, Perms: push
169
169
  @octo_obj = double('Octokit::Client', create_team: @team)
170
170
  @perms = %w(pull push)
171
171
  @conf_obj = double('Lita::Config', org_team_add_allowed_perms: @perms)
172
- allow(github_org).to receive(:config).and_return(@conf_obj)
173
- allow(github_org).to receive(:func_disabled?).and_return(false)
174
- allow(github_org).to receive(:octo).and_return(@octo_obj)
172
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:config).and_return(@conf_obj)
173
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(false)
174
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:octo).and_return(@octo_obj)
175
175
  end
176
176
 
177
177
  context 'when all goes well' do
@@ -184,7 +184,9 @@ Name: HeckmanTest, Slug: heckmantest, ID: 42, Perms: push
184
184
  end
185
185
 
186
186
  context 'when the method is disabled' do
187
- before { allow(github_org).to receive(:func_disabled?).and_return(true) }
187
+ before do
188
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(true)
189
+ end
188
190
 
189
191
  it 'should return the method disabled error' do
190
192
  send_command('gh org team add GrapeDuty name:"HeckmanTest" perms:pull')
@@ -231,10 +233,10 @@ Missing the perms option
231
233
  before do
232
234
  @team = { name: 'HeckmanTest', id: 42, slug: 'heckmantest', permission: 'pull' }
233
235
  @octo_obj = double('Octokit::Client', delete_team: true)
234
- allow(github_org).to receive(:config).and_return(@conf_obj)
235
- allow(github_org).to receive(:func_disabled?).and_return(false)
236
- allow(github_org).to receive(:octo).and_return(@octo_obj)
237
- allow(github_org).to receive(:team?).with('42').and_return(@team)
236
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:config).and_return(@conf_obj)
237
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(false)
238
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:octo).and_return(@octo_obj)
239
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:team?).with('42').and_return(@team)
238
240
  end
239
241
 
240
242
  context 'when all goes well' do
@@ -245,7 +247,9 @@ Missing the perms option
245
247
  end
246
248
 
247
249
  context 'when the method is disabled' do
248
- before { allow(github_org).to receive(:func_disabled?).and_return(true) }
250
+ before do
251
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(true)
252
+ end
249
253
 
250
254
  it 'should return the method disabled error' do
251
255
  send_command('gh org team rm GrapeDuty 42')
@@ -254,7 +258,9 @@ Missing the perms option
254
258
  end
255
259
 
256
260
  context 'when the team does not exist' do
257
- before { allow(github_org).to receive(:team?).with('42').and_return(false) }
261
+ before do
262
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:team?).with('42').and_return(false)
263
+ end
258
264
 
259
265
  it 'should respond with the team not found error' do
260
266
  send_command('gh org team rm GrapeDuty 42')
@@ -289,9 +295,9 @@ Missing the perms option
289
295
  @conf_obj = double('Lita::Config', default_org: 'GrapeDuty')
290
296
  allow(@octo_obj).to receive(:user).with(no_args).and_return(@self_user)
291
297
  allow(@octo_obj).to receive(:user).with('theckman').and_return(@t_user)
292
- allow(github_org).to receive(:func_disabled?).and_return(false)
293
- allow(github_org).to receive(:octo).and_return(@octo_obj)
294
- allow(github_org).to receive(:cofig).and_return(@conf_obj)
298
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(false)
299
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:octo).and_return(@octo_obj)
300
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:cofig).and_return(@conf_obj)
295
301
  end
296
302
 
297
303
  context 'when all goes well' do
@@ -302,7 +308,9 @@ Missing the perms option
302
308
  end
303
309
 
304
310
  context 'when the method is disabled' do
305
- before { allow(github_org).to receive(:func_disabled?).and_return(true) }
311
+ before do
312
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(true)
313
+ end
306
314
 
307
315
  it 'should return the method disabled error' do
308
316
  send_command('gh org eject GrapeDuty theckman')
@@ -368,10 +376,10 @@ Missing the perms option
368
376
  @conf_obj = double('Lita::Config', default_org: 'GrapeDuty')
369
377
  allow(@octo_obj).to receive(:user).with(no_args).and_return(@self_user)
370
378
  allow(@octo_obj).to receive(:user).with('theckman').and_return(@t_user)
371
- allow(github_org).to receive(:func_disabled?).and_return(false)
372
- allow(github_org).to receive(:octo).and_return(@octo_obj)
373
- allow(github_org).to receive(:cofig).and_return(@conf_obj)
374
- allow(github_org).to receive(:team_id).and_return(42)
379
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(false)
380
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:octo).and_return(@octo_obj)
381
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:cofig).and_return(@conf_obj)
382
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:team_id).and_return(42)
375
383
  end
376
384
 
377
385
  context 'when all goes well' do
@@ -382,7 +390,9 @@ Missing the perms option
382
390
  end
383
391
 
384
392
  context 'when the method is disabled' do
385
- before { allow(github_org).to receive(:func_disabled?).and_return(true) }
393
+ before do
394
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(true)
395
+ end
386
396
 
387
397
  it 'should return the method disabled error' do
388
398
  send_command('gh org user add GrapeDuty heckmantest theckman')
@@ -448,10 +458,10 @@ Missing the perms option
448
458
  @conf_obj = double('Lita::Config', default_org: 'GrapeDuty')
449
459
  allow(@octo_obj).to receive(:user).with(no_args).and_return(@self_user)
450
460
  allow(@octo_obj).to receive(:user).with('theckman').and_return(@t_user)
451
- allow(github_org).to receive(:func_disabled?).and_return(false)
452
- allow(github_org).to receive(:octo).and_return(@octo_obj)
453
- allow(github_org).to receive(:cofig).and_return(@conf_obj)
454
- allow(github_org).to receive(:team_id).and_return(42)
461
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(false)
462
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:octo).and_return(@octo_obj)
463
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:cofig).and_return(@conf_obj)
464
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:team_id).and_return(42)
455
465
  end
456
466
 
457
467
  context 'when all goes well' do
@@ -462,7 +472,9 @@ Missing the perms option
462
472
  end
463
473
 
464
474
  context 'when the method is disabled' do
465
- before { allow(github_org).to receive(:func_disabled?).and_return(true) }
475
+ before do
476
+ allow_any_instance_of(Lita::Handlers::GithubOrg).to receive(:func_disabled?).and_return(true)
477
+ end
466
478
 
467
479
  it 'should return the method disabled error' do
468
480
  send_command('gh org user rm GrapeDuty heckmantest theckman')
@@ -52,7 +52,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
52
52
  describe '.merge_pr' do
53
53
  before do
54
54
  @octo_obj = double('Octokit::Client', merge_pull_request: :ohai)
55
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
55
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
56
56
  end
57
57
 
58
58
  let(:pr_num) { 42 }
@@ -167,7 +167,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
167
167
  @user_obj = { name: 'Tim Heckman' }
168
168
  @cs_obj = { state: 'success' }
169
169
  @octo_obj = double('Octokit::Client', user: @user_obj, combined_status: @cs_obj)
170
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
170
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
171
171
  end
172
172
 
173
173
  let(:pr_obj) do
@@ -217,7 +217,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
217
217
  context 'when user has no name set' do
218
218
  before do
219
219
  @octo_obj = double('Octokit::Client', user: {}, combined_status: @cs_obj)
220
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
220
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
221
221
  end
222
222
 
223
223
  it 'should not include the real name parenthesis' do
@@ -269,7 +269,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
269
269
  before do
270
270
  @user_obj = { name: 'Tim Heckman' }
271
271
  @octo_obj = double('Octokit::Client', user: @user_obj)
272
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
272
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
273
273
  end
274
274
 
275
275
  let(:pr_obj) do
@@ -320,7 +320,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
320
320
  before do
321
321
  @user_obj = {}
322
322
  @octo_obj = double('Octokit::Client', user: @user_obj)
323
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
323
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
324
324
  end
325
325
 
326
326
  it 'should set the :merged_by key without parenthesis' do
@@ -352,11 +352,11 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
352
352
 
353
353
  describe '.build_pr_info' do
354
354
  before do
355
- allow(github_pr).to receive(:build_pr_header!).and_return(nil)
356
- allow(github_pr).to receive(:build_pr_commitinfo!).and_return(nil)
357
- allow(github_pr).to receive(:build_pr_status!).and_return(nil)
358
- allow(github_pr).to receive(:build_pr_merge!).and_return(nil)
359
- allow(github_pr).to receive(:build_pr_comments!).and_return(nil)
355
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_header!).and_return(nil)
356
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_commitinfo!).and_return(nil)
357
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_status!).and_return(nil)
358
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_merge!).and_return(nil)
359
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_comments!).and_return(nil)
360
360
  end
361
361
 
362
362
  let(:pr_obj) { :ohai }
@@ -366,27 +366,27 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
366
366
  end
367
367
 
368
368
  it 'should call .build_pr_header!' do
369
- expect(github_pr).to receive(:build_pr_header!).with({}, pr_obj).and_return(nil)
369
+ expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_header!).with({}, pr_obj).and_return(nil)
370
370
  github_pr.send(:build_pr_info, pr_obj, full_name)
371
371
  end
372
372
 
373
373
  it 'should call .build_pr_commitinfo!' do
374
- expect(github_pr).to receive(:build_pr_commitinfo!).with({}, pr_obj).and_return(nil)
374
+ expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_commitinfo!).with({}, pr_obj).and_return(nil)
375
375
  github_pr.send(:build_pr_info, pr_obj, full_name)
376
376
  end
377
377
 
378
378
  it 'should call .build_pr_status!' do
379
- expect(github_pr).to receive(:build_pr_status!).with({}, pr_obj, full_name).and_return(nil)
379
+ expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_status!).with({}, pr_obj, full_name).and_return(nil)
380
380
  github_pr.send(:build_pr_info, pr_obj, full_name)
381
381
  end
382
382
 
383
383
  it 'should call .build_pr_merge!' do
384
- expect(github_pr).to receive(:build_pr_merge!).with({}, pr_obj).and_return(nil)
384
+ expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_merge!).with({}, pr_obj).and_return(nil)
385
385
  github_pr.send(:build_pr_info, pr_obj, full_name)
386
386
  end
387
387
 
388
388
  it 'should call .build_pr_comments!' do
389
- expect(github_pr).to receive(:build_pr_comments!).with({}, pr_obj).and_return(nil)
389
+ expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_comments!).with({}, pr_obj).and_return(nil)
390
390
  github_pr.send(:build_pr_info, pr_obj, full_name)
391
391
  end
392
392
  end
@@ -408,7 +408,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
408
408
  before do
409
409
  @merge_status = { sha: 'abc456', merged: true, message: 'Pull Request successfully merged' }
410
410
  @octo_obj = double('Octokit::Client', merge_pull_request: @merge_status)
411
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
411
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
412
412
  end
413
413
 
414
414
  context 'when all goes well' do
@@ -423,7 +423,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
423
423
  @merge_status = { sha: 'abc456', merged: false, message: '*BOOM*' }
424
424
  @octo_obj = double('Octokit::Client')
425
425
  allow(@octo_obj).to receive(:merge_pull_request).and_raise(StandardError.new)
426
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
426
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
427
427
  end
428
428
 
429
429
  it 'should return nil' do
@@ -445,8 +445,8 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
445
445
  review_comments: 2, comments: 1
446
446
  }
447
447
  @pr_resp = { fail: false, not_found: false, pr: @pr_info }
448
- allow(github_pr).to receive(:pull_request).and_return(@pr_resp)
449
- allow(github_pr).to receive(:build_pr_info).and_return(@pr_info)
448
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:pull_request).and_return(@pr_resp)
449
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_info).and_return(@pr_info)
450
450
  end
451
451
 
452
452
  it 'should reply with the expeced output' do
@@ -472,8 +472,8 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
472
472
  merged_by: 'theckman (Tim Heckman)', review_comments: 2, comments: 1
473
473
  }
474
474
  @pr_resp = { fail: false, not_found: false, pr: @pr_info }
475
- allow(github_pr).to receive(:pull_request).and_return(@pr_resp)
476
- allow(github_pr).to receive(:build_pr_info).and_return(@pr_info)
475
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:pull_request).and_return(@pr_resp)
476
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_info).and_return(@pr_info)
477
477
  end
478
478
 
479
479
  it 'should reply with the expeced output' do
@@ -492,7 +492,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
492
492
  context 'when the PR was not found' do
493
493
  before do
494
494
  @pr_resp = { fail: true, not_found: true, pr: @pr_info }
495
- allow(github_pr).to receive(:pull_request).and_return(@pr_resp)
495
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:pull_request).and_return(@pr_resp)
496
496
  end
497
497
 
498
498
  it 'should reply with the not found error' do
@@ -508,15 +508,15 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
508
508
  @pr_obj = { head: { ref: 'fix-some-bugs' }, title: 'fix bug' }
509
509
  @merge_status = { sha: 'abc456', merged: true, message: 'Pull Request successfully merged' }
510
510
  @octo_obj = double('Octokit::Client', pull_request: @pr_obj)
511
- allow(github_pr).to receive(:octo).and_return(@octo_obj)
512
- allow(github_pr).to receive(:func_disabled?).and_return(false)
513
- allow(github_pr).to receive(:config).and_return(@cfg_obj)
514
- allow(github_pr).to receive(:merge_pr).and_return(@merge_status)
511
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj)
512
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:func_disabled?).and_return(false)
513
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:config).and_return(@cfg_obj)
514
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).and_return(@merge_status)
515
515
  end
516
516
 
517
517
  context 'when command disabled' do
518
518
  before do
519
- allow(github_pr).to receive(:func_disabled?).and_return(true)
519
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:func_disabled?).and_return(true)
520
520
  end
521
521
 
522
522
  it 'should no-op and say such' do
@@ -538,7 +538,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
538
538
 
539
539
  context 'when merging should succeed' do
540
540
  it 'should set the right commit message' do
541
- expect(github_pr).to receive(:merge_pr).with(
541
+ expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).with(
542
542
  'GrapeDuty', 'lita-test', '42', "Merge pull request #42 from GrapeDuty/fix-some-bugs\n\nfix bug"
543
543
  )
544
544
  send_command('shipit GrapeDuty/lita-test #42')
@@ -554,7 +554,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
554
554
  context 'when merging bombs' do
555
555
  before do
556
556
  @merge_status = { sha: 'abc456', merged: false, message: '*BOOM*' }
557
- allow(github_pr).to receive(:merge_pr).and_return(@merge_status)
557
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).and_return(@merge_status)
558
558
  end
559
559
 
560
560
  it 'should confirm the failure' do
@@ -571,7 +571,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
571
571
  before do
572
572
  @merge_status = { sha: 'abc456', merged: false, message: '*BOOM*' }
573
573
  @octo_obj = double('Octokit::Client', pull_request: @pr_obj)
574
- allow(github_pr).to receive(:merge_pr).and_return(nil)
574
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).and_return(nil)
575
575
  end
576
576
 
577
577
  it 'should confirm the failure' do
@@ -589,8 +589,8 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
589
589
  before do
590
590
  cfg_obj = double('Lita::Configuration')
591
591
  octo_obj = double('Octokit::Client', pull_requests: [])
592
- allow(github_pr).to receive(:octo).and_return(octo_obj)
593
- allow(github_pr).to receive(:config).and_return(cfg_obj)
592
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(octo_obj)
593
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:config).and_return(cfg_obj)
594
594
  end
595
595
 
596
596
  context 'when there are no pull requests' do
@@ -607,7 +607,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
607
607
  { title: 'Test1', number: 42, html_url: 'htmlurl', user: { login: 'theckman' } }
608
608
  ]
609
609
  octo_obj = double('Octokit::Client', pull_requests: pr)
610
- allow(github_pr).to receive(:octo).and_return(octo_obj)
610
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(octo_obj)
611
611
  end
612
612
 
613
613
  it 'should reply with the PRs' do
@@ -643,7 +643,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
643
643
  { title: 'Test1', number: 42, html_url: 'xxx', user: { login: 'theckman' } }
644
644
  ]
645
645
  octo_obj = double('Octokit::Client', pull_requests: pr)
646
- allow(github_pr).to receive(:octo).and_return(octo_obj)
646
+ allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(octo_obj)
647
647
  end
648
648
 
649
649
  it 'should return the list of ten oldest & ten newest' do
@@ -128,125 +128,208 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
128
128
  end
129
129
  end
130
130
 
131
- describe '.default_team' do
131
+ describe '.default_teams' do
132
132
  before do
133
133
  allow(github_repo).to receive(:team_id_by_slug).and_return(88)
134
134
  end
135
135
 
136
- context 'when the default team slug is set' do
136
+ context 'when default_team_slugs is set' do
137
137
  before do
138
- cfg_obj = double('Lita::Configuration', default_team_slug: 'heckman')
138
+ cfg_obj = double('Lita::Configuration', default_team_slugs: ['heckman'])
139
139
  allow(github_repo).to receive(:config).and_return(cfg_obj)
140
140
  end
141
141
 
142
- it 'should return the team ID of the slug' do
142
+ it 'should return an array containing the team ID of the slug' do
143
143
  expect(github_repo).to receive(:team_id_by_slug).with('heckman', 'GrapeDuty')
144
144
  .and_return(42)
145
- expect(github_repo.send(:default_team, github_org)).to eql 42
145
+ expect(github_repo.send(:default_teams, github_org)).to eql [42]
146
146
  end
147
147
  end
148
148
 
149
- context 'when the default slug is not set' do
149
+ context 'when default_team_slugs is not set' do
150
150
  before do
151
- cfg_obj = double('Lita::Configuration', default_team_slug: nil)
151
+ cfg_obj = double('Lita::Configuration', default_team_slugs: nil)
152
152
  allow(github_repo).to receive(:config).and_return(cfg_obj)
153
153
  end
154
154
 
155
- it 'should return nil' do
156
- expect(github_repo.send(:default_team, github_org)).to be_nil
155
+ it 'should return [nil]' do
156
+ expect(github_repo.send(:default_teams, github_org)).to eql [nil]
157
157
  end
158
158
  end
159
- end
160
159
 
161
- describe '.extrapolate_create_opts' do
162
- before do
163
- @eco_opts = {}
164
- @c_obj = double('Lita::Configuration', default_team_slug: 'h3ckman')
165
- allow(github_repo).to receive(:config).and_return(@c_obj)
166
- allow(github_repo).to receive(:team_id_by_slug).and_return(42)
167
- allow(github_repo).to receive(:should_repo_be_private?).and_return(true)
168
- end
160
+ context 'when default_team_slugs is an empty array' do
161
+ before do
162
+ cfg_obj = double('Lita::Configuration', default_team_slugs: [])
163
+ allow(github_repo).to receive(:config).and_return(cfg_obj)
164
+ end
169
165
 
170
- it 'should set the :organization key, :team_id key, and :private key' do
171
- h = { organization: github_org, team_id: 42, private: true }
172
- expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
166
+ it 'should return [nil]' do
167
+ expect(github_repo.send(:default_teams, github_org)).to eql [nil]
168
+ end
173
169
  end
174
170
 
175
- it 'should set the private key to the return of should_repo_be_private?' do
176
- opts = { private: 'test', team_id: 42 }
177
- expect(github_repo).to receive(:should_repo_be_private?).with('test').and_return :ohai
178
- r = github_repo.send(:extrapolate_create_opts, opts, github_org)
179
- expect(r[:private]).to eql :ohai
171
+ context 'when default_team_slugs is set to an array with multiple elements' do
172
+ before do
173
+ cfg_obj = double('Lita::Configuration', default_team_slugs: %w(heckman orwell))
174
+ allow(github_repo).to receive(:config).and_return(cfg_obj)
175
+ end
176
+
177
+ it 'should return an array containing the corresponding team IDs' do
178
+ expect(github_repo).to receive(:team_id_by_slug).with('heckman', 'GrapeDuty')
179
+ .and_return(42)
180
+ expect(github_repo).to receive(:team_id_by_slug).with('orwell', 'GrapeDuty')
181
+ .and_return(84)
182
+ expect(github_repo.send(:default_teams, github_org)).to eql [42, 84]
183
+ end
180
184
  end
185
+ end
181
186
 
182
- context 'when there is no :team set' do
183
- context 'when default_team returns a team id' do
184
- it 'should get the default team_id' do
185
- h = { organization: github_org, team_id: 44, private: true }
186
- expect(github_repo).to receive(:default_team).with(github_org).and_return(44)
187
- expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
188
- end
187
+ describe '.extrapolate_create_opts' do
188
+ context 'when default_team_slugs is set' do
189
+ before do
190
+ @eco_opts = {}
191
+ @c_obj = double('Lita::Configuration', default_team_slugs: ['h3ckman'])
192
+ allow(github_repo).to receive(:config).and_return(@c_obj)
193
+ allow(github_repo).to receive(:team_id_by_slug).and_return(42)
194
+ allow(github_repo).to receive(:should_repo_be_private?).and_return(true)
189
195
  end
190
196
 
191
- context 'when default_team returns nil' do
192
- before do
193
- @c_obj = double('Lita::Configuration', default_team_slug: nil)
194
- allow(github_repo).to receive(:config).and_return(@c_obj)
195
- end
197
+ it 'should set the :organization key, :team_id key, and :private key' do
198
+ h = { organization: github_org, team_id: 42, private: true }
199
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
200
+ end
196
201
 
197
- it 'should not set the :team_id key' do
198
- h = { organization: github_org, private: true }
199
- expect(github_repo).to receive(:default_team).with(github_org).and_return(nil)
200
- expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
201
- end
202
+ it 'should set the private key to the return of should_repo_be_private?' do
203
+ opts = { private: 'test', team_id: 42 }
204
+ expect(github_repo).to receive(:should_repo_be_private?).with('test').and_return :ohai
205
+ r = github_repo.send(:extrapolate_create_opts, opts, github_org)
206
+ expect(r[:private]).to eql :ohai
202
207
  end
203
- end
204
208
 
205
- context 'when options contains :team and no :team_id' do
206
- context 'when given a valid slug' do
207
- before { @eco_opts = { team: 'heckman' } }
209
+ context 'when there is no :team set' do
210
+ context 'when default_teams returns an array containing a team id' do
211
+ it 'should get the default team_id' do
212
+ h = { organization: github_org, team_id: 44, private: true }
213
+ expect(github_repo).to receive(:default_teams).with(github_org).and_return([44])
214
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
215
+ end
216
+ end
208
217
 
209
- it 'should set the :team_id key' do
210
- h = { organization: github_org, team_id: 84, private: true }.merge!(@eco_opts)
211
- expect(github_repo).to receive(:team_id_by_slug).with('heckman', github_org).and_return(84)
212
- expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
218
+ context 'when default_teams returns [nil]' do
219
+ before do
220
+ @c_obj = double('Lita::Configuration', default_team_slugs: nil)
221
+ allow(github_repo).to receive(:config).and_return(@c_obj)
222
+ end
223
+
224
+ it 'should not set the :team_id key' do
225
+ h = { organization: github_org, private: true }
226
+ expect(github_repo).to receive(:default_teams).with(github_org).and_return([nil])
227
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
228
+ end
213
229
  end
214
230
  end
215
231
 
216
- context 'when given an invalid slug' do
217
- context 'when there is a default slug set' do
218
- it 'should set the team to the default' do
219
- h = { organization: github_org, team_id: 42, private: true }.merge!(@eco_opts)
220
- expect(github_repo).to receive(:team_id_by_slug).with('h3ckman', github_org).and_return(42)
232
+ context 'when options contains :team and no :team_id' do
233
+ context 'when given a valid slug' do
234
+ before { @eco_opts = { team: 'heckman' } }
235
+
236
+ it 'should set the :team_id key' do
237
+ h = { organization: github_org, team_id: 84, private: true }.merge!(@eco_opts)
238
+ expect(github_repo).to receive(:team_id_by_slug).with('heckman', github_org).and_return(84)
221
239
  expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
222
240
  end
223
241
  end
224
242
 
225
- context 'when there is no default slug set' do
226
- before do
227
- @eco_opts = { team: 'h3ckman', private: true }
228
- c_obj = double('Lita::Configuration', default_team_slug: nil)
229
- allow(github_repo).to receive(:config).and_return(c_obj)
243
+ context 'when given an invalid slug' do
244
+ context 'when there is a default slug set' do
245
+ it 'should set the team to the default' do
246
+ h = { organization: github_org, team_id: 42, private: true }.merge!(@eco_opts)
247
+ expect(github_repo).to receive(:team_id_by_slug).with('h3ckman', github_org).and_return(42)
248
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
249
+ end
230
250
  end
231
251
 
232
- it 'should not set a :team_id' do
233
- h = { organization: github_org }.merge!(@eco_opts)
234
- expect(github_repo).to receive(:team_id_by_slug).with('h3ckman', github_org)
235
- .and_return(nil)
236
- expect(github_repo).to receive(:default_team).with(github_org).and_call_original
237
- expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
252
+ context 'when there is no default slug set' do
253
+ before do
254
+ @eco_opts = { team: 'h3ckman', private: true }
255
+ c_obj = double('Lita::Configuration', default_team_slugs: nil)
256
+ allow(github_repo).to receive(:config).and_return(c_obj)
257
+ end
258
+
259
+ it 'should not set a :team_id' do
260
+ h = { organization: github_org }.merge!(@eco_opts)
261
+ expect(github_repo).to receive(:team_id_by_slug).with('h3ckman', github_org)
262
+ .and_return(nil)
263
+ expect(github_repo).to receive(:default_teams).with(github_org).and_call_original
264
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
265
+ end
238
266
  end
239
267
  end
240
268
  end
269
+
270
+ context 'when there is a :team_id key' do
271
+ before { @eco_opts = { team_id: 44, private: true } }
272
+
273
+ it 'should just leave it alone...' do
274
+ h = { organization: github_org }.merge!(@eco_opts)
275
+ expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
276
+ end
277
+ end
241
278
  end
242
279
 
243
- context 'when there is a :team_id key' do
244
- before { @eco_opts = { team_id: 44, private: true } }
280
+ context 'with an array of default teams' do
281
+ before do
282
+ allow(github_repo).to receive(:should_repo_be_private?).and_return(true)
283
+ end
245
284
 
246
- it 'should just leave it alone...' do
247
- h = { organization: github_org }.merge!(@eco_opts)
248
- expect(github_repo).not_to receive(:team_id_by_slug)
249
- expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
285
+ context 'consisting of a nil element' do
286
+ before do
287
+ allow(github_repo).to receive(:default_teams).with(github_org).and_return([nil])
288
+ end
289
+
290
+ it 'does not set :team_id' do
291
+ expect(github_repo.send(:extrapolate_create_opts, { private: true }, github_org)).to eql(organization: github_org, private: true)
292
+ end
293
+ end
294
+
295
+ context 'consisting of one valid team ID' do
296
+ before do
297
+ allow(github_repo).to receive(:default_teams).with(github_org).and_return([42])
298
+ end
299
+
300
+ it 'sets :team_id' do
301
+ expect(github_repo.send(:extrapolate_create_opts, { private: true }, github_org)).to eql(organization: github_org, team_id: 42, private: true)
302
+ end
303
+ end
304
+
305
+ context 'consisting of two valid team IDs' do
306
+ before do
307
+ allow(github_repo).to receive(:default_teams).with(github_org).and_return([42, 84])
308
+ end
309
+
310
+ it 'sets :team_id and :other_teams' do
311
+ expect(github_repo.send(:extrapolate_create_opts, { private: true }, github_org)).to eql(organization: github_org, team_id: 42, other_teams: [84], private: true)
312
+ end
313
+ end
314
+
315
+ context 'consisting of three valid team IDs' do
316
+ before do
317
+ allow(github_repo).to receive(:default_teams).with(github_org).and_return([42, 84, 1])
318
+ end
319
+
320
+ it 'sets :team_id and :other_teams' do
321
+ expect(github_repo.send(:extrapolate_create_opts, { private: true }, github_org)).to eql(organization: github_org, team_id: 42, other_teams: [84, 1], private: true)
322
+ end
323
+ end
324
+
325
+ context 'consisting of one valid team ID and one invalid team ID' do
326
+ before do
327
+ allow(github_repo).to receive(:default_teams).with(github_org).and_return([42, nil])
328
+ end
329
+
330
+ it 'sets :team_id but not :other_teams' do
331
+ expect(github_repo.send(:extrapolate_create_opts, { private: true }, github_org)).to eql(organization: github_org, team_id: 42, private: true)
332
+ end
250
333
  end
251
334
  end
252
335
  end
@@ -261,11 +344,20 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
261
344
  allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
262
345
  end
263
346
 
264
- it 'should confirm succesfful creation' do
347
+ it 'should confirm successful creation' do
265
348
  opts = { private: true, team_id: 42, organization: github_org }
266
349
  expect(github_repo.send(:create_repo, github_org, 'lita-test', opts))
267
350
  .to eql 'Created GrapeDuty/lita-test: https://github.com/GrapeDuty/lita-test'
268
351
  end
352
+
353
+ context 'when other teams are given' do
354
+ it 'should add teams to the repo after creating it' do
355
+ expect(github_repo).to receive(:add_team_to_repo).with('GrapeDuty/lita-test', 42)
356
+ expect(github_repo).to receive(:add_team_to_repo).with('GrapeDuty/lita-test', 84)
357
+ opts = { private: true, team_id: 1, other_teams: [42, 84], organization: github_org }
358
+ github_repo.send(:create_repo, github_org, 'lita-test', opts)
359
+ end
360
+ end
269
361
  end
270
362
 
271
363
  context 'when repo not created' do
@@ -562,10 +654,10 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
562
654
  conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty')
563
655
  @response = double('Lita::Response', match_data: match_data)
564
656
  @octo_obj = double('Octokit::Client', edit_repository: { description: 'oh hello' })
565
- allow(github_repo).to receive(:config).and_return(conf_obj)
566
- allow(github_repo).to receive(:octo).and_return(@octo_obj)
567
- allow(github_repo).to receive(:func_disabled?).and_return(false)
568
- allow(github_repo).to receive(:repo?).and_return(true)
657
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:config).and_return(conf_obj)
658
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(false)
659
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).and_return(true)
660
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:octo).and_return(@octo_obj)
569
661
  end
570
662
 
571
663
  context 'when valid inputs provided, and all things work out' do
@@ -576,7 +668,9 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
576
668
  end
577
669
 
578
670
  context 'when function disabled' do
579
- before { allow(github_repo).to receive(:func_disabled?).and_return(true) }
671
+ before do
672
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(true)
673
+ end
580
674
 
581
675
  it 'should return the method disabled error' do
582
676
  send_command('gh repo update description lita-test A new description!')
@@ -585,7 +679,9 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
585
679
  end
586
680
 
587
681
  context 'when repo not found' do
588
- before { allow(github_repo).to receive(:repo?).and_return(false) }
682
+ before do
683
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).and_return(false)
684
+ end
589
685
 
590
686
  it 'should return the repo not found error' do
591
687
  send_command('gh repo update description lita-test A new description!')
@@ -612,10 +708,10 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
612
708
  conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty')
613
709
  @response = double('Lita::Response', match_data: match_data)
614
710
  @octo_obj = double('Octokit::Client', edit_repository: { homepage: 'https://test.it' })
615
- allow(github_repo).to receive(:config).and_return(conf_obj)
616
- allow(github_repo).to receive(:octo).and_return(@octo_obj)
617
- allow(github_repo).to receive(:func_disabled?).and_return(false)
618
- allow(github_repo).to receive(:repo?).and_return(true)
711
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:config).and_return(conf_obj)
712
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:octo).and_return(@octo_obj)
713
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(false)
714
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).and_return(true)
619
715
  end
620
716
 
621
717
  context 'when valid inputs provided, and all things work out' do
@@ -626,7 +722,9 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
626
722
  end
627
723
 
628
724
  context 'when function disabled' do
629
- before { allow(github_repo).to receive(:func_disabled?).and_return(true) }
725
+ before do
726
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(true)
727
+ end
630
728
 
631
729
  it 'should return the method disabled error' do
632
730
  send_command('gh repo update homepage lita-test https://test.it')
@@ -635,7 +733,9 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
635
733
  end
636
734
 
637
735
  context 'when repo not found' do
638
- before { allow(github_repo).to receive(:repo?).and_return(false) }
736
+ before do
737
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).and_return(false)
738
+ end
639
739
 
640
740
  it 'should return the repo not found error' do
641
741
  send_command('gh repo update homepage lita-test https://test.it')
@@ -685,7 +785,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
685
785
  }
686
786
  pr = [nil, nil, nil, nil, nil]
687
787
  @octo_obj = double('Octokit::Client', repository: repo, pull_requests: pr)
688
- allow(github_repo).to receive(:octo).and_return(@octo_obj)
788
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:octo).and_return(@octo_obj)
689
789
  end
690
790
 
691
791
  it 'should return some repo info' do
@@ -699,9 +799,9 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
699
799
 
700
800
  describe '.repo_delete' do
701
801
  before do
702
- allow(github_repo).to receive(:func_disabled?).and_return(false)
703
- allow(github_repo).to receive(:delete_repo).and_return('hello there')
704
- allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
802
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(false)
803
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:delete_repo).and_return('hello there')
804
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
705
805
  end
706
806
 
707
807
  it 'reply with the return from delete_repo()' do
@@ -711,7 +811,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
711
811
 
712
812
  context 'when command disabled' do
713
813
  before do
714
- allow(github_repo).to receive(:func_disabled?).and_return(true)
814
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(true)
715
815
  end
716
816
 
717
817
  it 'should no-op and say such if the command is disabled' do
@@ -722,7 +822,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
722
822
 
723
823
  context 'when repo not found' do
724
824
  before do
725
- allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
825
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
726
826
  end
727
827
 
728
828
  it 'should no-op informing you that the repo is not there' do
@@ -735,15 +835,15 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
735
835
  describe '.repo_create' do
736
836
  before do
737
837
  @opts = { private: true, team_id: 42, organization: github_org }
738
- allow(github_repo).to receive(:func_disabled?).and_return(false)
739
- allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
740
- allow(github_repo).to receive(:extrapolate_create_opts).and_return(@opts)
741
- allow(github_repo).to receive(:create_repo).and_return('hello from PAX prime!')
838
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(false)
839
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
840
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:extrapolate_create_opts).and_return(@opts)
841
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:create_repo).and_return('hello from PAX prime!')
742
842
  end
743
843
 
744
844
  context 'when command disabled' do
745
845
  before do
746
- allow(github_repo).to receive(:func_disabled?).and_return(true)
846
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(true)
747
847
  end
748
848
 
749
849
  it 'should no-op and say such if the command is disabled' do
@@ -754,7 +854,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
754
854
 
755
855
  context 'when repo already exists' do
756
856
  before do
757
- allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
857
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
758
858
  end
759
859
 
760
860
  it 'should tell you it already exists' do
@@ -765,11 +865,11 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
765
865
 
766
866
  context 'when repo does not exist' do
767
867
  before do
768
- allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
868
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
769
869
  end
770
870
 
771
871
  it 'should reply with the return of create_repo()' do
772
- expect(github_repo).to receive(:extrapolate_create_opts).and_return(@opts)
872
+ expect_any_instance_of(Lita::Handlers::GithubRepo).to receive(:extrapolate_create_opts).and_return(@opts)
773
873
  send_command("gh repo create #{github_org}/lita-test")
774
874
  expect(replies.last).to eql 'hello from PAX prime!'
775
875
  end
@@ -778,9 +878,9 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
778
878
 
779
879
  describe '.repo_rename' do
780
880
  before do
781
- allow(github_repo).to receive(:func_disabled?).and_return(false)
782
- allow(github_repo).to receive(:rename_repo).and_return('hello there')
783
- allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
881
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(false)
882
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:rename_repo).and_return('hello there')
883
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
784
884
  end
785
885
 
786
886
  it 'reply with the return from rename_repo()' do
@@ -790,7 +890,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
790
890
 
791
891
  context 'when command disabled' do
792
892
  before do
793
- allow(github_repo).to receive(:func_disabled?).and_return(true)
893
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:func_disabled?).and_return(true)
794
894
  end
795
895
 
796
896
  it 'should no-op and say such if the command is disabled' do
@@ -801,7 +901,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
801
901
 
802
902
  context 'when repo not found' do
803
903
  before do
804
- allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
904
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
805
905
  end
806
906
 
807
907
  it 'should no-op informing you that the repo is not there' do
@@ -818,7 +918,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
818
918
  { name: 'Everyone', slug: 'everyone', id: 42, permission: 'push' }
819
919
  ]
820
920
  @octo_obj = double('Octokit::Client', repository_teams: @teams)
821
- allow(github_repo).to receive(:octo).and_return(@octo_obj)
921
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:octo).and_return(@octo_obj)
822
922
  end
823
923
 
824
924
  context 'when it finds a repo' do
@@ -853,11 +953,11 @@ Name: Interns, Slug: interns, ID: 84, Perms: pull
853
953
 
854
954
  describe '.repo_team_router' do
855
955
  before do
856
- allow(github_repo).to receive(:repo_team_add).with(an_instance_of(Lita::Response)).and_return('ohai')
956
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo_team_add).with(an_instance_of(Lita::Response)).and_return('ohai')
857
957
  end
858
958
 
859
959
  it 'should call the method based on action and respond with its return' do
860
- expect(github_repo).to receive(:repo_team_add).with(an_instance_of(Lita::Response)).and_return('ohai')
960
+ expect_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo_team_add).with(an_instance_of(Lita::Response)).and_return('ohai')
861
961
  send_command("gh repo team add 42 #{github_org}/lita-test")
862
962
  expect(replies.last).to eql 'ohai'
863
963
  end
@@ -865,11 +965,11 @@ Name: Interns, Slug: interns, ID: 84, Perms: pull
865
965
 
866
966
  describe '.repo_update_router' do
867
967
  before do
868
- allow(github_repo).to receive(:repo_update_description).with(an_instance_of(Lita::Response)).and_return('ohai')
968
+ allow_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo_update_description).with(an_instance_of(Lita::Response)).and_return('ohai')
869
969
  end
870
970
 
871
971
  it 'should call the method based on the action and respond with its return' do
872
- expect(github_repo).to receive(:repo_update_description).with(an_instance_of(Lita::Response)).and_return('ohai')
972
+ expect_any_instance_of(Lita::Handlers::GithubRepo).to receive(:repo_update_description).with(an_instance_of(Lita::Response)).and_return('ohai')
873
973
  send_command("gh repo update description #{github_org}/lita-test Something funky here")
874
974
  expect(replies.last).to eql 'ohai'
875
975
  end
@@ -300,7 +300,7 @@ Following: 20, Followers: 10, Joined: 2011-05-14 04:16:33 UTC'
300
300
  before do
301
301
  @secret = 'GZSDEMLDMY3TQYLG'
302
302
  conf_obj = double('Lita::Configuration', totp_secret: @secret)
303
- allow(github).to receive(:config).and_return(conf_obj)
303
+ allow_any_instance_of(Lita::Handlers::Github).to receive(:config).and_return(conf_obj)
304
304
  end
305
305
 
306
306
  context 'when token is set' do
@@ -314,7 +314,7 @@ Following: 20, Followers: 10, Joined: 2011-05-14 04:16:33 UTC'
314
314
  context 'when token is not set' do
315
315
  before do
316
316
  conf_obj = double('Lita::Configuration', totp_secret: nil)
317
- allow(github).to receive(:config).and_return(conf_obj)
317
+ allow_any_instance_of(Lita::Handlers::Github).to receive(:config).and_return(conf_obj)
318
318
  end
319
319
 
320
320
  it 'should return the error message' do
@@ -344,15 +344,15 @@ Following: 20, Followers: 10, Joined: 2011-05-14 04:16:33 UTC'
344
344
  }
345
345
  @orgs = [{ login: 'PagerDuty' }, { login: 'GrapeDuty' }]
346
346
  @octo_obj = double('Octokit::Client', user: @user_obj, organizations: @orgs)
347
- allow(github).to receive(:octo).and_return(@octo_obj)
348
- allow(github).to receive(:whois_reply).and_return('StubbedResponse')
347
+ allow_any_instance_of(Lita::Handlers::Github).to receive(:octo).and_return(@octo_obj)
348
+ allow_any_instance_of(Lita::Handlers::Github).to receive(:whois_reply).and_return('StubbedResponse')
349
349
  end
350
350
 
351
351
  context 'when all goes well' do
352
352
  it 'should return the response from whois_reply' do
353
353
  expect(@octo_obj).to receive(:user).with('theckman').and_return(@user_obj)
354
354
  expect(@octo_obj).to receive(:organizations).with('theckman').and_return(@orgs)
355
- expect(github).to receive(:whois_reply).with(@user_obj, %w(PagerDuty GrapeDuty)).and_return('StubbedResponse')
355
+ allow_any_instance_of(Lita::Handlers::Github).to receive(:whois_reply).with(@user_obj, %w(PagerDuty GrapeDuty)).and_return('StubbedResponse')
356
356
  send_command('gh whois theckman')
357
357
  expect(replies.last).to eql 'StubbedResponse'
358
358
  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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heckman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  version: '0'
258
258
  requirements: []
259
259
  rubyforge_project:
260
- rubygems_version: 2.4.3
260
+ rubygems_version: 2.4.5
261
261
  signing_key:
262
262
  specification_version: 4
263
263
  summary: GitHub repo/org management in Lita; handler not ready for production