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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 807063c8ac3a37a3d99452dd97ca4697b25466ee
4
- data.tar.gz: b05330632d6bec6b9e2de3dda514770ad5f5d4fb
3
+ metadata.gz: a74bbd8ca959d937503c0d0f676aafa83d8f4fe8
4
+ data.tar.gz: 8df94bb7c74863c82c66b436c60350f1d25b9a86
5
5
  SHA512:
6
- metadata.gz: 89cccb87fe4a2a3dd8023fb53a8e5752bf45dfe1c4ef0d9d45442e5cecbbec80ffaa2040ffcc7d0e1f2ce644c8805be1e712d91fccad001c0dffe1829903d05a
7
- data.tar.gz: a880e825a989589478bd1eef547c94d034192370e6b23c659cc92fa1ab791dd0b43e24c3692f3c071091f9ed67bca542f2754781e392c6dceeb85bcd94a58f1a
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
 
@@ -16,6 +16,6 @@
16
16
 
17
17
  # Administer your Hub of Gits with Lita!
18
18
  module LitaGithub
19
- VERSION = '0.0.6'
19
+ VERSION = '0.0.7'
20
20
  MAJ, MIN, REV = VERSION.split('.').map(&:to_i)
21
21
  end
@@ -59,6 +59,7 @@ module Lita
59
59
  def self.default_config(config)
60
60
  # when setting default configuration values please remember one thing:
61
61
  # secure and safe by default
62
+ config.default_team_slug = nil
62
63
  config.repo_private_default = true
63
64
 
64
65
  ####
@@ -121,20 +121,26 @@ module Lita
121
121
  opts[:organization] = org
122
122
 
123
123
  if opts.key?(:team)
124
- opts[:team_id] = team_by_slug(opts[:team], org) || team_by_slug(config.default_team_slug, org)
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
- opts[:team_id] = team_by_slug(config.default_team_slug, org)
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 team_by_slug(slug, org)
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 '.team_by_slug' do
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(:team_by_slug, 'heckman', github_org)).to eql 42
101
- expect(github_repo.send(:team_by_slug, 'orwell', github_org)).to eql 84
102
- expect(github_repo.send(:team_by_slug, 'unknown', github_org)).to be_nil
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(:team_by_slug, 'unknown', 'x')).to be_nil
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(:team_by_slug).and_return(42)
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(:team_by_slug).with('heckman', github_org).and_return(84)
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
- it 'should set the team to the default' do
136
- h = { organization: github_org, team_id: 42 }.merge!(@eco_opts)
137
- expect(github_repo).to receive(:team_by_slug).with('h3ckman', github_org).and_return(42)
138
- expect(github_repo.send(:extrapolate_create_opts, @eco_opts, github_org)).to eql h
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(:team_by_slug)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heckman