lita-github 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/lita-github/version.rb +1 -1
- data/lib/lita/handlers/github.rb +51 -0
- data/locales/en.yml +9 -0
- data/spec/unit/lita/handlers/github_spec.rb +184 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0349ebd1948d263860af6b90c1a24447a6408aea
|
4
|
+
data.tar.gz: a4e1279c91922ce93c18519701a91dca1f2ce76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19e4723298203e74eb221818523164fa6e54d7e2c4d92bbf6474c1f7cbb8c7751c2c457f2752780957bebbd28a3c221445477140363775dedd6210b71912f504
|
7
|
+
data.tar.gz: 2d3b335bfa654197c4118bdd77b1d91e596e62b6701936dac401b692dab8ef5f8f79bc0c106d1c2be25d97a73cfdc938e6c603573dbfcb532763cd3dd8cb4504
|
data/README.md
CHANGED
@@ -49,6 +49,8 @@ Here is the current functionality:
|
|
49
49
|
* get the version of handler
|
50
50
|
* `!gh token`
|
51
51
|
* generate a TOTP token if `config.handlers.github.totp_secret` is set in the config
|
52
|
+
* `!gh whois theckman`
|
53
|
+
* show some information about a GitHub user
|
52
54
|
|
53
55
|
### GitHub Repository Handler
|
54
56
|
* `!gh repo create PagerDuty/lita-github private:true team:<team_slug>`
|
data/lib/lita-github/version.rb
CHANGED
data/lib/lita/handlers/github.rb
CHANGED
@@ -56,6 +56,15 @@ module Lita
|
|
56
56
|
}
|
57
57
|
)
|
58
58
|
|
59
|
+
route(
|
60
|
+
/#{LitaGithub::R::A_REG}(?:whois|user)\s+(?<username>[a-zA-Z0-9_\-]+)/,
|
61
|
+
:whois,
|
62
|
+
command: true,
|
63
|
+
help: {
|
64
|
+
'gh whois theckman' => 'show some information about that GitHub user'
|
65
|
+
}
|
66
|
+
)
|
67
|
+
|
59
68
|
def self.default_config(config)
|
60
69
|
# when setting default configuration values please remember one thing:
|
61
70
|
# secure and safe by default
|
@@ -102,6 +111,48 @@ module Lita
|
|
102
111
|
response.reply(t('token_generate.no_secret'))
|
103
112
|
end
|
104
113
|
end
|
114
|
+
|
115
|
+
def whois(response)
|
116
|
+
username = response.match_data['username'].strip
|
117
|
+
|
118
|
+
begin
|
119
|
+
user = octo.user(username)
|
120
|
+
rescue Octokit::NotFound
|
121
|
+
return response.reply(t('whois.user_not_found', username: username))
|
122
|
+
end
|
123
|
+
|
124
|
+
orgs = octo.organizations(username).map { |o| o[:login] }
|
125
|
+
reply = whois_reply(user, orgs)
|
126
|
+
|
127
|
+
response.reply(reply)
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def key_valid?(val)
|
133
|
+
(val.nil? || val.empty?) ? false : true
|
134
|
+
end
|
135
|
+
|
136
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
137
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
138
|
+
def whois_reply(user, orgs)
|
139
|
+
name = user.key?(:name) && !user[:name].nil? ? " (#{user[:name]})" : ''
|
140
|
+
|
141
|
+
reply = "#{user[:login]}#{name} :: #{user[:html_url]}\n"
|
142
|
+
|
143
|
+
reply << t('whois.location', l: user[:location]) if key_valid?(user[:location])
|
144
|
+
reply << t('whois.company', c: user[:company]) if key_valid?(user[:company])
|
145
|
+
reply << t('whois.orgs', o: orgs.join(', ')) unless orgs.empty?
|
146
|
+
|
147
|
+
reply << t('whois.id', i: user[:id])
|
148
|
+
key_valid?(user[:email]) ? reply << ", #{t('whois.email', e: user[:email])}\n" : reply << "\n"
|
149
|
+
|
150
|
+
reply << t('whois.account_info', user.to_h)
|
151
|
+
reply << t('whois.user_info', user.to_h)
|
152
|
+
reply
|
153
|
+
end
|
154
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
155
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
105
156
|
end
|
106
157
|
|
107
158
|
Lita.register_handler(Github)
|
data/locales/en.yml
CHANGED
@@ -9,6 +9,15 @@ en:
|
|
9
9
|
token_generate:
|
10
10
|
no_secret: "'totp_secret' has not been provided in the config, unable to generate TOTP"
|
11
11
|
totp: "%{token}"
|
12
|
+
whois:
|
13
|
+
user_not_found: "Sorry, unable to locate the GitHub user %{username}"
|
14
|
+
id: "ID: %{i}"
|
15
|
+
orgs: "Orgs: %{o}\n"
|
16
|
+
email: "Email: %{e}"
|
17
|
+
company: "Company: %{c}\n"
|
18
|
+
location: "Located: %{l}\n"
|
19
|
+
account_info: "GitHub Admin: %{site_admin}, Repos: %{public_repos}, Gists: %{public_gists}\n"
|
20
|
+
user_info: "Following: %{following}, Followers: %{followers}, Created: %{created_at}"
|
12
21
|
github_repo:
|
13
22
|
method_disabled: "Sorry, this function has either been disabled or not enabled in the config"
|
14
23
|
not_found: "That repo (%{org}/%{repo}) was not found"
|
@@ -19,11 +19,20 @@ 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
|
+
# status routing
|
22
23
|
it { routes_command('gh status').to(:status) }
|
23
24
|
it { routes_command('github status').to(:status) }
|
25
|
+
|
26
|
+
# version routing
|
24
27
|
it { routes_command('gh version').to(:version) }
|
28
|
+
|
29
|
+
# token routing
|
25
30
|
it { routes_command('gh token').to(:token_generate) }
|
26
31
|
|
32
|
+
# whois routing
|
33
|
+
it { routes_command('gh whois theckman').to(:whois) }
|
34
|
+
it { routes_command('gh user theckman').to(:whois) }
|
35
|
+
|
27
36
|
describe '#default_config' do
|
28
37
|
it 'should set default team to nil' do
|
29
38
|
expect(Lita.config.handlers.github.default_team_slug).to be_nil
|
@@ -74,6 +83,138 @@ describe Lita::Handlers::Github, lita_handler: true do
|
|
74
83
|
end
|
75
84
|
end
|
76
85
|
|
86
|
+
####
|
87
|
+
# Helper Methods
|
88
|
+
####
|
89
|
+
describe '.key_valid?' do
|
90
|
+
context 'when value is nil' do
|
91
|
+
it 'should be false' do
|
92
|
+
expect(github.send(:key_valid?, nil)).to be_falsey
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when value is empty String ("")' do
|
97
|
+
it 'should be false' do
|
98
|
+
expect(github.send(:key_valid?, '')).to be_falsey
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when value is a String' do
|
103
|
+
it 'should be true' do
|
104
|
+
expect(github.send(:key_valid?, 'something')).to be_truthy
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '.whois_reply' do
|
110
|
+
before do
|
111
|
+
@user_obj = {
|
112
|
+
name: 'Tim Heckman',
|
113
|
+
login: 'theckman',
|
114
|
+
location: 'San Francisco, CA',
|
115
|
+
company: 'PagerDuty, Inc.',
|
116
|
+
id: 787_332,
|
117
|
+
email: 'tim@pagerduty.com',
|
118
|
+
html_url: 'https://github.com/theckman',
|
119
|
+
site_admin: false,
|
120
|
+
public_repos: 42,
|
121
|
+
public_gists: 1,
|
122
|
+
following: 20,
|
123
|
+
followers: 10,
|
124
|
+
created_at: Time.parse('2011-05-14 04:16:33 UTC')
|
125
|
+
}
|
126
|
+
@orgs = %w(PagerDuty GrapeDuty)
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when all fields are there' do
|
130
|
+
it 'should reply with the proper response' do
|
131
|
+
r = github.send(:whois_reply, @user_obj, @orgs)
|
132
|
+
expect(r).to eql 'theckman (Tim Heckman) :: https://github.com/theckman
|
133
|
+
Located: San Francisco, CA
|
134
|
+
Company: PagerDuty, Inc.
|
135
|
+
Orgs: PagerDuty, GrapeDuty
|
136
|
+
ID: 787332, Email: tim@pagerduty.com
|
137
|
+
GitHub Admin: false, Repos: 42, Gists: 1
|
138
|
+
Following: 20, Followers: 10, Created: 2011-05-14 04:16:33 UTC'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when name is unset' do
|
143
|
+
before { @user_obj.delete(:name) }
|
144
|
+
|
145
|
+
it 'should reply with the proper response' do
|
146
|
+
r = github.send(:whois_reply, @user_obj, @orgs)
|
147
|
+
expect(r).to eql 'theckman :: https://github.com/theckman
|
148
|
+
Located: San Francisco, CA
|
149
|
+
Company: PagerDuty, Inc.
|
150
|
+
Orgs: PagerDuty, GrapeDuty
|
151
|
+
ID: 787332, Email: tim@pagerduty.com
|
152
|
+
GitHub Admin: false, Repos: 42, Gists: 1
|
153
|
+
Following: 20, Followers: 10, Created: 2011-05-14 04:16:33 UTC'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when location is unset' do
|
158
|
+
before { @user_obj.delete(:location) }
|
159
|
+
|
160
|
+
it 'should reply with the proper response' do
|
161
|
+
r = github.send(:whois_reply, @user_obj, @orgs)
|
162
|
+
expect(r).to eql 'theckman (Tim Heckman) :: https://github.com/theckman
|
163
|
+
Company: PagerDuty, Inc.
|
164
|
+
Orgs: PagerDuty, GrapeDuty
|
165
|
+
ID: 787332, Email: tim@pagerduty.com
|
166
|
+
GitHub Admin: false, Repos: 42, Gists: 1
|
167
|
+
Following: 20, Followers: 10, Created: 2011-05-14 04:16:33 UTC'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'when company is unset' do
|
172
|
+
before { @user_obj.delete(:company) }
|
173
|
+
|
174
|
+
it 'should reply with the proper response' do
|
175
|
+
r = github.send(:whois_reply, @user_obj, @orgs)
|
176
|
+
expect(r).to eql 'theckman (Tim Heckman) :: https://github.com/theckman
|
177
|
+
Located: San Francisco, CA
|
178
|
+
Orgs: PagerDuty, GrapeDuty
|
179
|
+
ID: 787332, Email: tim@pagerduty.com
|
180
|
+
GitHub Admin: false, Repos: 42, Gists: 1
|
181
|
+
Following: 20, Followers: 10, Created: 2011-05-14 04:16:33 UTC'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when orgs is empty' do
|
186
|
+
before { @orgs.clear }
|
187
|
+
|
188
|
+
it 'should reply with the proper response' do
|
189
|
+
r = github.send(:whois_reply, @user_obj, @orgs)
|
190
|
+
expect(r).to eql 'theckman (Tim Heckman) :: https://github.com/theckman
|
191
|
+
Located: San Francisco, CA
|
192
|
+
Company: PagerDuty, Inc.
|
193
|
+
ID: 787332, Email: tim@pagerduty.com
|
194
|
+
GitHub Admin: false, Repos: 42, Gists: 1
|
195
|
+
Following: 20, Followers: 10, Created: 2011-05-14 04:16:33 UTC'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'when email is empty string' do
|
200
|
+
before { @user_obj[:email] = '' }
|
201
|
+
|
202
|
+
it 'should reply with the proper response' do
|
203
|
+
r = github.send(:whois_reply, @user_obj, @orgs)
|
204
|
+
expect(r).to eql 'theckman (Tim Heckman) :: https://github.com/theckman
|
205
|
+
Located: San Francisco, CA
|
206
|
+
Company: PagerDuty, Inc.
|
207
|
+
Orgs: PagerDuty, GrapeDuty
|
208
|
+
ID: 787332
|
209
|
+
GitHub Admin: false, Repos: 42, Gists: 1
|
210
|
+
Following: 20, Followers: 10, Created: 2011-05-14 04:16:33 UTC'
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
####
|
216
|
+
# Handlers
|
217
|
+
####
|
77
218
|
describe '.status' do
|
78
219
|
context 'when GitHub status is good' do
|
79
220
|
before do
|
@@ -171,4 +312,47 @@ describe Lita::Handlers::Github, lita_handler: true do
|
|
171
312
|
end
|
172
313
|
end
|
173
314
|
end
|
315
|
+
|
316
|
+
describe '.whois' do
|
317
|
+
before do
|
318
|
+
@user_obj = {
|
319
|
+
name: 'Tim Heckman',
|
320
|
+
login: 'theckman',
|
321
|
+
location: 'San Francisco, CA',
|
322
|
+
company: 'PagerDuty, Inc.',
|
323
|
+
id: 787_332,
|
324
|
+
email: 'tim@pagerduty.com',
|
325
|
+
html_url: 'https://github.com/theckman',
|
326
|
+
site_admin: false,
|
327
|
+
public_repos: 42,
|
328
|
+
public_gists: 1,
|
329
|
+
following: 20,
|
330
|
+
followers: 10,
|
331
|
+
created_at: Time.parse('2011-05-14 04:16:33 UTC')
|
332
|
+
}
|
333
|
+
@orgs = [{ login: 'PagerDuty' }, { login: 'GrapeDuty' }]
|
334
|
+
@octo_obj = double('Octokit::Client', user: @user_obj, organizations: @orgs)
|
335
|
+
allow(github).to receive(:octo).and_return(@octo_obj)
|
336
|
+
allow(github).to receive(:whois_reply).and_return('StubbedResponse')
|
337
|
+
end
|
338
|
+
|
339
|
+
context 'when all goes well' do
|
340
|
+
it 'should return the response from whois_reply' do
|
341
|
+
expect(@octo_obj).to receive(:user).with('theckman').and_return(@user_obj)
|
342
|
+
expect(@octo_obj).to receive(:organizations).with('theckman').and_return(@orgs)
|
343
|
+
expect(github).to receive(:whois_reply).with(@user_obj, %w(PagerDuty GrapeDuty)).and_return('StubbedResponse')
|
344
|
+
send_command('gh whois theckman')
|
345
|
+
expect(replies.last).to eql 'StubbedResponse'
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context 'when user can not be found' do
|
350
|
+
before { allow(@octo_obj).to receive(:user).with('theckman').and_raise(Octokit::NotFound.new) }
|
351
|
+
|
352
|
+
it 'should return the response from whois_reply' do
|
353
|
+
send_command('gh whois theckman')
|
354
|
+
expect(replies.last).to eql 'Sorry, unable to locate the GitHub user theckman'
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
174
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.0.
|
4
|
+
version: 0.0.13
|
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-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|