Skip to content

Commit

Permalink
[#403] Include last commit date in generated retro
Browse files Browse the repository at this point in the history
- Also fix a few linter errors
  • Loading branch information
mengdaming committed Oct 22, 2024
1 parent cd5699f commit 377d534
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/cmd/retro.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
// retroCmd represents the retro command
var retroCmd = &cobra.Command{
Use: "retro",
Short: "Generates a retrospective template using stats",
Short: "Generate retrospective template with stats",
Long: `TODO`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
parameters.Mode = runmode.Retro{}
u := cli.New(parameters, engine.NewTCREngine())
u.Start()
Expand Down
2 changes: 1 addition & 1 deletion src/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (tcr *TCREngine) PrintStats(p params.Params) {
}

// GenerateRetro generates a retrospective markdown file template using stats
func (tcr *TCREngine) GenerateRetro(_ params.Params) {
func (*TCREngine) GenerateRetro(_ params.Params) {
//TODO implement me
panic("implement me")
}
Expand Down
10 changes: 6 additions & 4 deletions src/retro/retrospective.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ import (
)

//go:embed template/retro.md
var tmpl string
var retroTemplate string

// GenerateMarkdown builds retrospective markdown contents
func GenerateMarkdown(tcrEvents *events.TcrEvents) string {
t := template.New("QuickRetro")
t, _ = t.Parse(tmpl)
t := template.New("retro")
t, _ = t.Parse(retroTemplate)

date := tcrEvents.EndingTime().Format("2006/01/02")
greenAvg := tcrEvents.AllLineChangesPerGreenCommit().Avg()
redAvg := tcrEvents.AllLineChangesPerRedCommit().Avg()

buf := new(bytes.Buffer)
_ = t.Execute(buf, struct {
Date string
GreenAvg any
RedAvg any
}{greenAvg, redAvg})
}{date, greenAvg, redAvg})
return buf.String()
}
37 changes: 21 additions & 16 deletions src/retro/retrospective_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ SOFTWARE.
package retro

import (
"github.com/murex/tcr/events"
e "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()
tcrEvents := e.NewTcrEvents()
md := GenerateMarkdown(tcrEvents)
assert.Contains(t, md, "# Quick Retrospective")
assert.Contains(t, md, "Average passed commit size: 0")
Expand All @@ -39,23 +39,28 @@ func Test_generate_retrospective_md_for_empty_tcr_events(t *testing.T) {

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)
tcrEvents := e.NewTcrEvents()
tcrEvents.Add(now, *e.ATcrEvent(
e.WithCommandStatus(e.StatusPass),
e.WithModifiedSrcLines(20),
e.WithModifiedTestLines(10)))
tcrEvents.Add(now, *e.ATcrEvent(
e.WithCommandStatus(e.StatusFail),
e.WithModifiedSrcLines(10),
e.WithModifiedTestLines(5)))

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")
}

func Test_include_last_commit_date_in_generated_md(t *testing.T) {
d := time.Date(2022, 9, 22, 11, 0, 0, 0, time.UTC)
tcrEvents := e.TcrEvents{
*e.ADatedTcrEvent(e.WithTimestamp(d.Add(-24 * time.Hour))),
*e.ADatedTcrEvent(e.WithTimestamp(d)),
}
md := GenerateMarkdown(&tcrEvents)
assert.Contains(t, md, "2022/09/22")
}
6 changes: 3 additions & 3 deletions src/retro/template/retro.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## TODO - Session Name

| Team | Date |
|------|------------|
| XXX | MM/DD/YYYY |
| Team | Date |
|------|-----------|
| XXX | {{.Date}} |

## Session's TCR metrics

Expand Down

0 comments on commit 377d534

Please sign in to comment.