diff options
| author | Taras Madan <tarasmadan@google.com> | 2024-10-02 09:57:11 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2024-10-02 09:40:02 +0000 |
| commit | cae5050a7d451664114fa502ed59fa100329141f (patch) | |
| tree | 25f3723b98da91062179512f2b142b96493a01f5 /pkg | |
| parent | e13d0f0baaeea41cc584c6333bbf0b788d7174b9 (diff) | |
pkg/cover: add FileCoverageLink to templateHeatmapRow
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/cover/heatmap.go | 31 | ||||
| -rw-r--r-- | pkg/cover/heatmap_test.go | 12 |
2 files changed, 38 insertions, 5 deletions
diff --git a/pkg/cover/heatmap.go b/pkg/cover/heatmap.go index 246642c72..685518bd5 100644 --- a/pkg/cover/heatmap.go +++ b/pkg/cover/heatmap.go @@ -28,10 +28,12 @@ type templateHeatmapRow struct { Depth int LastDayInstrumented int64 Tooltips []string + FileCoverageLink []string builder map[string]*templateHeatmapRow instrumented map[coveragedb.TimePeriod]int64 covered map[coveragedb.TimePeriod]int64 + filePath string } type templateHeatmap struct { @@ -39,7 +41,7 @@ type templateHeatmap struct { Periods []string } -func (thm *templateHeatmapRow) addParts(depth int, pathLeft []string, instrumented, covered int64, +func (thm *templateHeatmapRow) addParts(depth int, pathLeft []string, filePath string, instrumented, covered int64, timePeriod coveragedb.TimePeriod) { thm.instrumented[timePeriod] += instrumented thm.covered[timePeriod] += covered @@ -48,17 +50,22 @@ func (thm *templateHeatmapRow) addParts(depth int, pathLeft []string, instrument } nextElement := pathLeft[0] isDir := len(pathLeft) > 1 + fp := "" + if !isDir { + fp = filePath + } if _, ok := thm.builder[nextElement]; !ok { thm.builder[nextElement] = &templateHeatmapRow{ Name: nextElement, Depth: depth, IsDir: isDir, + filePath: fp, builder: make(map[string]*templateHeatmapRow), instrumented: make(map[coveragedb.TimePeriod]int64), covered: make(map[coveragedb.TimePeriod]int64), } } - thm.builder[nextElement].addParts(depth+1, pathLeft[1:], instrumented, covered, timePeriod) + thm.builder[nextElement].addParts(depth+1, pathLeft[1:], filePath, instrumented, covered, timePeriod) } func (thm *templateHeatmapRow) prepareDataFor(timePeriods []coveragedb.TimePeriod) { @@ -77,6 +84,14 @@ func (thm *templateHeatmapRow) prepareDataFor(timePeriods []coveragedb.TimePerio thm.Coverage = append(thm.Coverage, dateCoverage) thm.Tooltips = append(thm.Tooltips, fmt.Sprintf("Instrumented:\t%d blocks\nCovered:\t%d blocks", 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", + tp.DateTo.String(), + "day", + "commit", + thm.filePath)) + } } if len(timePeriods) > 0 { lastDate := timePeriods[len(timePeriods)-1] @@ -88,6 +103,7 @@ func (thm *templateHeatmapRow) prepareDataFor(timePeriods []coveragedb.TimePerio } type fileCoverageWithDetails struct { + Subsystem string Filepath string Instrumented int64 Covered int64 @@ -98,6 +114,7 @@ type fileCoverageWithDetails struct { func filesCoverageToTemplateData(fCov []*fileCoverageWithDetails) *templateHeatmap { res := templateHeatmap{ Root: &templateHeatmapRow{ + IsDir: true, builder: map[string]*templateHeatmapRow{}, instrumented: map[coveragedb.TimePeriod]int64{}, covered: map[coveragedb.TimePeriod]int64{}, @@ -105,9 +122,14 @@ func filesCoverageToTemplateData(fCov []*fileCoverageWithDetails) *templateHeatm } timePeriods := map[coveragedb.TimePeriod]struct{}{} for _, fc := range fCov { + var pathLeft []string + if fc.Subsystem != "" { + pathLeft = append(pathLeft, fc.Subsystem) + } res.Root.addParts( 0, - strings.Split(fc.Filepath, "/"), + append(pathLeft, strings.Split(fc.Filepath, "/")...), + fc.Filepath, fc.Instrumented, fc.Covered, fc.TimePeriod) @@ -254,7 +276,8 @@ func DoSubsystemsHeatMapStyleBodyJS(ctx context.Context, projectID, ns, subsyste for _, cwd := range covWithDetails { for _, ssName := range cwd.Subsystems { newRecord := fileCoverageWithDetails{ - Filepath: ssName + "/" + cwd.Filepath, + Filepath: cwd.Filepath, + Subsystem: ssName, Instrumented: cwd.Instrumented, Covered: cwd.Covered, TimePeriod: cwd.TimePeriod, diff --git a/pkg/cover/heatmap_test.go b/pkg/cover/heatmap_test.go index be90493df..f7c058a7a 100644 --- a/pkg/cover/heatmap_test.go +++ b/pkg/cover/heatmap_test.go @@ -24,6 +24,7 @@ func TestFilesCoverageToTemplateData(t *testing.T) { want: &templateHeatmap{ Root: &templateHeatmapRow{ Items: []*templateHeatmapRow{}, + IsDir: true, }, }, }, @@ -50,11 +51,13 @@ func TestFilesCoverageToTemplateData(t *testing.T) { Tooltips: []string{ "Instrumented:\t1 blocks\nCovered:\t1 blocks", }, + FileCoverageLink: []string{ + "/upstream/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit&filepath=file1"}, }, }, Name: "", Coverage: []int64{100}, - IsDir: false, + IsDir: true, Depth: 0, LastDayInstrumented: 1, Tooltips: []string{ @@ -96,6 +99,9 @@ func TestFilesCoverageToTemplateData(t *testing.T) { "Instrumented:\t1 blocks\nCovered:\t1 blocks", "Instrumented:\t0 blocks\nCovered:\t0 blocks", }, + FileCoverageLink: []string{ + "/upstream/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit&filepath=dir/file1", + "/upstream/graph/coverage/file?dateto=2024-07-02&period=day&commit=commit&filepath=dir/file1"}, }, { Items: []*templateHeatmapRow{}, @@ -108,6 +114,9 @@ func TestFilesCoverageToTemplateData(t *testing.T) { "Instrumented:\t0 blocks\nCovered:\t0 blocks", "Instrumented:\t1 blocks\nCovered:\t0 blocks", }, + FileCoverageLink: []string{ + "/upstream/graph/coverage/file?dateto=2024-07-01&period=day&commit=commit&filepath=dir/file2", + "/upstream/graph/coverage/file?dateto=2024-07-02&period=day&commit=commit&filepath=dir/file2"}, }, }, Name: "dir", @@ -128,6 +137,7 @@ func TestFilesCoverageToTemplateData(t *testing.T) { "Instrumented:\t1 blocks\nCovered:\t1 blocks", "Instrumented:\t1 blocks\nCovered:\t0 blocks", }, + IsDir: true, }, Periods: []string{"2024-07-01(1)", "2024-07-02(1)"}, }, |
