lita-github 0.0.9 → 0.0.10

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: bb3cd200b9fc34080456111f08e27e79a3297311
4
- data.tar.gz: eedcd297373ba3f19afe00e3ef460e8cf9248829
3
+ metadata.gz: 0edd68ade3e5fc642ccb5e606a94b09d40e08d8f
4
+ data.tar.gz: 8461b46c716ea556aa2c7cf50db4f91c994d91a6
5
5
  SHA512:
6
- metadata.gz: dfb028a7d353c084a53a9f9ed6c0811dc78850cad2eaf58f74cb00ab87be8d4f3cecb613a5369d3957ac237822c2207fd1d1af0dbce079c927018d11c1a949ef
7
- data.tar.gz: 85f39a45bf8bc5e1b0a1b1308472e8dc5bf5a33c9033691b98ac30876813c36779246786a4cf5300766054db16d712981ace7bcd4143263ca6ced2d60b98c37c
6
+ metadata.gz: 4842ed8a61059de7b651561966c2f074f223c1cc1489ecd92f379dad78ac6c19e5d3d5d7eb727d5254eb4125450e486847aa5a144c9520bff9cdf287ae1aaa01
7
+ data.tar.gz: d3f24df978afe5d70bd924c8c6165c391b225d55af099c684c06549d3bb615fea9dc73ebd0fe668cfb5b3c0e5ea8e7854b4079c96ec8639968dcec995e73f4e6
data/README.md CHANGED
@@ -63,6 +63,10 @@ Here is the current functionality:
63
63
  * adds the team to the repo -- requires confirmation and enabling via config option (`repo_team_add_enabled = true`)
64
64
  * `!gh repo team rm <TEAM_ID|TEAM_SLUG> PagerDuty/lita-github`
65
65
  * removes the team to the repo -- requires confirmation and enabling via config option (`repo_team_rm_enabled = true`)
66
+ * `!gh repo update description PagerDuty/lita-github The new lita-github description!`
67
+ * update the description of the repo, can be disabled with: `repo_update_description_enabled = false`
68
+ * `!gh repo update homepage lita-github https://github.com/PagerDuty/lita-github`
69
+ * update the homepage of the repo, can be disabled with: `repo_update_homepage_enabled = false`
66
70
 
67
71
  ### Github PR Handler
68
72
  * `!gh pr info PagerDuty/lita-github #42`
@@ -16,6 +16,6 @@
16
16
 
17
17
  # Administer your Hub of Gits with Lita!
18
18
  module LitaGithub
19
- VERSION = '0.0.9'
19
+ VERSION = '0.0.10'
20
20
  MAJ, MIN, REV = VERSION.split('.').map(&:to_i)
21
21
  end
@@ -70,10 +70,12 @@ module Lita
70
70
  config.totp_secret = nil
71
71
 
72
72
  # Lita::Handlers::GithubRepo
73
- config.repo_create_enabled = true
74
- config.repo_delete_enabled = false
75
- config.repo_team_add_enabled = false
76
- config.repo_team_rm_enabled = false
73
+ config.repo_create_enabled = true
74
+ config.repo_delete_enabled = false
75
+ config.repo_team_add_enabled = false
76
+ config.repo_team_rm_enabled = false
77
+ config.repo_update_description_enabled = true
78
+ config.repo_update_homepage_enabled = true
77
79
 
78
80
  # Lita::Handlers::GithubPR
79
81
  config.pr_merge_enabled = true
@@ -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 'uri'
17
18
  require 'lita-github/r'
18
19
  require 'lita-github/config'
19
20
  require 'lita-github/octo'
@@ -84,6 +85,14 @@ module Lita
84
85
  'gh repo team rm 42 PagerDuty/lita-test' => 'remove a team using ID to your repo'
85
86
  }
86
87
  )
88
+
89
+ route(
90
+ /#{LitaGithub::R::A_REG}repo\s+update\s+?(?<field>description|homepage)\s+?#{LitaGithub::R::REPO_REGEX}\s+?(?<content>.*)$/,
91
+ :repo_update_router, command: true, confirmation: true,
92
+ help: {
93
+ 'gh repo description PagerDuty/lita-github' => 'get the repo description'
94
+ }
95
+ )
87
96
  # rubocop:enable Metrics/LineLength
88
97
 
89
98
  def repo_create(response)
@@ -150,10 +159,15 @@ module Lita
150
159
  end
151
160
 
152
161
  def repo_team_router(response)
153
- action = response.match_data['action']
162
+ action = response.match_data['action'].strip
154
163
  response.reply(send("repo_team_#{action}".to_sym, response))
155
164
  end
156
165
 
166
+ def repo_update_router(response)
167
+ field = response.match_data['field'].strip
168
+ response.reply(send("repo_update_#{field}".to_sym, response))
169
+ end
170
+
157
171
  private
158
172
 
159
173
  def repo_team_add(response)
@@ -190,6 +204,47 @@ module Lita
190
204
  remove_team_from_repo(full_name, team)
191
205
  end
192
206
 
207
+ def repo_update_description(response)
208
+ return t('method_disabled') if func_disabled?(__method__)
209
+ md = response.match_data
210
+ org, repo = repo_match(md)
211
+ full_name = rpo(org, repo)
212
+
213
+ return t('not_found', org: org, repo: repo) unless repo?(full_name)
214
+
215
+ content = md['content'].strip
216
+
217
+ begin
218
+ resp = octo.edit_repository(full_name, description: content)
219
+ rescue StandardError
220
+ return t('repo_update_description.boom', repo: full_name)
221
+ end
222
+
223
+ t('repo_update_description.updated', repo: full_name, desc: resp[:description])
224
+ end
225
+
226
+ def repo_update_homepage(response)
227
+ return t('method_disabled') if func_disabled?(__method__)
228
+ md = response.match_data
229
+ org, repo = repo_match(md)
230
+ full_name = rpo(org, repo)
231
+
232
+ return t('not_found', org: org, repo: repo) unless repo?(full_name)
233
+
234
+ regexp = URI::DEFAULT_PARSER.regexp[:ABS_URI]
235
+ content = md['content'].strip
236
+
237
+ return t('repo_update_homepage.invalid_url', url: content) unless regexp.match(content)
238
+
239
+ begin
240
+ resp = octo.edit_repository(full_name, homepage: content)
241
+ rescue StandardError
242
+ return t('repo_update_homepage.boom', repo: full_name)
243
+ end
244
+
245
+ t('repo_update_homepage.updated', repo: full_name, url: resp[:homepage])
246
+ end
247
+
193
248
  def command_opts(cmd)
194
249
  o = {}
195
250
  cmd.scan(LitaGithub::R::OPT_REGEX).flatten.compact.each do |opt|
@@ -11,7 +11,7 @@ en:
11
11
  totp: "%{token}"
12
12
  github_repo:
13
13
  method_disabled: "Sorry, this function has either been disabled or not enabled in the config"
14
- not_found: "That repo (%{org}/%{repo}) does not exist"
14
+ not_found: "That repo (%{org}/%{repo}) was not found"
15
15
  team_not_found: "Unable to match any teams based on: %{team}"
16
16
  repo_create:
17
17
  pass: "Created %{org}/%{repo}: %{repo_url}"
@@ -34,6 +34,13 @@ en:
34
34
  pass: "Removed the '%{team}' team from %{repo}"
35
35
  fail: "Something went wrong trying to remove the '%{team}' team from %{repo}"
36
36
  exists: "The '%{team}' team is not a member of %{repo}"
37
+ repo_update_description:
38
+ updated: "The description for %{repo} has been updated to: '%{desc}'"
39
+ boom: "An uncaught exception was hit while trying to update the description of %{repo}. Is GitHub having issues?"
40
+ repo_update_homepage:
41
+ updated: "The homepage for %{repo} has been updated to: '%{url}'"
42
+ invalid_url: "The URL provided is not valid: '%{url}'"
43
+ boom: "An uncaught exception was hit while trying to update the homepage of %{repo}. Is GitHub having issues?"
37
44
  github_pr:
38
45
  method_disabled: "Sorry, this function has either been disabled or not enabled in the config"
39
46
  exception: "An unexpected exception was hit during the GitHub API operation. Please make sure all arguments are proper and try again, or try checking the GitHub status (gh status)"
@@ -56,6 +56,20 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
56
56
  it { routes_command('gh repo team rm 42 lita-test').to(:repo_team_router) }
57
57
  it { routes_command('gh repo team rm 42 to lita-test').to(:repo_team_router) }
58
58
 
59
+ # repo_update_router routing
60
+ it do
61
+ routes_command(
62
+ 'gh repo update homepage GrapeDuty/lita-test https://github.com/GrapeDuty/lita-test'
63
+ ).to(:repo_update_router)
64
+ end
65
+ it do
66
+ routes_command(
67
+ 'gh repo update homepage lita-test https://github.com/GrapeDuty/lita-test'
68
+ ).to(:repo_update_router)
69
+ end
70
+ it { routes_command('gh repo update description GrapeDuty/lita-test Some description here').to(:repo_update_router) }
71
+ it { routes_command('gh repo update description lita-test Some description here').to(:repo_update_router) }
72
+
59
73
  let(:github_repo) { Lita::Handlers::GithubRepo.new('robot') }
60
74
  let(:github_org) { 'GrapeDuty' }
61
75
  let(:disabled_reply) { 'Sorry, this function has either been disabled or not enabled in the config' }
@@ -429,32 +443,30 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
429
443
  describe '.repo_team_add' do
430
444
  before do
431
445
  match_data = { 'org' => github_org, 'repo' => 'lita-test', 'team' => 'HeckmanTest' }
432
- conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty', repo_team_add_enabled: true)
446
+ conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty')
433
447
  @response = double('Lita::Response', match_data: match_data)
434
448
  team = { id: 42, name: 'HeckmanTest' }
435
449
  allow(github_repo).to receive(:config).and_return(conf_obj)
436
450
  allow(github_repo).to receive(:gh_team).with('GrapeDuty', 'HeckmanTest').and_return(team)
451
+ allow(github_repo).to receive(:func_disabled?).and_return(false)
437
452
  allow(github_repo).to receive(:repo?).and_return(true)
438
453
  allow(github_repo).to receive(:repo_has_team?).and_return(false)
439
454
  allow(github_repo).to receive(:add_team_to_repo).and_return('attr')
440
455
  end
441
456
 
442
- context 'when function is disabled' do
443
- before do
444
- conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty', repo_team_add_enabled: false)
445
- allow(github_repo).to receive(:config).and_return(conf_obj)
446
- end
447
-
448
- it 'should return the method disabled error' do
457
+ context 'when valid inputs provided, and all things work out' do
458
+ it 'should return the text from add_team_to_repo' do
449
459
  r = github_repo.send(:repo_team_add, @response)
450
- expect(r).to eql 'Sorry, this function has either been disabled or not enabled in the config'
460
+ expect(r).to eql 'attr'
451
461
  end
452
462
  end
453
463
 
454
- context 'when valid inputs provided, and all things work out' do
455
- it 'should return the text from add_team_to_repo' do
464
+ context 'when function is disabled' do
465
+ before { allow(github_repo).to receive(:func_disabled?).and_return(true) }
466
+
467
+ it 'should return the method disabled error' do
456
468
  r = github_repo.send(:repo_team_add, @response)
457
- expect(r).to eql 'attr'
469
+ expect(r).to eql 'Sorry, this function has either been disabled or not enabled in the config'
458
470
  end
459
471
  end
460
472
 
@@ -463,7 +475,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
463
475
 
464
476
  it 'should return the repo not found error' do
465
477
  r = github_repo.send(:repo_team_add, @response)
466
- expect(r).to eql 'That repo (GrapeDuty/lita-test) does not exist'
478
+ expect(r).to eql 'That repo (GrapeDuty/lita-test) was not found'
467
479
  end
468
480
  end
469
481
 
@@ -489,32 +501,30 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
489
501
  describe '.repo_team_rm' do
490
502
  before do
491
503
  match_data = { 'org' => github_org, 'repo' => 'lita-test', 'team' => 'HeckmanTest' }
492
- conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty', repo_team_rm_enabled: true)
504
+ conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty')
493
505
  @response = double('Lita::Response', match_data: match_data)
494
506
  team = { id: 42, name: 'HeckmanTest' }
495
507
  allow(github_repo).to receive(:config).and_return(conf_obj)
508
+ allow(github_repo).to receive(:func_disabled?).and_return(false)
496
509
  allow(github_repo).to receive(:gh_team).with('GrapeDuty', 'HeckmanTest').and_return(team)
497
510
  allow(github_repo).to receive(:repo?).and_return(true)
498
511
  allow(github_repo).to receive(:repo_has_team?).and_return(true)
499
512
  allow(github_repo).to receive(:remove_team_from_repo).and_return('rtfr')
500
513
  end
501
514
 
502
- context 'when function is disabled' do
503
- before do
504
- conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty', repo_team_rm_enabled: false)
505
- allow(github_repo).to receive(:config).and_return(conf_obj)
506
- end
507
-
508
- it 'should return the method disabled error' do
515
+ context 'when valid inputs provided, and all things work out' do
516
+ it 'should return the text from remove_team_to_repo' do
509
517
  r = github_repo.send(:repo_team_rm, @response)
510
- expect(r).to eql 'Sorry, this function has either been disabled or not enabled in the config'
518
+ expect(r).to eql 'rtfr'
511
519
  end
512
520
  end
513
521
 
514
- context 'when valid inputs provided, and all things work out' do
515
- it 'should return the text from remove_team_to_repo' do
522
+ context 'when function is disabled' do
523
+ before { allow(github_repo).to receive(:func_disabled?).and_return(true) }
524
+
525
+ it 'should return the method disabled error' do
516
526
  r = github_repo.send(:repo_team_rm, @response)
517
- expect(r).to eql 'rtfr'
527
+ expect(r).to eql 'Sorry, this function has either been disabled or not enabled in the config'
518
528
  end
519
529
  end
520
530
 
@@ -523,7 +533,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
523
533
 
524
534
  it 'should return the repo not found error' do
525
535
  r = github_repo.send(:repo_team_rm, @response)
526
- expect(r).to eql 'That repo (GrapeDuty/lita-test) does not exist'
536
+ expect(r).to eql 'That repo (GrapeDuty/lita-test) was not found'
527
537
  end
528
538
  end
529
539
 
@@ -546,6 +556,121 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
546
556
  end
547
557
  end
548
558
 
559
+ describe '.repo_update_description' do
560
+ before do
561
+ match_data = { 'org' => github_org, 'repo' => 'lita-test', 'field' => 'description', 'content' => 'oh hello' }
562
+ conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty')
563
+ @response = double('Lita::Response', match_data: match_data)
564
+ @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)
569
+ end
570
+
571
+ context 'when valid inputs provided, and all things work out' do
572
+ it 'should respond that the description was updated' do
573
+ send_command('gh repo update description lita-test oh hello!')
574
+ expect(replies.last).to eql "The description for GrapeDuty/lita-test has been updated to: 'oh hello'"
575
+ end
576
+ end
577
+
578
+ context 'when function disabled' do
579
+ before { allow(github_repo).to receive(:func_disabled?).and_return(true) }
580
+
581
+ it 'should return the method disabled error' do
582
+ send_command('gh repo update description lita-test A new description!')
583
+ expect(replies.last).to eql 'Sorry, this function has either been disabled or not enabled in the config'
584
+ end
585
+ end
586
+
587
+ context 'when repo not found' do
588
+ before { allow(github_repo).to receive(:repo?).and_return(false) }
589
+
590
+ it 'should return the repo not found error' do
591
+ send_command('gh repo update description lita-test A new description!')
592
+ expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) was not found'
593
+ end
594
+ end
595
+
596
+ context 'when Octokit call explodes' do
597
+ before { allow(@octo_obj).to receive(:edit_repository).and_raise(StandardError.new) }
598
+
599
+ it 'should let us know things went a bit unexpected' do
600
+ send_command('gh repo update description lita-test A new description!')
601
+ expect(replies.last).to eql(
602
+ 'An uncaught exception was hit while trying to update the description of ' \
603
+ 'GrapeDuty/lita-test. Is GitHub having issues?'
604
+ )
605
+ end
606
+ end
607
+ end
608
+
609
+ describe '.repo_update_homepage' do
610
+ before do
611
+ match_data = { 'org' => github_org, 'repo' => 'lita-test', 'field' => 'homepage', 'content' => 'https://test.it' }
612
+ conf_obj = double('Lita::Configuration', default_org: 'GrapeDuty')
613
+ @response = double('Lita::Response', match_data: match_data)
614
+ @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)
619
+ end
620
+
621
+ context 'when valid inputs provided, and all things work out' do
622
+ it 'should respond that the homepage was updated' do
623
+ send_command('gh repo update homepage lita-test https://test.it')
624
+ expect(replies.last).to eql "The homepage for GrapeDuty/lita-test has been updated to: 'https://test.it'"
625
+ end
626
+ end
627
+
628
+ context 'when function disabled' do
629
+ before { allow(github_repo).to receive(:func_disabled?).and_return(true) }
630
+
631
+ it 'should return the method disabled error' do
632
+ send_command('gh repo update homepage lita-test https://test.it')
633
+ expect(replies.last).to eql 'Sorry, this function has either been disabled or not enabled in the config'
634
+ end
635
+ end
636
+
637
+ context 'when repo not found' do
638
+ before { allow(github_repo).to receive(:repo?).and_return(false) }
639
+
640
+ it 'should return the repo not found error' do
641
+ send_command('gh repo update homepage lita-test https://test.it')
642
+ expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) was not found'
643
+ end
644
+ end
645
+
646
+ context 'when Octokit call explodes' do
647
+ before { allow(@octo_obj).to receive(:edit_repository).and_raise(StandardError.new) }
648
+
649
+ it 'should let us know things went a bit unexpected' do
650
+ send_command('gh repo update homepage lita-test https://test.it')
651
+ expect(replies.last).to eql(
652
+ 'An uncaught exception was hit while trying to update the homepage of ' \
653
+ 'GrapeDuty/lita-test. Is GitHub having issues?'
654
+ )
655
+ end
656
+ end
657
+
658
+ context 'when URL is invalid' do
659
+ before do
660
+ match_data = {
661
+ 'org' => github_org, 'repo' => 'lita-test',
662
+ 'field' => 'homepage', 'content' => 'https://test. it'
663
+ }
664
+ @response = double('Lita::Response', match_data: match_data)
665
+ end
666
+
667
+ it 'should return the invalid URL error' do
668
+ send_command('gh repo update homepage lita-test https://test. it')
669
+ expect(replies.last).to eql "The URL provided is not valid: 'https://test. it'"
670
+ end
671
+ end
672
+ end
673
+
549
674
  ####
550
675
  # Handlers
551
676
  ####
@@ -602,7 +727,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
602
727
 
603
728
  it 'should no-op informing you that the repo is not there' do
604
729
  send_command("gh repo delete #{github_org}/lita-test")
605
- expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) does not exist'
730
+ expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) was not found'
606
731
  end
607
732
  end
608
733
  end
@@ -677,22 +802,32 @@ Name: Interns, Slug: interns, ID: 84, Perms: pull
677
802
 
678
803
  it 'should say the repo was not found' do
679
804
  send_command("gh repo teams #{github_org}/lita-test")
680
- expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) does not exist'
805
+ expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) was not found'
681
806
  end
682
807
  end
683
808
  end
684
809
 
685
810
  describe '.repo_team_router' do
686
811
  before do
687
- allow(github_repo).to receive(:repo_team_something)
688
- .with(an_instance_of(Lita::Response)).and_return('ohai')
812
+ allow(github_repo).to receive(:repo_team_add).with(an_instance_of(Lita::Response)).and_return('ohai')
689
813
  end
690
814
 
691
815
  it 'should call the method based on action and respond with its return' do
692
- expect(github_repo).to receive(:repo_team_add)
693
- .with(an_instance_of(Lita::Response)).and_return('ohai')
816
+ expect(github_repo).to receive(:repo_team_add).with(an_instance_of(Lita::Response)).and_return('ohai')
694
817
  send_command("gh repo team add 42 #{github_org}/lita-test")
695
818
  expect(replies.last).to eql 'ohai'
696
819
  end
697
820
  end
821
+
822
+ describe '.repo_update_router' do
823
+ before do
824
+ allow(github_repo).to receive(:repo_update_description).with(an_instance_of(Lita::Response)).and_return('ohai')
825
+ end
826
+
827
+ it 'should call the method based on the action and respond with its return' do
828
+ expect(github_repo).to receive(:repo_update_description).with(an_instance_of(Lita::Response)).and_return('ohai')
829
+ send_command("gh repo update description #{github_org}/lita-test Something funky here")
830
+ expect(replies.last).to eql 'ohai'
831
+ end
832
+ end
698
833
  end
@@ -49,6 +49,14 @@ describe Lita::Handlers::Github, lita_handler: true do
49
49
  expect(Lita.config.handlers.github.repo_team_rm_enabled).to be_falsey
50
50
  end
51
51
 
52
+ it 'should enale Lita::Handlers::GithubRepo.repo_update_description by default' do
53
+ expect(Lita.config.handlers.github.repo_update_description_enabled).to be_truthy
54
+ end
55
+
56
+ it 'should enale Lita::Handlers::GithubRepo.repo_update_homepage by default' do
57
+ expect(Lita.config.handlers.github.repo_update_homepage_enabled).to be_truthy
58
+ end
59
+
52
60
  it 'should enable Lita::Handlers::GithubPR.pr_merge by default' do
53
61
  expect(Lita.config.handlers.github.pr_merge_enabled).to be_truthy
54
62
  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.9
4
+ version: 0.0.10
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-09-12 00:00:00.000000000 Z
11
+ date: 2014-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler