lita-github 0.0.5 → 0.0.6

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: 84ebbc2e578a216a3e4e15fa00011549924cb610
4
- data.tar.gz: 700ad40378f13ab0d10b1775a361ccbca3aca5a1
3
+ metadata.gz: 807063c8ac3a37a3d99452dd97ca4697b25466ee
4
+ data.tar.gz: b05330632d6bec6b9e2de3dda514770ad5f5d4fb
5
5
  SHA512:
6
- metadata.gz: 9b7c3e7b9a3db900ad5033f72d44078935c1e11265764e3be9ead51ba9f1d2422a7100416c0897af2ac0c1b3127b7a8d9f20ef89be7ee563027dbdf3a7f8103f
7
- data.tar.gz: af6d62477813175ea4abc97117f4169ff4cd1f64da4028ab129e961fd023745ef38a8f4dcd6279623870cad641cf605832b3b63229b8424042e47f918bf2290e
6
+ metadata.gz: 89cccb87fe4a2a3dd8023fb53a8e5752bf45dfe1c4ef0d9d45442e5cecbbec80ffaa2040ffcc7d0e1f2ce644c8805be1e712d91fccad001c0dffe1829903d05a
7
+ data.tar.gz: a880e825a989589478bd1eef547c94d034192370e6b23c659cc92fa1ab791dd0b43e24c3692f3c071091f9ed67bca542f2754781e392c6dceeb85bcd94a58f1a
data/README.md CHANGED
@@ -63,3 +63,5 @@ Here is the current functionality:
63
63
  * `!gh pr merge #42 PagerDuty/lita-github` or `!shipit #42 PagerDuty/lita-github`
64
64
  * This merges the specified pull request
65
65
  * This method can be disabled by setting `config.handlers.github.pr_merge_enabled = false` in your configuration file
66
+ * `!gh pr list PagerDuty/lita-github`
67
+ * list the open pull requests on a repo
@@ -17,6 +17,8 @@
17
17
  module LitaGithub
18
18
  # Github handler common-use Repository methods
19
19
  module Repo
20
+ PR_LIST_MAX_COUNT = 20
21
+
20
22
  def rpo(org, repo)
21
23
  "#{org}/#{repo}"
22
24
  end
@@ -24,5 +26,10 @@ module LitaGithub
24
26
  def repo?(r)
25
27
  octo.repository?(r)
26
28
  end
29
+
30
+ def repo_match(response)
31
+ md = response.match_data
32
+ [organization(md['org']), md['repo']]
33
+ end
27
34
  end
28
35
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  # Administer your Hub of Gits with Lita!
18
18
  module LitaGithub
19
- VERSION = '0.0.5'
19
+ VERSION = '0.0.6'
20
20
  MAJ, MIN, REV = VERSION.split('.').map(&:to_i)
21
21
  end
@@ -32,7 +32,7 @@ module Lita
32
32
  on :loaded, :setup_octo # from LitaGithub::Octo
33
33
 
34
34
  route(
35
- /#{LitaGithub::R::A_REG}status/, :gh_status,
35
+ /#{LitaGithub::R::A_REG}status/, :status,
36
36
  command: true,
37
37
  help: {
38
38
  'github status' => 'get the system status from GitHub',
@@ -41,7 +41,7 @@ module Lita
41
41
  )
42
42
 
43
43
  route(
44
- /#{LitaGithub::R::A_REG}(?:v|version|build)/, :gh_version,
44
+ /#{LitaGithub::R::A_REG}(?:v|version|build)/, :version,
45
45
  command: true,
46
46
  help: {
47
47
  'gh version' => 'get the lita-github version'
@@ -76,11 +76,15 @@ module Lita
76
76
  config.pr_merge_enabled = true
77
77
  end
78
78
 
79
- def gh_status(response)
79
+ def status(response)
80
80
  status = octo.github_status_last_message
81
81
  response.reply(t("status.#{status[:status]}", status))
82
82
  end
83
83
 
84
+ def version(response)
85
+ response.reply("lita-github v#{LitaGithub::VERSION}")
86
+ end
87
+
84
88
  def token_generate(response)
85
89
  if config.totp_secret.is_a?(String)
86
90
  response.reply(t('token_generate.totp', token: ROTP::TOTP.new(config.totp_secret).now))
@@ -88,10 +92,6 @@ module Lita
88
92
  response.reply(t('token_generate.no_secret'))
89
93
  end
90
94
  end
91
-
92
- def gh_version(response)
93
- response.reply("lita-github v#{LitaGithub::VERSION}")
94
- end
95
95
  end
96
96
 
97
97
  Lita.register_handler(Github)
@@ -52,6 +52,14 @@ module Lita
52
52
  }
53
53
  )
54
54
 
55
+ route(
56
+ /#{LitaGithub::R::A_REG}pr\s+?list\s+?#{LitaGithub::R::REPO_REGEX}/, :pr_list,
57
+ command: true,
58
+ help: {
59
+ 'gh pr list PagerDuty/lita-github' => 'list the 10 oldest and newest PRs'
60
+ }
61
+ )
62
+
55
63
  # rubocop:disable Metrics/CyclomaticComplexity
56
64
  # rubocop:disable Metrics/PerceivedComplexity
57
65
  def pr_info(response)
@@ -98,6 +106,30 @@ module Lita
98
106
  # rubocop:enable Metrics/CyclomaticComplexity
99
107
  # rubocop:enable Metrics/PerceivedComplexity
100
108
 
109
+ def pr_list(response)
110
+ org, repo = repo_match(response)
111
+ full_name = rpo(org, repo)
112
+ reply = ''
113
+
114
+ prs = octo.pull_requests(full_name)
115
+
116
+ if prs.length > LitaGithub::Repo::PR_LIST_MAX_COUNT
117
+ reply = t('pr_list.large_list', max: LitaGithub::Repo::PR_LIST_MAX_COUNT)
118
+
119
+ prs.slice(0, 10).each { |pr| reply << list_line(pr, full_name) }
120
+
121
+ reply << "----\n"
122
+
123
+ prs.slice(-10, 10).each { |pr| reply << list_line(pr, full_name) }
124
+ elsif prs.length > 0
125
+ prs.each { |pr| reply << list_line(pr, full_name) }
126
+ else
127
+ reply = t('pr_list.no_prs')
128
+ end
129
+
130
+ response.reply(reply)
131
+ end
132
+
101
133
  private
102
134
 
103
135
  def pr_match(response)
@@ -183,6 +215,10 @@ module Lita
183
215
  info[:comments] = pr_obj[:comments]
184
216
  info
185
217
  end
218
+
219
+ def list_line(pr, full_name)
220
+ t('pr_info.header', build_pr_header!({}, pr).merge(repo: full_name))
221
+ end
186
222
  end
187
223
 
188
224
  Lita.register_handler(GithubPR)
@@ -117,12 +117,6 @@ module Lita
117
117
  o
118
118
  end
119
119
 
120
- # TODO: convert this to a mixin method for reuse
121
- def repo_match(response)
122
- md = response.match_data
123
- [organization(md['org']), md['repo']]
124
- end
125
-
126
120
  def extrapolate_create_opts(opts, org)
127
121
  opts[:organization] = org
128
122
 
@@ -35,3 +35,6 @@ en:
35
35
  pr_merge:
36
36
  pass: "Merged pull request #%{pr} from %{org}/%{branch}\n%{title}"
37
37
  fail: "Failed trying to merge PR #%{pr} (%{title}) :: %{url}\nMessage: %{msg}"
38
+ pr_list:
39
+ large_list: "You have more than %{max} open pull requests :(! Here are the ten newest oldest:\n"
40
+ no_prs: "This repo has no open pull requests; good job!"
@@ -5,6 +5,13 @@ require 'spec_helper'
5
5
  describe LitaGithub::Repo do
6
6
  include LitaGithub::Repo
7
7
 
8
+ describe '::PR_LIST_MAX_COUNT' do
9
+ subject { LitaGithub::Repo::PR_LIST_MAX_COUNT }
10
+
11
+ it { should be_an_instance_of Fixnum }
12
+ it { should eql 20 }
13
+ end
14
+
8
15
  describe '.rpo' do
9
16
  it 'should return the provided arguments in a Repo-like string' do
10
17
  org = 'GrapeDuty'
@@ -34,4 +41,17 @@ describe LitaGithub::Repo do
34
41
  it { should be_falsey }
35
42
  end
36
43
  end
44
+
45
+ describe '.repo_match' do
46
+ before { allow(self).to receive(:organization).and_return('GrapeDuty') }
47
+
48
+ let(:resp_obj) do
49
+ md_mock = { 'org' => 'GrapeDuty', 'repo' => 'lita-test' }
50
+ double('Lita::Response', match_data: md_mock)
51
+ end
52
+
53
+ it 'should return the Org/Repo match' do
54
+ expect(repo_match(resp_obj)).to eql ['GrapeDuty', 'lita-test']
55
+ end
56
+ end
37
57
  end
@@ -366,6 +366,16 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
366
366
  end
367
367
  end
368
368
 
369
+ describe '.list_line' do
370
+ let(:pr) { { title: 'Test', number: 42, html_url: 'nothtml' } }
371
+ let(:full_name) { 'GrapeDuty/lita-test' }
372
+
373
+ it 'should return a PR header' do
374
+ l = github_pr.send(:list_line, pr, full_name)
375
+ expect(l).to eql "GrapeDuty/lita-test #42: Test :: nothtml\n"
376
+ end
377
+ end
378
+
369
379
  ####
370
380
  # Handlers
371
381
  ####
@@ -549,4 +559,95 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
549
559
  end
550
560
  end
551
561
  end
562
+
563
+ describe '.pr_list' do
564
+ before do
565
+ cfg_obj = double('Lita::Configuration')
566
+ octo_obj = double('Octokit::Client', pull_requests: [])
567
+ allow(github_pr).to receive(:octo).and_return(octo_obj)
568
+ allow(github_pr).to receive(:config).and_return(cfg_obj)
569
+ end
570
+
571
+ context 'when there are no pull requests' do
572
+ it 'should state that there are no pull requests' do
573
+ send_command("gh pr list #{github_org}/#{github_repo}")
574
+ expect(replies.last).to eql 'This repo has no open pull requests; good job!'
575
+ end
576
+ end
577
+
578
+ context 'when there are less than 20 prs' do
579
+ before do
580
+ pr = [
581
+ { title: 'Test2', number: 84, html_url: 'nohtmlurl' },
582
+ { title: 'Test1', number: 42, html_url: 'htmlurl' }
583
+ ]
584
+ octo_obj = double('Octokit::Client', pull_requests: pr)
585
+ allow(github_pr).to receive(:octo).and_return(octo_obj)
586
+ end
587
+
588
+ it 'should reply with the PRs' do
589
+ send_command("gh pr list #{github_org}/#{github_repo}")
590
+ expect(replies.last).to eql "GrapeDuty/lita-test #84: Test2 :: nohtmlurl\n" \
591
+ "GrapeDuty/lita-test #42: Test1 :: htmlurl\n"
592
+ end
593
+ end
594
+
595
+ context 'when there are more than 20 prs' do
596
+ before do
597
+ pr = [
598
+ { title: 'Test21', number: 84, html_url: 'xxx' },
599
+ { title: 'Test20', number: 83, html_url: 'xxx' },
600
+ { title: 'Test19', number: 82, html_url: 'xxx' },
601
+ { title: 'Test18', number: 80, html_url: 'xxx' },
602
+ { title: 'Test17', number: 78, html_url: 'xxx' },
603
+ { title: 'Test16', number: 74, html_url: 'xxx' },
604
+ { title: 'Test15', number: 68, html_url: 'xxx' },
605
+ { title: 'Test14', number: 66, html_url: 'xxx' },
606
+ { title: 'Test13', number: 64, html_url: 'xxx' },
607
+ { title: 'Test12', number: 55, html_url: 'xxx' },
608
+ { title: 'Test11', number: 52, html_url: 'xxx' },
609
+ { title: 'Test10', number: 51, html_url: 'xxx' },
610
+ { title: 'Test9', number: 50, html_url: 'xxx' },
611
+ { title: 'Test8', number: 49, html_url: 'xxx' },
612
+ { title: 'Test7', number: 48, html_url: 'xxx' },
613
+ { title: 'Test6', number: 47, html_url: 'xxx' },
614
+ { title: 'Test5', number: 46, html_url: 'xxx' },
615
+ { title: 'Test4', number: 45, html_url: 'xxx' },
616
+ { title: 'Test3', number: 44, html_url: 'xxx' },
617
+ { title: 'Test2', number: 43, html_url: 'xxx' },
618
+ { title: 'Test1', number: 42, html_url: 'xxx' }
619
+ ]
620
+ octo_obj = double('Octokit::Client', pull_requests: pr)
621
+ allow(github_pr).to receive(:octo).and_return(octo_obj)
622
+ end
623
+
624
+ it 'should return the list of ten oldest & ten newest' do
625
+ send_command("gh pr list #{github_org}/#{github_repo}")
626
+ expect(replies.last)
627
+ .to eql "You have more than 20 open pull requests :(! Here are the ten newest oldest:
628
+ GrapeDuty/lita-test #84: Test21 :: xxx
629
+ GrapeDuty/lita-test #83: Test20 :: xxx
630
+ GrapeDuty/lita-test #82: Test19 :: xxx
631
+ GrapeDuty/lita-test #80: Test18 :: xxx
632
+ GrapeDuty/lita-test #78: Test17 :: xxx
633
+ GrapeDuty/lita-test #74: Test16 :: xxx
634
+ GrapeDuty/lita-test #68: Test15 :: xxx
635
+ GrapeDuty/lita-test #66: Test14 :: xxx
636
+ GrapeDuty/lita-test #64: Test13 :: xxx
637
+ GrapeDuty/lita-test #55: Test12 :: xxx
638
+ ----
639
+ GrapeDuty/lita-test #51: Test10 :: xxx
640
+ GrapeDuty/lita-test #50: Test9 :: xxx
641
+ GrapeDuty/lita-test #49: Test8 :: xxx
642
+ GrapeDuty/lita-test #48: Test7 :: xxx
643
+ GrapeDuty/lita-test #47: Test6 :: xxx
644
+ GrapeDuty/lita-test #46: Test5 :: xxx
645
+ GrapeDuty/lita-test #45: Test4 :: xxx
646
+ GrapeDuty/lita-test #44: Test3 :: xxx
647
+ GrapeDuty/lita-test #43: Test2 :: xxx
648
+ GrapeDuty/lita-test #42: Test1 :: xxx
649
+ "
650
+ end
651
+ end
652
+ end
552
653
  end
@@ -151,17 +151,6 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
151
151
  end
152
152
  end
153
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
154
  describe '.command_opts' do
166
155
  it 'should find the valid options' do
167
156
  o = ' private:true team:heckman bacon:always bacon:sometimes'
@@ -19,9 +19,9 @@ require 'spec_helper'
19
19
  describe Lita::Handlers::Github, lita_handler: true do
20
20
  let(:github) { Lita::Handlers::Github.new('robot') }
21
21
 
22
- it { routes_command('gh status').to(:gh_status) }
23
- it { routes_command('github status').to(:gh_status) }
24
- it { routes_command('gh version').to(:gh_version) }
22
+ it { routes_command('gh status').to(:status) }
23
+ it { routes_command('github status').to(:status) }
24
+ it { routes_command('gh version').to(:version) }
25
25
  it { routes_command('gh token').to(:token_generate) }
26
26
 
27
27
  describe '#default_config' do
@@ -42,7 +42,7 @@ describe Lita::Handlers::Github, lita_handler: true do
42
42
  end
43
43
  end
44
44
 
45
- describe '.gh_status' do
45
+ describe '.status' do
46
46
  context 'when GitHub status is good' do
47
47
  before do
48
48
  @octo = double(
@@ -104,7 +104,7 @@ describe Lita::Handlers::Github, lita_handler: true do
104
104
  end
105
105
  end
106
106
 
107
- describe '.gh_version' do
107
+ describe '.version' do
108
108
  it 'should send back the Lita version' do
109
109
  send_command('gh version')
110
110
  expect(replies.last).to eql "lita-github v#{LitaGithub::VERSION}"
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.5
4
+ version: 0.0.6
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-06 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler