Skip to content

Commit

Permalink
[#403] Plug in the GenerateRetro function
Browse files Browse the repository at this point in the history
- Wrote the long description of the retro command
- Added a title property to the retro.md file
- Passed the repo name as a parameter to GenerateMarkDown
- Saved the repo name in the generated md file
  • Loading branch information
aatwi committed Oct 18, 2024
1 parent 7b67d34 commit 6b64bf9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
14 changes: 13 additions & 1 deletion src/cmd/retro.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ import (
var retroCmd = &cobra.Command{
Use: "retro",
Short: "Generate retrospective template with stats",
Long: `TODO`,
Long: `
TCR retro subcommand generates a retrospective template in markdown format prefilled with TCR execution info.
The markdown file is saved into the TCR base directory with the name 'tcr-retro.md'.
The following information is included in the markdown:
- Average size of changes per passing commit
- Average size of changes per failing commit
These stats are extracted for the repository containing TCR base directory (cf. -b option).
The branch is the current working branch set for this repository.
This subcommand does not start TCR engine.`,
Run: func(_ *cobra.Command, _ []string) {
parameters.Mode = runmode.Retro{}
u := cli.New(parameters, engine.NewTCREngine())
Expand Down
18 changes: 15 additions & 3 deletions src/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/murex/tcr/params"
"github.com/murex/tcr/report"
"github.com/murex/tcr/report/role_event"
"github.com/murex/tcr/retro"
"github.com/murex/tcr/role"
"github.com/murex/tcr/runmode"
"github.com/murex/tcr/settings"
Expand All @@ -45,6 +46,7 @@ import (
"github.com/murex/tcr/vcs/factory"
"gopkg.in/tomb.v2"
"os"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -108,6 +110,8 @@ type (
}
)

const retroFileName = "tcr-retro.md"

const traceReporterWaitingTime = 100 * time.Millisecond

const fsWatchRearmDelay = 100 * time.Millisecond
Expand Down Expand Up @@ -229,9 +233,17 @@ func (tcr *TCREngine) PrintStats(p params.Params) {
}

// GenerateRetro generates a retrospective markdown file template using stats
func (*TCREngine) GenerateRetro(_ params.Params) {
//TODO implement me
panic("implement me")
func (tcr *TCREngine) GenerateRetro(p params.Params) {
tcrEvents := tcrLogsToEvents(tcr.queryVCSLogs(p))
markdown := retro.GenerateMarkdown(filepath.Base(tcr.vcs.GetRootDir()), &tcrEvents)

retroPath := filepath.Join(tcr.sourceTree.GetBaseDir(), retroFileName)
err := os.WriteFile(retroPath, []byte(markdown), 0644)
if err != nil {
report.PostError(err)
} else {
report.PostInfo("Retro file generated ", retroPath)
}
}

func tcrLogsToEvents(tcrLogs vcs.LogItems) (tcrEvents events.TcrEvents) {
Expand Down
13 changes: 10 additions & 3 deletions src/retro/retrospective.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,32 @@ import (
_ "embed"
"github.com/murex/tcr/events"
"text/template"
"time"
)

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

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

date := tcrEvents.EndingTime().Format("2006/01/02")
d := time.Now().UTC()
if tcrEvents.Len() != 0 {
d = tcrEvents.EndingTime()
}
date := d.Format("2006/01/02")

greenAvg := tcrEvents.AllLineChangesPerGreenCommit().Avg()
redAvg := tcrEvents.AllLineChangesPerRedCommit().Avg()

buf := new(bytes.Buffer)
_ = t.Execute(buf, struct {
Title string
Date string
GreenAvg any
RedAvg any
}{date, greenAvg, redAvg})
}{repoName, date, greenAvg, redAvg})
return buf.String()
}
20 changes: 17 additions & 3 deletions src/retro/retrospective_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func Test_generate_retrospective_md_for_empty_tcr_events(t *testing.T) {
tcrEvents := e.NewTcrEvents()
md := GenerateMarkdown(tcrEvents)
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")
Expand All @@ -49,18 +49,32 @@ func Test_generate_retrospective_md_with_one_passing_and_one_failing_commit(t *t
e.WithModifiedSrcLines(10),
e.WithModifiedTestLines(5)))

md := GenerateMarkdown(tcrEvents)
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_the_generated_date_is_current_date_for_empty_tcr_events(t *testing.T) {
now := time.Now().UTC()
tcrEvents := e.NewTcrEvents()
md := GenerateMarkdown("", tcrEvents)
assert.Contains(t, md, now.Format("2006/01/02"))
}

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)
md := GenerateMarkdown("", &tcrEvents)
assert.Contains(t, md, "2022/09/22")
}

func Test_include_the_repo_name_in_generated_md(t *testing.T) {
repo := "SampleRepoName"
tcrEvents := e.TcrEvents{}
md := GenerateMarkdown(repo, &tcrEvents)
assert.Contains(t, md, "## "+repo)
}
2 changes: 1 addition & 1 deletion src/retro/template/retro.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Quick Retrospective

## TODO - Session Name
## {{.Title}}

| Team | Date |
|------|-----------|
Expand Down

0 comments on commit 6b64bf9

Please sign in to comment.