Skip to content

Commit b3ad0fe

Browse files
committed
Merge branch 'master' into logs_changes_am
* master: Fix spec Only fetch user if restarted_by is not nil Fix model Fix typo Add restarter to job Fix typo Add restarted_by into hub restart payload
2 parents ffe54a5 + f5691fc commit b3ad0fe

File tree

8 files changed

+51
-6
lines changed

8 files changed

+51
-6
lines changed

lib/travis/api/app/endpoint/builds.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Builds < Endpoint
6060
status 400
6161
false
6262
else
63-
payload = { id: params[:id], user_id: current_user.id }
63+
payload = { id: params[:id], user_id: current_user.id, restarted_by: current_user.id }
6464
service.push("build:restart", payload)
6565
status 202
6666
true

lib/travis/api/app/endpoint/jobs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Jobs < Endpoint
6868
status 400
6969
false
7070
else
71-
payload = {id: params[:id], user_id: current_user.id}
71+
payload = {id: params[:id], user_id: current_user.id, restarted_by: current_user.id}
7272
service.push("job:restart", payload)
7373
status 202
7474
true

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'travis/config/defaults'
2+
require 'travis/api/v3/models/user'
23

34
module Travis::API::V3
45
class Models::JobConfig < Model
@@ -66,6 +67,10 @@ def migrated?
6667
!!org_id
6768
end
6869

70+
def restarter
71+
@restarter ||= Travis::API::V3::Models::User.find(restarted_by) if restarted_by
72+
end
73+
6974
private def enterprise?
7075
!!Travis.config.enterprise
7176
end

lib/travis/api/v3/queries/build.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def restart(user)
2525
raise BuildAlreadyRunning if %w(received queued started).include? find.state
2626

2727
service = Travis::Enqueue::Services::RestartModel.new(user, { build_id: id })
28-
payload = { id: id, user_id: user.id }
28+
payload = { id: id, user_id: user.id, restarted_by: user.id }
2929

3030
service.push("build:restart", payload)
3131
end

lib/travis/api/v3/queries/job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def restart(user)
2323
raise JobAlreadyRunning if %w(received queued started).include? find.state
2424

2525
service = Travis::Enqueue::Services::RestartModel.new(user, { job_id: id })
26-
payload = { id: id, user_id: user.id }
26+
payload = { id: id, user_id: user.id, restarted_by: user.id }
2727

2828
service.push("job:restart", payload)
2929
end

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
module Travis::API::V3
44
class Renderer::Job < ModelRenderer
55
representation(:minimal, :id)
6-
representation(:standard, *representations[:minimal], :allow_failure, :number, :state, :started_at, :finished_at, :build, :queue, :repository, :commit, :owner, :stage, :created_at, :updated_at, :private)
6+
representation(:standard, *representations[:minimal], :allow_failure, :number, :state, :started_at, :finished_at, :build, :queue, :repository, :commit, :owner, :stage, :created_at, :updated_at, :private, :restarted_at, :restarted_by)
77
representation(:active, *representations[:standard])
88

99
# TODO: I don't want to config be visible in the regular representation
1010
# as I want it to be visible only after adding include=job.config
1111
# we probably need to have a better way of doing this
12-
representation(:with_config, *representations[:minimal], :allow_failure, :number, :state, :started_at, :finished_at, :build, :queue, :repository, :commit, :owner, :stage, :created_at, :updated_at, :config)
12+
representation(:with_config, *representations[:minimal], :allow_failure, :number, :state, :started_at, :finished_at, :build, :queue, :repository, :commit, :owner, :stage, :created_at, :updated_at, :restarted_at, :restarted_by, :config)
1313

1414
hidden_representations(:with_config)
1515
hidden_representations(:active)
@@ -26,6 +26,16 @@ def updated_at
2626
json_format_time_with_ms(model.updated_at)
2727
end
2828

29+
def restarted_by
30+
return nil unless restarter = model.restarter
31+
{
32+
'@type' => 'user',
33+
'@representation' => 'minimal'.freeze,
34+
'id' => restarter.id,
35+
'login' => restarter.login
36+
}
37+
end
38+
2939
def config
3040
if include_config?
3141
ConfigObfuscator.new(model.config, model.repository.key).obfuscate

spec/v3/services/job/find_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
"created_at" => json_format_time_with_ms(job.created_at),
6161
"updated_at" => json_format_time_with_ms(job.updated_at),
6262
"private" => false,
63+
"restarted_at" => nil,
64+
"restarted_by" => nil,
6365
"build" => {
6466
"@type" => "build",
6567
"@href" => "/v3/build/#{build.id}",
@@ -177,6 +179,8 @@
177179
"created_at" => json_format_time_with_ms(job.created_at),
178180
"updated_at" => json_format_time_with_ms(job.updated_at),
179181
"private" => false,
182+
"restarted_at" => nil,
183+
"restarted_by" => nil,
180184
"build" => {
181185
"@type" => "build",
182186
"@href" => "/v3/build/#{build.id}",
@@ -256,6 +260,8 @@
256260
"created_at" => json_format_time_with_ms(job2.created_at),
257261
"updated_at" => json_format_time_with_ms(job2.updated_at),
258262
"private" => false,
263+
"restarted_at" => nil,
264+
"restarted_by" => nil,
259265
"build" => {
260266
"@type" => "build",
261267
"@href" => "/v3/build/#{build.id}",

spec/v3/services/jobs/find_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"prioritize" => false },
3737
"id" => jobs[0].id,
3838
"private" => false,
39+
"restarted_at" => nil,
40+
"restarted_by" => nil,
3941
"number" => "#{jobs[0].number}",
4042
"state" => "configured",
4143
"started_at" => "2010-11-12T13:00:00Z",
@@ -113,6 +115,8 @@
113115
"prioritize" => false},
114116
"id" => jobs[1].id,
115117
"private" => false,
118+
"restarted_at" => nil,
119+
"restarted_by" => nil,
116120
"number" => "#{jobs[1].number}",
117121
"state" => "configured",
118122
"started_at" => "2010-11-12T13:00:00Z",
@@ -190,6 +194,8 @@
190194
"prioritize" => false},
191195
"id" => jobs[2].id,
192196
"private" => false,
197+
"restarted_at" => nil,
198+
"restarted_by" => nil,
193199
"number" => "#{jobs[2].number}",
194200
"state" => "configured",
195201
"started_at" => "2010-11-12T13:00:00Z",
@@ -267,6 +273,8 @@
267273
"prioritize" => false},
268274
"id" => jobs[3].id,
269275
"private" => false,
276+
"restarted_at" => nil,
277+
"restarted_by" => nil,
270278
"number" => "#{jobs[3].number}",
271279
"state" => "configured",
272280
"started_at" => "2010-11-12T13:00:00Z",
@@ -362,6 +370,8 @@
362370
"prioritize" => false },
363371
"id" => jobs[0].id,
364372
"private" => false,
373+
"restarted_at" => nil,
374+
"restarted_by" => nil,
365375
"number" => "#{jobs[0].number}",
366376
"state" => "configured",
367377
"started_at" => "2010-11-12T13:00:00Z",
@@ -439,6 +449,8 @@
439449
"prioritize" => false },
440450
"id" => jobs[1].id,
441451
"private" => false,
452+
"restarted_at" => nil,
453+
"restarted_by" => nil,
442454
"number" => "#{jobs[1].number}",
443455
"state" => "configured",
444456
"started_at" => "2010-11-12T13:00:00Z",
@@ -516,6 +528,8 @@
516528
"prioritize" => false },
517529
"id" => jobs[2].id,
518530
"private" => false,
531+
"restarted_at" => nil,
532+
"restarted_by" => nil,
519533
"number" => "#{jobs[2].number}",
520534
"state" => "configured",
521535
"started_at" => "2010-11-12T13:00:00Z",
@@ -593,6 +607,8 @@
593607
"prioritize" => false },
594608
"id" => jobs[3].id,
595609
"private" => false,
610+
"restarted_at" => nil,
611+
"restarted_by" => nil,
596612
"number" => "#{jobs[3].number}",
597613
"state" => "configured",
598614
"started_at" => "2010-11-12T13:00:00Z",
@@ -691,6 +707,8 @@
691707
"prioritize" => true },
692708
"id" => jobs[0].id,
693709
"private" => false,
710+
"restarted_at" => nil,
711+
"restarted_by" => nil,
694712
"number" => "#{jobs[0].number}",
695713
"state" => "configured",
696714
"started_at" => "2010-11-12T13:00:00Z",
@@ -768,6 +786,8 @@
768786
"prioritize" => true },
769787
"id" => jobs[1].id,
770788
"private" => false,
789+
"restarted_at" => nil,
790+
"restarted_by" => nil,
771791
"number" => "#{jobs[1].number}",
772792
"state" => "configured",
773793
"started_at" => "2010-11-12T13:00:00Z",
@@ -845,6 +865,8 @@
845865
"prioritize" => true },
846866
"id" => jobs[2].id,
847867
"private" => false,
868+
"restarted_at" => nil,
869+
"restarted_by" => nil,
848870
"number" => "#{jobs[2].number}",
849871
"state" => "configured",
850872
"started_at" => "2010-11-12T13:00:00Z",
@@ -922,6 +944,8 @@
922944
"prioritize" => true },
923945
"id" => jobs[3].id,
924946
"private" => false,
947+
"restarted_at" => nil,
948+
"restarted_by" => nil,
925949
"number" => "#{jobs[3].number}",
926950
"state" => "configured",
927951
"started_at" => "2010-11-12T13:00:00Z",

0 commit comments

Comments
 (0)