lita-github 0.0.6 → 0.0.7
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 +4 -4
- data/README.md +1 -0
- data/lib/lita-github/version.rb +1 -1
- data/lib/lita/handlers/github.rb +1 -0
- data/lib/lita/handlers/github_repo.rb +9 -3
- data/spec/unit/lita/handlers/github_repo_spec.rb +83 -12
- data/spec/unit/lita/handlers/github_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a74bbd8ca959d937503c0d0f676aafa83d8f4fe8
|
|
4
|
+
data.tar.gz: 8df94bb7c74863c82c66b436c60350f1d25b9a86
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4db4682a4c9fd305c4685887d1241476270bbad98df0a5c381dd3e8c1562cfa8699c5767396fd5fa1ebda1a0a20e3c853bb99eca8f7adfbad5a62ee2cf5ec6e0
|
|
7
|
+
data.tar.gz: 8125f027de492262b1a5068afcc39471cd001478e0bfe6a4afee4157b22fadb60f6bd40f9155838ad338605b028d219bde80c7f2ea74d1d26482a1cf00e4134e
|
data/README.md
CHANGED
|
@@ -27,6 +27,7 @@ The configuration options will get their own in-depth doc a little further down
|
|
|
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
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
|
|
30
31
|
* the default team that should be added to a repo based on the slug name:
|
|
31
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]
|
|
32
33
|
|
data/lib/lita-github/version.rb
CHANGED
data/lib/lita/handlers/github.rb
CHANGED
|
@@ -121,20 +121,26 @@ module Lita
|
|
|
121
121
|
opts[:organization] = org
|
|
122
122
|
|
|
123
123
|
if opts.key?(:team)
|
|
124
|
-
|
|
124
|
+
t_id = team_id_by_slug(opts[:team], org) || default_team(org)
|
|
125
|
+
opts[:team_id] = t_id unless t_id.nil?
|
|
125
126
|
else
|
|
126
|
-
|
|
127
|
+
t_id = default_team(org)
|
|
128
|
+
opts[:team_id] = t_id unless t_id.nil?
|
|
127
129
|
end unless opts.key?(:team_id)
|
|
128
130
|
opts
|
|
129
131
|
end
|
|
130
132
|
|
|
131
|
-
def
|
|
133
|
+
def team_id_by_slug(slug, org)
|
|
132
134
|
octo.organization_teams(org).each do |team|
|
|
133
135
|
return team[:id] if team[:slug] == slug
|
|
134
136
|
end
|
|
135
137
|
nil
|
|
136
138
|
end
|
|
137
139
|
|
|
140
|
+
def default_team(org)
|
|
141
|
+
config.default_team_slug.nil? ? nil : team_id_by_slug(config.default_team_slug, org)
|
|
142
|
+
end
|
|
143
|
+
|
|
138
144
|
def should_repo_be_private?(value)
|
|
139
145
|
if value.nil? || value.empty?
|
|
140
146
|
config.repo_private_default
|
|
@@ -84,7 +84,37 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
describe '.
|
|
87
|
+
describe '.default_team' do
|
|
88
|
+
before do
|
|
89
|
+
allow(github_repo).to receive(:team_id_by_slug).and_return(88)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context 'when the default team slug is set' do
|
|
93
|
+
before do
|
|
94
|
+
cfg_obj = double('Lita::Configuration', default_team_slug: 'heckman')
|
|
95
|
+
allow(github_repo).to receive(:config).and_return(cfg_obj)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'should return the team ID of the slug' do
|
|
99
|
+
expect(github_repo).to receive(:team_id_by_slug).with('heckman', 'GrapeDuty')
|
|
100
|
+
.and_return(42)
|
|
101
|
+
expect(github_repo.send(:default_team, github_org)).to eql 42
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context 'when the default slug is not set' do
|
|
106
|
+
before do
|
|
107
|
+
cfg_obj = double('Lita::Configuration', default_team_slug: nil)
|
|
108
|
+
allow(github_repo).to receive(:config).and_return(cfg_obj)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'should return nil' do
|
|
112
|
+
expect(github_repo.send(:default_team, github_org)).to be_nil
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe '.team_id_by_slug' do
|
|
88
118
|
before do
|
|
89
119
|
@teams = [
|
|
90
120
|
{ id: 1, slug: 'hi' },
|
|
@@ -97,13 +127,13 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
|
97
127
|
|
|
98
128
|
it 'should return the team id of the team matching the slug' do
|
|
99
129
|
expect(@octo_obj).to receive(:organization_teams).with(github_org).and_return(@teams)
|
|
100
|
-
expect(github_repo.send(:
|
|
101
|
-
expect(github_repo.send(:
|
|
102
|
-
expect(github_repo.send(:
|
|
130
|
+
expect(github_repo.send(:team_id_by_slug, 'heckman', github_org)).to eql 42
|
|
131
|
+
expect(github_repo.send(:team_id_by_slug, 'orwell', github_org)).to eql 84
|
|
132
|
+
expect(github_repo.send(:team_id_by_slug, 'unknown', github_org)).to be_nil
|
|
103
133
|
end
|
|
104
134
|
|
|
105
135
|
it 'should return nil if unknown' do
|
|
106
|
-
expect(github_repo.send(:
|
|
136
|
+
expect(github_repo.send(:team_id_by_slug, 'unknown', 'x')).to be_nil
|
|
107
137
|
end
|
|
108
138
|
end
|
|
109
139
|
|
|
@@ -112,7 +142,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
|
112
142
|
@eco_opts = {}
|
|
113
143
|
@c_obj = double('Lita::Configuration', default_team_slug: 'h3ckman')
|
|
114
144
|
allow(github_repo).to receive(:config).and_return(@c_obj)
|
|
115
|
-
allow(github_repo).to receive(:
|
|
145
|
+
allow(github_repo).to receive(:team_id_by_slug).and_return(42)
|
|
116
146
|
end
|
|
117
147
|
|
|
118
148
|
it 'should set the :organization key and :team_id key' do
|
|
@@ -120,22 +150,63 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
|
120
150
|
expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
|
|
121
151
|
end
|
|
122
152
|
|
|
153
|
+
context 'when there is no :team set' do
|
|
154
|
+
context 'when default_team returns a team id' do
|
|
155
|
+
it 'should get the default team_id' do
|
|
156
|
+
h = { organization: github_org, team_id: 44 }
|
|
157
|
+
expect(github_repo).to receive(:default_team).with(github_org).and_return(44)
|
|
158
|
+
expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
context 'when default_team returns nil' do
|
|
163
|
+
before do
|
|
164
|
+
@c_obj = double('Lita::Configuration', default_team_slug: nil)
|
|
165
|
+
allow(github_repo).to receive(:config).and_return(@c_obj)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'should not set the :team_id key' do
|
|
169
|
+
h = { organization: github_org }
|
|
170
|
+
expect(github_repo).to receive(:default_team).with(github_org).and_return(nil)
|
|
171
|
+
expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
123
176
|
context 'when options contains :team and no :team_id' do
|
|
124
177
|
context 'when given a valid slug' do
|
|
125
178
|
before { @eco_opts = { team: 'heckman' } }
|
|
126
179
|
|
|
127
180
|
it 'should set the :team_id key' do
|
|
128
181
|
h = { organization: github_org, team_id: 84 }.merge!(@eco_opts)
|
|
129
|
-
expect(github_repo).to receive(:
|
|
182
|
+
expect(github_repo).to receive(:team_id_by_slug).with('heckman', github_org).and_return(84)
|
|
130
183
|
expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
|
|
131
184
|
end
|
|
132
185
|
end
|
|
133
186
|
|
|
134
187
|
context 'when given an invalid slug' do
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
188
|
+
context 'when there is a default slug set' do
|
|
189
|
+
it 'should set the team to the default' do
|
|
190
|
+
h = { organization: github_org, team_id: 42 }.merge!(@eco_opts)
|
|
191
|
+
expect(github_repo).to receive(:team_id_by_slug).with('h3ckman', github_org).and_return(42)
|
|
192
|
+
expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
context 'when there is no default slug set' do
|
|
197
|
+
before do
|
|
198
|
+
@eco_opts = { team: 'h3ckman' }
|
|
199
|
+
c_obj = double('Lita::Configuration', default_team_slug: nil)
|
|
200
|
+
allow(github_repo).to receive(:config).and_return(c_obj)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'should not set a :team_id' do
|
|
204
|
+
h = { organization: github_org }.merge!(@eco_opts)
|
|
205
|
+
expect(github_repo).to receive(:team_id_by_slug).with('h3ckman', github_org)
|
|
206
|
+
.and_return(nil)
|
|
207
|
+
expect(github_repo).to receive(:default_team).with(github_org).and_call_original
|
|
208
|
+
expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
|
|
209
|
+
end
|
|
139
210
|
end
|
|
140
211
|
end
|
|
141
212
|
end
|
|
@@ -145,7 +216,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
|
145
216
|
|
|
146
217
|
it 'should just leave it alone...' do
|
|
147
218
|
h = { organization: github_org }.merge!(@eco_opts)
|
|
148
|
-
expect(github_repo).not_to receive(:
|
|
219
|
+
expect(github_repo).not_to receive(:team_id_by_slug)
|
|
149
220
|
expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
|
|
150
221
|
end
|
|
151
222
|
end
|
|
@@ -25,6 +25,10 @@ describe Lita::Handlers::Github, lita_handler: true do
|
|
|
25
25
|
it { routes_command('gh token').to(:token_generate) }
|
|
26
26
|
|
|
27
27
|
describe '#default_config' do
|
|
28
|
+
it 'should set default team to nil' do
|
|
29
|
+
expect(Lita.config.handlers.github.default_team_slug).to be_nil
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
it 'should set repos to private by default' do
|
|
29
33
|
expect(Lita.config.handlers.github.repo_private_default).to be_truthy
|
|
30
34
|
end
|