Skip to content

Commit e7d5eb9

Browse files
Merge pull request #1221 from travis-ci/bug-fix-cycle-5
Bugfix cycle 5
2 parents 99fd627 + c28fd60 commit e7d5eb9

File tree

11 files changed

+56
-15
lines changed

11 files changed

+56
-15
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Travis::API::V3
22
class Models::Execution
33
attr_reader :id, :os, :instance_size, :arch, :virtualization_type, :queue, :job_id, :repository_id, :owner_id,
44
:owner_type, :plan_id, :sender_id, :credits_consumed, :user_license_credits_consumed, :started_at,
5-
:finished_at, :created_at, :updated_at
5+
:finished_at, :created_at, :updated_at, :sender_login, :repo_slug, :repo_owner_name
66

77
def initialize(attributes = {})
88
@id = attributes.fetch('id')
@@ -23,6 +23,21 @@ def initialize(attributes = {})
2323
@finished_at = attributes.fetch('finished_at')
2424
@created_at = attributes.fetch('created_at')
2525
@updated_at = attributes.fetch('updated_at')
26+
@sender_login = nil
27+
@repo_slug = nil
28+
@repo_owner_name = nil
29+
end
30+
31+
def sender_login=(sender_login)
32+
@sender_login = sender_login
33+
end
34+
35+
def repo_slug=(repo_slug)
36+
@repo_slug = repo_slug
37+
end
38+
39+
def repo_owner_name=(repo_owner_name)
40+
@repo_owner_name = repo_owner_name
2641
end
2742
end
2843
end

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module Travis::API::V3
22
class Models::Invoice
3-
attr_reader :id, :created_at, :status, :url, :amount_due
3+
attr_reader :id, :created_at, :status, :url, :amount_due, :cc_last_digits
44

55
def initialize(attributes = {})
66
@id = attributes.fetch('id')
77
@created_at = attributes.fetch('created_at') && DateTime.parse(attributes.fetch('created_at'))
88
@status = attributes.fetch('status')
99
@url = attributes.fetch('url')
1010
@amount_due = attributes.fetch('amount_due')
11+
@cc_last_digits = attributes.fetch('cc_last_digits')
1112
end
1213
end
1314
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Travis::API::V3
22
class Renderer::Execution < ModelRenderer
33
representation :minimal, :id, :os, :instance_size, :arch, :virtualization_type, :queue, :job_id,
4-
:repository_id, :owner_id, :owner_type, :plan_id, :sender_id, :credits_consumed,
5-
:user_license_credits_consumed, :started_at, :finished_at, :created_at, :updated_at
4+
:repository_id, :owner_id, :owner_type, :plan_id, :sender_id, :credits_consumed, :started_at,
5+
:user_license_credits_consumed, :finished_at, :created_at, :updated_at, :sender_login, :repo_slug, :repo_owner_name
66
representation :standard, *representations[:minimal]
77
end
88
end

lib/travis/api/v3/renderer/invoice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Travis::API::V3
22
class Renderer::Invoice < ModelRenderer
3-
representation(:standard, :id, :created_at, :status, :url, :amount_due)
3+
representation(:standard, :id, :created_at, :status, :url, :amount_due, :cc_last_digits)
44
end
55
end

lib/travis/api/v3/services/executions/for_owner.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,23 @@ def run!
1212
raise NotFound unless owner
1313
raise InsufficientAccess unless access_control.visible?(owner)
1414

15-
result query(:executions).for_owner(owner, access_control.user.id, params['page'] || 0,
15+
results = query(:executions).for_owner(owner, access_control.user.id, params['page'] || 0,
1616
params['per_page'] || 0, params['from'], params['to'])
17+
result presented_results(results)
18+
end
19+
20+
def presented_results(results)
21+
senders = Travis::API::V3::Models::User.where(id: results.map(&:sender_id)).index_by(&:id)
22+
repositories = Travis::API::V3::Models::Repository.where(id: results.map(&:repository_id)).index_by(&:id)
23+
24+
results.map do |execution|
25+
execution.sender_login = senders[execution.sender_id]&.login || 'Unknown Sender'
26+
repo = repositories[execution.repository_id]
27+
execution.repo_slug = repo&.slug || 'Unknown Repository'
28+
execution.repo_owner_name = repo&.owner_name || 'Unknown Repository Owner'
29+
30+
execution
31+
end
1732
end
1833
end
1934
end

lib/travis/services/find_caches.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def fetch_s3(cache_objects, options)
154154
def fetch_gcs(cache_objects, options)
155155
config = cache_options[:gcs]
156156
storage = ::Google::Apis::StorageV1::StorageService.new
157-
json_key_io = StringIO.new(config.to_h[:json_key])
157+
json_key_io = StringIO.new(JSON.dump(config.to_h[:json_key]))
158158
bucket_name = config[:bucket_name]
159159

160160
storage.authorization = ::Google::Auth::ServiceAccountCredentials.make_creds(

spec/lib/services/find_caches_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
end
7272

7373
context 'with GCS configuration' do
74-
let(:cache_options) { { gcs: { bucket_name: '', json_key: '' } } }
74+
let(:cache_options) { { gcs: { bucket_name: '', json_key: { type: 'service_account', project_id: 'test-project-id' } } } }
7575
its(:size) { is_expected.to eq 0 }
7676
end
7777
end

spec/v3/billing_client_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@
5252

5353
it 'returns a list of invoices' do
5454
stub_billing_request(:get, "/subscriptions/#{subscription_id}/invoices", auth_key: auth_key, user_id: user_id)
55-
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999, status: 'paid' }]))
55+
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999, status: 'paid', cc_last_digits: '4242' }]))
5656
expect(subject.first).to be_a(Travis::API::V3::Models::Invoice)
5757
expect(subject.first.id).to eq(invoice_id)
5858
expect(subject.first.amount_due).to eq(999)
59+
expect(subject.first.cc_last_digits).to eq('4242')
5960
end
6061

6162
it 'returns an empty list if there are no invoices' do
@@ -71,10 +72,11 @@
7172

7273
it 'returns a list of invoices' do
7374
stub_billing_request(:get, "/v2/subscriptions/#{subscription_id}/invoices", auth_key: auth_key, user_id: user_id)
74-
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999, status: 'paid' }]))
75+
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999, status: 'paid', cc_last_digits: '4242' }]))
7576
expect(subject.first).to be_a(Travis::API::V3::Models::Invoice)
7677
expect(subject.first.id).to eq(invoice_id)
7778
expect(subject.first.amount_due).to eq(999)
79+
expect(subject.first.cc_last_digits).to eq('4242')
7880
end
7981

8082
it 'returns an empty list if there are no invoices' do

spec/v3/services/subscription/invoices_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
let(:amount_due) { 100 }
2828
let(:status) { 'paid' }
2929
let(:subscription_id) { rand(999) }
30+
let(:cc_last_digits) { '4242' }
3031
before do
3132
stub_billing_request(:get, "/subscriptions/#{subscription_id}/invoices", auth_key: billing_auth_key, user_id: user.id)
32-
.to_return(status: 200, body: JSON.dump([{'id' => invoice_id, 'created_at' => created_at, 'url' => url, 'amount_due' => amount_due, 'status' => status }]))
33+
.to_return(status: 200, body: JSON.dump([{'id' => invoice_id, 'created_at' => created_at, 'url' => url, 'amount_due' => amount_due, 'status' => status, 'cc_last_digits' => cc_last_digits }]))
3334
end
3435

3536
it 'responds with list of subscriptions' do
@@ -47,7 +48,8 @@
4748
'created_at' => created_at,
4849
'url' => url,
4950
'amount_due' => amount_due,
50-
'status' => status
51+
'status' => status,
52+
'cc_last_digits' => cc_last_digits
5153
}]
5254
})
5355
end

spec/v3/services/v2_subscription/executions_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@
6969
'started_at' => Time.now.to_s,
7070
'finished_at' => (Time.now + 10.minutes).to_s,
7171
'created_at' => Time.now.to_s,
72-
'updated_at' => Time.now.to_s
72+
'updated_at' => Time.now.to_s,
73+
'repo_owner_name' => "svenfuchs",
74+
'repo_slug' => "svenfuchs/minimal",
75+
'sender_login' => "svenfuchs"
7376
}]
7477
})
7578
end

0 commit comments

Comments
 (0)