Skip to content

Commit 472edc2

Browse files
committed
Add pipeline_url property to construct pipeline URL
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 279bd06 commit 472edc2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

vulnerabilities/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from itertools import groupby
1818
from operator import attrgetter
1919
from typing import Union
20+
from urllib.parse import urljoin
2021

2122
import django_rq
2223
import redis
@@ -1842,11 +1843,13 @@ class PipelineRun(models.Model):
18421843
null=True,
18431844
editable=False,
18441845
)
1846+
18451847
run_end_date = models.DateTimeField(
18461848
blank=True,
18471849
null=True,
18481850
editable=False,
18491851
)
1852+
18501853
run_exitcode = models.IntegerField(
18511854
null=True,
18521855
blank=True,
@@ -1856,20 +1859,24 @@ class PipelineRun(models.Model):
18561859
blank=True,
18571860
editable=False,
18581861
)
1862+
18591863
created_date = models.DateTimeField(
18601864
auto_now_add=True,
18611865
db_index=True,
18621866
)
1867+
18631868
vulnerablecode_version = models.CharField(
18641869
max_length=100,
18651870
blank=True,
18661871
null=True,
18671872
)
1873+
18681874
vulnerablecode_commit = models.CharField(
18691875
max_length=300,
18701876
blank=True,
18711877
null=True,
18721878
)
1879+
18731880
log = models.TextField(
18741881
blank=True,
18751882
editable=False,
@@ -1959,6 +1966,18 @@ def execution_time(self):
19591966
execution_time = (self.run_end_date - self.run_start_date).total_seconds()
19601967
return humanize_time(execution_time)
19611968

1969+
@property
1970+
def pipeline_url(self):
1971+
"""Return pipeline URL based on commit and class module path."""
1972+
if not self.vulnerablecode_commit:
1973+
return None
1974+
1975+
base_url = "https://github.com/aboutcode-org/vulnerablecode/blob/"
1976+
module_path = self.pipeline_class.__module__.replace(".", "/") + ".py"
1977+
relative_path = f"{self.vulnerablecode_commit}/{module_path}"
1978+
1979+
return urljoin(base_url, relative_path)
1980+
19621981
def set_vulnerablecode_version_and_commit(self):
19631982
"""Set the current VulnerableCode version and commit."""
19641983
if self.vulnerablecode_version:

vulnerabilities/templates/pipeline_run_details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ <h1 class="title">{{ pipeline_name }} Run Log</h1>
9999
<p class="is-size-7 has-text-weight-semibold">Commit</p>
100100
<p class="has-text-grey is-size-7">
101101
{% if run.vulnerablecode_commit %}
102-
<a href="https://github.com/aboutcode-org/vulnerablecode/tree/{{ run.vulnerablecode_commit }}"
102+
<a href="{{ run.pipeline_url }}"
103103
target="_blank">
104104
{{ run.vulnerablecode_commit }}
105105
<i class="fa fa-external-link fa_link_custom"></i>

0 commit comments

Comments
 (0)