2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-10 17:41:04 -05:00
|
|
|
module Ci
|
2020-01-10 13:07:43 -05:00
|
|
|
class BuildPresenter < ProcessablePresenter
|
2017-01-10 17:41:04 -05:00
|
|
|
def erased_by_user?
|
|
|
|
# Build can be erased through API, therefore it does not have
|
|
|
|
# `erased_by` user assigned in that case.
|
|
|
|
erased? && erased_by
|
|
|
|
end
|
|
|
|
|
|
|
|
def erased_by_name
|
|
|
|
erased_by.name if erased_by_user?
|
|
|
|
end
|
2017-04-05 11:33:19 -04:00
|
|
|
|
2021-08-31 05:08:57 -04:00
|
|
|
def status_title(status = detailed_status)
|
2017-04-06 09:32:56 -04:00
|
|
|
if auto_canceled?
|
|
|
|
"Job is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}"
|
2018-04-05 17:04:42 -04:00
|
|
|
else
|
2021-08-31 05:08:57 -04:00
|
|
|
tooltip_for_badge(status)
|
2017-04-05 11:33:19 -04:00
|
|
|
end
|
|
|
|
end
|
2017-09-04 09:21:47 -04:00
|
|
|
|
|
|
|
def trigger_variables
|
|
|
|
return [] unless trigger_request
|
|
|
|
|
|
|
|
@trigger_variables ||=
|
|
|
|
if pipeline.variables.any?
|
|
|
|
pipeline.variables.map(&:to_runner_variable)
|
|
|
|
else
|
|
|
|
trigger_request.user_variables
|
|
|
|
end
|
|
|
|
end
|
2018-04-05 17:04:42 -04:00
|
|
|
|
|
|
|
def tooltip_message
|
|
|
|
"#{subject.name} - #{detailed_status.status_tooltip}"
|
|
|
|
end
|
|
|
|
|
2018-09-24 07:02:26 -04:00
|
|
|
def execute_in
|
2018-09-25 01:21:41 -04:00
|
|
|
scheduled? && scheduled_at && [0, scheduled_at - Time.now].max
|
2018-09-24 07:02:26 -04:00
|
|
|
end
|
|
|
|
|
2018-04-05 17:04:42 -04:00
|
|
|
private
|
|
|
|
|
2021-08-31 05:08:57 -04:00
|
|
|
def tooltip_for_badge(status)
|
|
|
|
status.badge_tooltip.capitalize
|
2018-04-05 17:04:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def detailed_status
|
|
|
|
@detailed_status ||= subject.detailed_status(user)
|
|
|
|
end
|
2017-01-10 17:41:04 -05:00
|
|
|
end
|
|
|
|
end
|
2021-02-02 07:10:15 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Ci::BuildPresenter.prepend_mod_with('Ci::BuildPresenter')
|