Skip to content

Commit e036f1b

Browse files
authored
restarted_by feature - merge from master (#1248)
* BSFY-141 merge - add restarted by
1 parent 978635f commit e036f1b

File tree

10 files changed

+53
-8
lines changed

10 files changed

+53
-8
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/app/extensions/smart_constants.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def helpers(*list, &block)
1515
end
1616

1717
def register(*list, &block)
18-
super(*resolve_constants(list, Extensions), &block)
18+
super(*resolve_constants(list, Extensions), &block)
1919
end
2020

2121
private

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
restart_status = service.push("build:restart", payload)
3131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Queries::Builds < Query
44
params :name, prefix: :branch, method_name: :branch_name
55

66
sortable_by :id, :created_at, :started_at, :finished_at,
7-
number: "number::int %{order}"
7+
number: "number::int %{order}"
88
default_sort "number:desc,id:desc"
99

1010
def find(repository)

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
restart_status = service.push("job:restart", payload)
2929

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}",
@@ -175,6 +177,8 @@
175177
"created_at" => json_format_time_with_ms(job.created_at),
176178
"updated_at" => json_format_time_with_ms(job.updated_at),
177179
"private" => false,
180+
"restarted_at" => nil,
181+
"restarted_by" => nil,
178182
"build" => {
179183
"@type" => "build",
180184
"@href" => "/v3/build/#{build.id}",
@@ -252,6 +256,8 @@
252256
"created_at" => json_format_time_with_ms(job2.created_at),
253257
"updated_at" => json_format_time_with_ms(job2.updated_at),
254258
"private" => false,
259+
"restarted_at" => nil,
260+
"restarted_by" => nil,
255261
"build" => {
256262
"@type" => "build",
257263
"@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",
@@ -111,6 +113,8 @@
111113
"prioritize" => false},
112114
"id" => jobs[1].id,
113115
"private" => false,
116+
"restarted_at" => nil,
117+
"restarted_by" => nil,
114118
"number" => "#{jobs[1].number}",
115119
"state" => "configured",
116120
"started_at" => "2010-11-12T13:00:00Z",
@@ -186,6 +190,8 @@
186190
"prioritize" => false},
187191
"id" => jobs[2].id,
188192
"private" => false,
193+
"restarted_at" => nil,
194+
"restarted_by" => nil,
189195
"number" => "#{jobs[2].number}",
190196
"state" => "configured",
191197
"started_at" => "2010-11-12T13:00:00Z",
@@ -261,6 +267,8 @@
261267
"prioritize" => false},
262268
"id" => jobs[3].id,
263269
"private" => false,
270+
"restarted_at" => nil,
271+
"restarted_by" => nil,
264272
"number" => "#{jobs[3].number}",
265273
"state" => "configured",
266274
"started_at" => "2010-11-12T13:00:00Z",
@@ -354,6 +362,8 @@
354362
"prioritize" => false },
355363
"id" => jobs[0].id,
356364
"private" => false,
365+
"restarted_at" => nil,
366+
"restarted_by" => nil,
357367
"number" => "#{jobs[0].number}",
358368
"state" => "configured",
359369
"started_at" => "2010-11-12T13:00:00Z",
@@ -429,6 +439,8 @@
429439
"prioritize" => false },
430440
"id" => jobs[1].id,
431441
"private" => false,
442+
"restarted_at" => nil,
443+
"restarted_by" => nil,
432444
"number" => "#{jobs[1].number}",
433445
"state" => "configured",
434446
"started_at" => "2010-11-12T13:00:00Z",
@@ -504,6 +516,8 @@
504516
"prioritize" => false },
505517
"id" => jobs[2].id,
506518
"private" => false,
519+
"restarted_at" => nil,
520+
"restarted_by" => nil,
507521
"number" => "#{jobs[2].number}",
508522
"state" => "configured",
509523
"started_at" => "2010-11-12T13:00:00Z",
@@ -579,6 +593,8 @@
579593
"prioritize" => false },
580594
"id" => jobs[3].id,
581595
"private" => false,
596+
"restarted_at" => nil,
597+
"restarted_by" => nil,
582598
"number" => "#{jobs[3].number}",
583599
"state" => "configured",
584600
"started_at" => "2010-11-12T13:00:00Z",
@@ -675,6 +691,8 @@
675691
"prioritize" => true },
676692
"id" => jobs[0].id,
677693
"private" => false,
694+
"restarted_at" => nil,
695+
"restarted_by" => nil,
678696
"number" => "#{jobs[0].number}",
679697
"state" => "configured",
680698
"started_at" => "2010-11-12T13:00:00Z",
@@ -750,6 +768,8 @@
750768
"prioritize" => true },
751769
"id" => jobs[1].id,
752770
"private" => false,
771+
"restarted_at" => nil,
772+
"restarted_by" => nil,
753773
"number" => "#{jobs[1].number}",
754774
"state" => "configured",
755775
"started_at" => "2010-11-12T13:00:00Z",
@@ -825,6 +845,8 @@
825845
"prioritize" => true },
826846
"id" => jobs[2].id,
827847
"private" => false,
848+
"restarted_at" => nil,
849+
"restarted_by" => nil,
828850
"number" => "#{jobs[2].number}",
829851
"state" => "configured",
830852
"started_at" => "2010-11-12T13:00:00Z",
@@ -900,6 +922,8 @@
900922
"prioritize" => true },
901923
"id" => jobs[3].id,
902924
"private" => false,
925+
"restarted_at" => nil,
926+
"restarted_by" => nil,
903927
"number" => "#{jobs[3].number}",
904928
"state" => "configured",
905929
"started_at" => "2010-11-12T13:00:00Z",

0 commit comments

Comments
 (0)