Skip to content

Commit 4be9352

Browse files
authored
Merge pull request #1150 from AndriiMysko/user-allowance-am
Implement user license allowance
2 parents d32c36a + f7a9935 commit 4be9352

File tree

10 files changed

+106
-62
lines changed

10 files changed

+106
-62
lines changed

lib/travis/api/v3/billing_client.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ def allowance(owner_type, owner_id)
1414
end
1515

1616
def self.default_allowance_response(id = 0)
17-
Travis::API::V3::Models::Allowance.new(1, id, { "public_repos" => true, "private_repos" => false, "concurrency_limit" => 1 }.freeze)
17+
Travis::API::V3::Models::Allowance.new(1, id, {
18+
"public_repos" => true,
19+
"private_repos" => false,
20+
"concurrency_limit" => 1,
21+
"user_usage" => false,
22+
"pending_user_licenses" => false
23+
}.freeze)
1824
end
1925

2026
def executions(owner_type, owner_id, page, per_page, from, to)

lib/travis/api/v3/models/allowance.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
module Travis::API::V3
22
class Models::Allowance
3-
attr_reader :subscription_type, :public_repos, :private_repos, :concurrency_limit, :id
3+
attr_reader :subscription_type, :public_repos, :private_repos, :concurrency_limit, :user_usage, :pending_user_licenses, :id
44

55
def initialize(subscription_type, owner_id, attributes = {})
66
@subscription_type = subscription_type
77
@id = owner_id
88
@public_repos = attributes.fetch('public_repos')
99
@private_repos = attributes.fetch('private_repos')
1010
@concurrency_limit = attributes.fetch('concurrency_limit')
11+
@user_usage = attributes.fetch('user_usage')
12+
@pending_user_licenses = attributes.fetch('pending_user_licenses')
1113
end
1214
end
1315
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Travis::API::V3
22
class Renderer::Allowance < ModelRenderer
3-
representation(:minimal, :subscription_type, :public_repos, :private_repos, :concurrency_limit, :id)
4-
representation(:standard, :subscription_type, :public_repos, :private_repos, :concurrency_limit, :id)
3+
representation(:minimal, :subscription_type, :public_repos, :private_repos, :concurrency_limit, :user_usage, :pending_user_licenses, :id)
4+
representation(:standard, :subscription_type, :public_repos, :private_repos, :concurrency_limit, :user_usage, :pending_user_licenses, :id)
55
end
66
end

spec/v3/services/installation/find_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@
5959
"allowance" => {
6060
"@representation" => "minimal",
6161
"@type" => "allowance",
62-
"id" => 1,
6362
"concurrency_limit" => 1,
6463
"private_repos" => false,
6564
"public_repos" => true,
66-
"subscription_type" => 1
65+
"subscription_type" => 1,
66+
"user_usage" => false,
67+
"pending_user_licenses" => false,
68+
"id" => 1
6769
},
6870
"allow_migration" => false,
6971
"recently_signed_up" => false,

spec/v3/services/organization/find_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
"allowance" => {
2727
"@type" => "allowance",
2828
"@representation" => "minimal",
29-
"id" => org.id,
3029
"subscription_type" => 1,
3130
"public_repos" => true,
3231
"private_repos" => false,
33-
"concurrency_limit" => 1
32+
"concurrency_limit" => 1,
33+
"user_usage" => false,
34+
"pending_user_licenses" => false,
35+
"id" => org.id
3436
}
3537
}}
3638
end
@@ -64,11 +66,13 @@
6466
"allowance" => {
6567
"@type" => "allowance",
6668
"@representation" => "minimal",
67-
"id" => org.id,
6869
"subscription_type" => 1,
6970
"public_repos" => true,
7071
"private_repos" => false,
71-
"concurrency_limit" => 1
72+
"concurrency_limit" => 1,
73+
"user_usage" => false,
74+
"pending_user_licenses" => false,
75+
"id" => org.id
7276
}
7377
}}
7478
end

spec/v3/services/organizations/for_current_user_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@
6262
"allowance" => {
6363
"@type" => "allowance",
6464
"@representation" => "minimal",
65-
"id" => org.id,
6665
"subscription_type" => 1,
6766
"public_repos" => true,
6867
"private_repos" => false,
69-
"concurrency_limit" => 1
68+
"concurrency_limit" => 1,
69+
"user_usage" => false,
70+
"pending_user_licenses" => false,
71+
"id" => org.id
7072
}
7173
}]
7274
}}

spec/v3/services/owner/find_spec.rb

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
"allowance" => {
2727
"@type" => "allowance",
2828
"@representation" => "minimal",
29-
"id" => org.id,
3029
"subscription_type" => 1,
3130
"public_repos" => true,
3231
"private_repos" => false,
33-
"concurrency_limit" => 1
32+
"concurrency_limit" => 1,
33+
"user_usage" => false,
34+
"pending_user_licenses" => false,
35+
"id" => org.id
3436
}
3537
}}
3638
end
@@ -55,11 +57,13 @@
5557
"allowance" => {
5658
"@type" => "allowance",
5759
"@representation" => "minimal",
58-
"id" => org.id,
5960
"subscription_type" => 1,
6061
"public_repos" => true,
6162
"private_repos" => false,
62-
"concurrency_limit" => 1
63+
"concurrency_limit" => 1,
64+
"user_usage" => false,
65+
"pending_user_licenses" => false,
66+
"id" => org.id
6367
}
6468
}}
6569
end
@@ -89,11 +93,13 @@
8993
"allowance" => {
9094
"@type" => "allowance",
9195
"@representation" => "minimal",
92-
"id" => org.id,
9396
"subscription_type" => 1,
9497
"public_repos" => true,
9598
"private_repos" => false,
96-
"concurrency_limit" => 1
99+
"concurrency_limit" => 1,
100+
"user_usage" => false,
101+
"pending_user_licenses" => false,
102+
"id" => org.id
97103
},
98104
"repositories" => [{
99105
"@type" => "repository",
@@ -167,11 +173,13 @@
167173
"allowance" => {
168174
"@type" => "allowance",
169175
"@representation" => "minimal",
170-
"id" => org.id,
171176
"subscription_type" => 1,
172177
"public_repos" => true,
173178
"private_repos" => false,
174-
"concurrency_limit" => 1
179+
"concurrency_limit" => 1,
180+
"user_usage" => false,
181+
"pending_user_licenses" => false,
182+
"id" => org.id
175183
},
176184
"repositories" => [{
177185
"@type" => "repository",
@@ -240,11 +248,13 @@
240248
"allowance" => {
241249
"@type" => "allowance",
242250
"@representation" => "minimal",
243-
"id" => org.id,
244251
"subscription_type" => 1,
245252
"public_repos" => true,
246253
"private_repos" => false,
247-
"concurrency_limit" => 1
254+
"concurrency_limit" => 1,
255+
"user_usage" => false,
256+
"pending_user_licenses" => false,
257+
"id" => org.id
248258
}
249259
}}
250260
end
@@ -273,11 +283,13 @@
273283
"allowance" => {
274284
"@type" => "allowance",
275285
"@representation" => "minimal",
276-
"id" => org.id,
277286
"subscription_type" => 1,
278287
"public_repos" => true,
279288
"private_repos" => false,
280-
"concurrency_limit" => 1
289+
"concurrency_limit" => 1,
290+
"user_usage" => false,
291+
"pending_user_licenses" => false,
292+
"id" => org.id
281293
},
282294
"@warnings" => [{
283295
"@type" => "warning",
@@ -316,11 +328,13 @@
316328
"allowance" => {
317329
"@type" => "allowance",
318330
"@representation" => "minimal",
319-
"id" => user.id,
320331
"subscription_type" => 1,
321332
"public_repos" => true,
322333
"private_repos" => false,
323-
"concurrency_limit" => 1
334+
"concurrency_limit" => 1,
335+
"user_usage" => false,
336+
"pending_user_licenses" => false,
337+
"id" => user.id
324338
},
325339
"recently_signed_up"=>false,
326340
"secure_user_hash" => nil,
@@ -350,11 +364,13 @@
350364
"allowance" => {
351365
"@type" => "allowance",
352366
"@representation" => "minimal",
353-
"id" => user.id,
354367
"subscription_type" => 1,
355368
"public_repos" => true,
356369
"private_repos" => false,
357-
"concurrency_limit" => 1
370+
"concurrency_limit" => 1,
371+
"user_usage" => false,
372+
"pending_user_licenses" => false,
373+
"id" => user.id
358374
},
359375
"recently_signed_up"=>false,
360376
"secure_user_hash" => nil,
@@ -384,11 +400,13 @@
384400
"allowance" => {
385401
"@type" => "allowance",
386402
"@representation" => "minimal",
387-
"id" => user.id,
388403
"subscription_type" => 1,
389404
"public_repos" => true,
390405
"private_repos" => false,
391-
"concurrency_limit" => 1
406+
"concurrency_limit" => 1,
407+
"user_usage" => false,
408+
"pending_user_licenses" => false,
409+
"id" => user.id
392410
},
393411
"recently_signed_up"=>false,
394412
"secure_user_hash" => nil,
@@ -422,11 +440,13 @@
422440
"allowance" => {
423441
"@type" => "allowance",
424442
"@representation" => "minimal",
425-
"id" => user.id,
426443
"subscription_type" => 1,
427444
"public_repos" => true,
428445
"private_repos" => false,
429-
"concurrency_limit" => 1
446+
"concurrency_limit" => 1,
447+
"user_usage" => false,
448+
"pending_user_licenses" => false,
449+
"id" => user.id
430450
},
431451
"recently_signed_up"=>false,
432452
"secure_user_hash" => nil,

spec/v3/services/repositories/for_owner_spec.rb

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,15 @@
557557
before { get("/v3/owner/svenfuchs/allowance", {}, headers) }
558558
example { expect(last_response).to be_ok }
559559
example { expect(JSON.load(body)).to be == {
560-
"@representation" => "standard",
561-
"@type" => "allowance",
562-
"concurrency_limit" => 1,
563-
"id" => 0,
564-
"private_repos" => false,
565-
"public_repos" => true,
566-
"subscription_type" => 1
560+
"@representation" => "standard",
561+
"@type" => "allowance",
562+
"concurrency_limit" => 1,
563+
"private_repos" => false,
564+
"public_repos" => true,
565+
"subscription_type" => 1,
566+
"user_usage" => false,
567+
"pending_user_licenses" => false,
568+
"id" => 0
567569
}}
568570
end
569571

@@ -573,18 +575,20 @@
573575
Travis.config.billing.url = billing_url
574576
Travis.config.billing.auth_key = billing_auth_key
575577
stub_billing_request(:get, "/usage/users/1/allowance", auth_key: billing_auth_key, user_id: 1)
576-
.to_return(body: JSON.dump({ 'public_repos': true, 'private_repos': true, 'concurrency_limit': 666 }))
578+
.to_return(body: JSON.dump({ 'public_repos': true, 'private_repos': true, 'user_usage': true, 'pending_user_licenses': false, 'concurrency_limit': 666 }))
577579
get("/v3/owner/svenfuchs/allowance", {}, headers)
578580
end
579581
example { expect(last_response).to be_ok }
580582
example { expect(JSON.load(body)).to be == {
581-
"@representation" => "standard",
582-
"@type" => "allowance",
583-
"concurrency_limit" => 666,
584-
"id" => 1,
585-
"private_repos" => true,
586-
"public_repos" => true,
587-
"subscription_type" => 2
583+
"@representation" => "standard",
584+
"@type" => "allowance",
585+
"concurrency_limit" => 666,
586+
"private_repos" => true,
587+
"public_repos" => true,
588+
"subscription_type" => 2,
589+
"user_usage" => true,
590+
"pending_user_licenses" => false,
591+
"id" => 1
588592
}}
589593
end
590594

spec/v3/services/user/current_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
"education" => nil,
2626
"allow_migration" => false,
2727
"allowance" => {
28-
"@type" => "allowance",
29-
"@representation" => "minimal",
30-
"id" => user.id,
31-
"subscription_type" => 1,
32-
"public_repos" => true,
33-
"private_repos" => false,
34-
"concurrency_limit" => 1
28+
"@type" => "allowance",
29+
"@representation" => "minimal",
30+
"subscription_type" => 1,
31+
"public_repos" => true,
32+
"private_repos" => false,
33+
"concurrency_limit" => 1,
34+
"user_usage" => false,
35+
"pending_user_licenses" => false,
36+
"id" => user.id
3537
},
3638
"recently_signed_up"=>false,
3739
"secure_user_hash" => nil

spec/v3/services/user/find_spec.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Travis.config.billing.url = billing_url
1515
Travis.config.billing.auth_key = billing_auth_key
1616
stub_billing_request(:get, "/usage/users/#{user.id}/allowance", auth_key: billing_auth_key, user_id: user.id)
17-
.to_return(body: JSON.dump({ 'public_repos': true, 'private_repos': true, 'concurrency_limit': 666 }))
17+
.to_return(body: JSON.dump({ 'public_repos': true, 'private_repos': true, 'user_usage': true, 'pending_user_licenses': false, 'concurrency_limit': 666 }))
1818
end
1919

2020
describe "authenticated as user with access" do
@@ -38,13 +38,15 @@
3838
"education" => true,
3939
"allow_migration" => false,
4040
"allowance" => {
41-
"@type" => "allowance",
42-
"@representation" => "minimal",
43-
"id" => user.id,
44-
"subscription_type" => 2,
45-
"public_repos" => true,
46-
"private_repos" => true,
47-
"concurrency_limit" => 666
41+
"@type" => "allowance",
42+
"@representation" => "minimal",
43+
"subscription_type" => 2,
44+
"public_repos" => true,
45+
"private_repos" => true,
46+
"concurrency_limit" => 666,
47+
"user_usage" => true,
48+
"pending_user_licenses" => false,
49+
"id" => user.id
4850
},
4951
"recently_signed_up"=>false,
5052
"secure_user_hash" => nil,

0 commit comments

Comments
 (0)