aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-10-01 18:13:23 +0200
committerTaras Madan <tarasmadan@google.com>2024-10-02 09:40:02 +0000
commitb384c770f1783ef8d82a52ab62f24b1e8365dde7 (patch)
treecb5b017f7458339a29fb4da976a93bc430c89465 /pkg
parente6185ff22b3ea7f1e80c8f931fbc21802df71402 (diff)
pkg/cover: render file links
Diffstat (limited to 'pkg')
-rw-r--r--pkg/cover/heatmap.go2
-rw-r--r--pkg/cover/heatmap_test.go10
-rw-r--r--pkg/cover/templates/heatmap.html21
3 files changed, 25 insertions, 8 deletions
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();
+ }
</script>
{{ end }}
@@ -113,7 +124,7 @@
{{ end }}
{{ define "body" }}
- <div>
+ <div style="display:inline-block">
<ul id="collapsible-list">
<li>
<div class="first_column bold">
@@ -142,6 +153,8 @@
{{template "dir" .Root}}
</ul>
</div>
+ <div id="file-content" style="display:inline-block; vertical-align: top">
+ </div>
{{ end }}
{{define "dir"}}
@@ -158,7 +171,11 @@
</div>
{{ range $i, $cov := $child.Coverage }}
<div class="date_column cover_percent">
- {{$cov}}%
+ {{ if $child.IsDir }}
+ {{ $cov }}%
+ {{ else }}
+ <a href="javascript:onShowFileContent('/upstream{{ index $child.FileCoverageLink $i }}');">{{ $cov }}%</a>
+ {{ end }}
<pre class="tooltiptext">{{ index $child.Tooltips $i }}</pre>
</div>
{{ end }}