Skip to content

Commit e7c8cba

Browse files
committed
Do not humanize execution time in api response
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 0df4d48 commit e7c8cba

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

vulnerabilities/api_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def get_status(self, obj):
652652
return obj.status
653653

654654
def get_execution_time(self, obj):
655-
return obj.execution_time
655+
return round(obj.execution_time, 2)
656656

657657

658658
class PipelineScheduleAPISerializer(serializers.HyperlinkedModelSerializer):

vulnerabilities/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,7 @@ def execution_time(self):
19721972

19731973
end_time = self.run_end_date or timezone.now()
19741974
time_delta = (end_time - self.run_start_date).total_seconds()
1975-
return humanize_time(time_delta)
1975+
return time_delta
19761976

19771977
@property
19781978
def pipeline_url(self):

vulnerabilities/templates/pipeline_run_details.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ <h1 class="title">{{ pipeline_name }} Run Log</h1>
7373
</div>
7474
<div class="column is-one-fifth-desktop is-one-quarter-tablet is-half-mobile">
7575
<p class="is-size-7 has-text-weight-semibold">Execution Time</p>
76-
<p class="has-text-grey is-size-7">{{ run.execution_time|default_if_none:"N/A" }}</p>
76+
<p class="has-text-grey is-size-7">
77+
{% if run.execution_time %}
78+
{{ run.execution_time|humanize_duration }}
79+
{% else %}
80+
N/A
81+
{% endif %}
82+
</p>
7783
</div>
7884
<div class="column is-one-fifth-desktop is-one-quarter-tablet is-half-mobile">
7985
<p class="is-size-7 has-text-weight-semibold">Exit Code</p>

vulnerabilities/templates/pipeline_run_list.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{% extends "base.html" %}
2+
{% load utils %}
3+
24

35
{% block title %}
46
{{ pipeline_name }} Runs
@@ -81,7 +83,13 @@ <h1>{{ pipeline_name }} Runs</h1>
8183
{% endif %}
8284
</span>
8385
</div>
84-
<div class="column is-one-eighth has-text-grey">{{ run.execution_time|default_if_none:"N/A" }}</div>
86+
<div class="column is-one-eighth has-text-grey">
87+
{% if run.execution_time %}
88+
{{ run.execution_time|humanize_duration }}
89+
{% else %}
90+
N/A
91+
{% endif %}
92+
</div>
8593
<div class="column is-one-fifth has-text-grey">
8694
{% if run.run_start_date %}
8795
{{ run.run_start_date|date:"Y-m-d H:i" }}

vulnerabilities/templatetags/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#
99

1010

11+
from aboutcode.pipeline import humanize_time
1112
from django import template
1213

1314
register = template.Library()
@@ -18,3 +19,8 @@ def strip(value):
1819
if isinstance(value, str):
1920
return value.strip()
2021
return value
22+
23+
24+
@register.filter
25+
def humanize_duration(duration):
26+
return humanize_time(seconds=duration)

0 commit comments

Comments
 (0)