From 03515d717c4c30794f927ba0b0fba53676096d47 Mon Sep 17 00:00:00 2001 From: Ahmad ATWI Date: Tue, 15 Oct 2024 11:52:40 +0200 Subject: [PATCH] [#403] Implement the template for retro in Retro - Create a retro package - Implement the function retrospective.GenerateMarkdown - Function now includes only average passed and average failed commit size - Write corresponding tests --- src/retro/retrospective.go | 46 +++++++++++++++++++++++++ src/retro/retrospective_test.go | 61 +++++++++++++++++++++++++++++++++ src/runmode/retro.go | 7 +--- 3 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 src/retro/retrospective.go create mode 100644 src/retro/retrospective_test.go diff --git a/src/retro/retrospective.go b/src/retro/retrospective.go new file mode 100644 index 00000000..b523d3ad --- /dev/null +++ b/src/retro/retrospective.go @@ -0,0 +1,46 @@ +/* +Copyright (c) 2024 Murex + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +package retro + +import ( + "bytes" + "github.com/murex/tcr/events" + "text/template" +) + +func GenerateMarkdown(tcrEvents *events.TcrEvents) string { + t := template.New("QuickRetro") + t, _ = t.Parse("# Quick Retrospective\n" + + "Average passed commit size: {{.GreenAvg}}\n" + + "Average failed commit size: {{.RedAvg}}\n") + + greenAvg := tcrEvents.AllLineChangesPerGreenCommit().Avg() + redAvg := tcrEvents.AllLineChangesPerRedCommit().Avg() + + buf := new(bytes.Buffer) + t.Execute(buf, struct { + GreenAvg any + RedAvg any + }{greenAvg, redAvg}) + return buf.String() +} diff --git a/src/retro/retrospective_test.go b/src/retro/retrospective_test.go new file mode 100644 index 00000000..12648dc6 --- /dev/null +++ b/src/retro/retrospective_test.go @@ -0,0 +1,61 @@ +/* +Copyright (c) 2024 Murex + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +package retro + +import ( + "github.com/murex/tcr/events" + "github.com/stretchr/testify/assert" + "testing" + "time" +) + +func Test_generate_retrospective_md_for_empty_tcr_events(t *testing.T) { + tcrEvents := events.NewTcrEvents() + md := GenerateMarkdown(tcrEvents) + assert.Contains(t, md, "# Quick Retrospective") + assert.Contains(t, md, "Average passed commit size: 0") + assert.Contains(t, md, "Average failed commit size: 0") +} + +func Test_generate_retrospective_md_with_one_passing_and_one_failing_commit(t *testing.T) { + now := time.Now().UTC() + tcrEvents := events.NewTcrEvents() + passedStatus := events.WithCommandStatus(events.StatusPass) + passedLines := events.WithModifiedSrcLines(20) + passedTestLines := events.WithModifiedTestLines(10) + + passedEvent := events.ATcrEvent(passedStatus, passedLines, passedTestLines) + + failedStatus := events.WithCommandStatus(events.StatusFail) + failedLines := events.WithModifiedSrcLines(10) + failedTestLines := events.WithModifiedTestLines(5) + failedEvent := events.ATcrEvent(failedStatus, failedLines, failedTestLines) + + tcrEvents.Add(now, *passedEvent) + tcrEvents.Add(now, *failedEvent) + + md := GenerateMarkdown(tcrEvents) + assert.Contains(t, md, "# Quick Retrospective") + assert.Contains(t, md, "Average passed commit size: 30") + assert.Contains(t, md, "Average failed commit size: 15") +} diff --git a/src/runmode/retro.go b/src/runmode/retro.go index d9e4c170..1642ad4c 100644 --- a/src/runmode/retro.go +++ b/src/runmode/retro.go @@ -37,12 +37,7 @@ func (Retro) AutoPushDefault() bool { } // IsMultiRole indicates if this run mode supports multiple roles -func (r Retro) IsMultiRole() bool { - return false -} - -// NeedsCountdownTimer indicates if a countdown timer is needed with this run mode -func (Retro) NeedsCountdownTimer() bool { +func (Retro) IsMultiRole() bool { return false }