Skip to content

Commit

Permalink
[#403] Implement the template for retro in Retro
Browse files Browse the repository at this point in the history
- Create a retro package
- Implement the function retrospective.GenerateMarkdown
- Function now includes only average passed and average failed commit size
- Write corresponding tests
  • Loading branch information
aatwi authored and mengdaming committed Oct 22, 2024
1 parent 806d55b commit 03515d7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 6 deletions.
46 changes: 46 additions & 0 deletions src/retro/retrospective.go
Original file line number Diff line number Diff line change
@@ -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()
}
61 changes: 61 additions & 0 deletions src/retro/retrospective_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
7 changes: 1 addition & 6 deletions src/runmode/retro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 03515d7

Please sign in to comment.