From b384c770f1783ef8d82a52ab62f24b1e8365dde7 Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Tue, 1 Oct 2024 18:13:23 +0200 Subject: pkg/cover: render file links --- pkg/cover/heatmap.go | 2 +- pkg/cover/heatmap_test.go | 10 +++++----- pkg/cover/templates/heatmap.html | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) (limited to 'pkg') diff --git a/pkg/cover/heatmap.go b/pkg/cover/heatmap.go index 365f756c9..3f860ac07 100644 --- a/pkg/cover/heatmap.go +++ b/pkg/cover/heatmap.go @@ -87,7 +87,7 @@ func (thm *templateHeatmapRow) prepareDataFor(pageColumns []pageColumnTarget) { thm.instrumented[tp], thm.covered[tp])) if !thm.IsDir { thm.FileCoverageLink = append(thm.FileCoverageLink, - fmt.Sprintf("/upstream/graph/coverage/file?dateto=%s&period=%s&commit=%s&filepath=%s", + fmt.Sprintf("/graph/coverage/file?dateto=%s&period=%s&commit=%s&filepath=%s", tp.DateTo.String(), tp.Type, pageColumn.Commit, diff --git a/pkg/cover/heatmap_test.go b/pkg/cover/heatmap_test.go index 5739d2e9c..d872e31d1 100644 --- a/pkg/cover/heatmap_test.go +++ b/pkg/cover/heatmap_test.go @@ -53,7 +53,7 @@ func TestFilesCoverageToTemplateData(t *testing.T) { "Instrumented:\t1 blocks\nCovered:\t1 blocks", }, FileCoverageLink: []string{ - "/upstream/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit1&filepath=file1"}, + "/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit1&filepath=file1"}, }, }, Name: "", @@ -103,8 +103,8 @@ func TestFilesCoverageToTemplateData(t *testing.T) { "Instrumented:\t0 blocks\nCovered:\t0 blocks", }, FileCoverageLink: []string{ - "/upstream/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit1&filepath=dir/file1", - "/upstream/graph/coverage/file?dateto=2024-07-02&period=day&commit=commit2&filepath=dir/file1"}, + "/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit1&filepath=dir/file1", + "/graph/coverage/file?dateto=2024-07-02&period=day&commit=commit2&filepath=dir/file1"}, }, { Items: []*templateHeatmapRow{}, @@ -118,8 +118,8 @@ func TestFilesCoverageToTemplateData(t *testing.T) { "Instrumented:\t1 blocks\nCovered:\t0 blocks", }, FileCoverageLink: []string{ - "/upstream/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit1&filepath=dir/file2", - "/upstream/graph/coverage/file?dateto=2024-07-02&period=day&commit=commit2&filepath=dir/file2"}, + "/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit1&filepath=dir/file2", + "/graph/coverage/file?dateto=2024-07-02&period=day&commit=commit2&filepath=dir/file2"}, }, }, Name: "dir", diff --git a/pkg/cover/templates/heatmap.html b/pkg/cover/templates/heatmap.html index d72d3a02c..512b0c417 100644 --- a/pkg/cover/templates/heatmap.html +++ b/pkg/cover/templates/heatmap.html @@ -21,6 +21,17 @@ this.parentElement.parentElement.parentElement.querySelector(".nested").classList.toggle("active"); }); } + + function reqListener() { + document.getElementById("file-content").innerHTML = this.responseText; + } + + function onShowFileContent(url){ + const req = new XMLHttpRequest(); + req.addEventListener("load", reqListener); + req.open("GET", url); + req.send(); + } {{ end }} @@ -113,7 +124,7 @@ {{ end }} {{ define "body" }} -
+
  • @@ -142,6 +153,8 @@ {{template "dir" .Root}}
+
+
{{ end }} {{define "dir"}} @@ -158,7 +171,11 @@
{{ range $i, $cov := $child.Coverage }}
- {{$cov}}% + {{ if $child.IsDir }} + {{ $cov }}% + {{ else }} + {{ $cov }}% + {{ end }}
{{ index $child.Tooltips $i }}
{{ end }} -- cgit mrf-deployment