Skip to content

Commit 6d80352

Browse files
committed
hack: add support for date ranges to notes.go script
This is useful for the comms team when creating the weekly updates for the slack channel. Example invocation would be: `go run hack/tools/release/notes.go --since 2023-02-06 --until 2023-02-12`
1 parent f68c489 commit 6d80352

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

hack/tools/release/notes.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"os/exec"
2929
"regexp"
3030
"strings"
31+
"time"
3132
)
3233

3334
/*
@@ -60,6 +61,9 @@ var (
6061

6162
fromTag = flag.String("from", "", "The tag or commit to start from.")
6263

64+
since = flag.String("since", "", "Include commits starting from and including this date. Accepts format: YYYY-MM-DD")
65+
until = flag.String("until", "", "Include commits up to and including this date. Accepts format: YYYY-MM-DD")
66+
6367
tagRegex = regexp.MustCompile(`^\[release-[\w-\.]*\]`)
6468
)
6569

@@ -89,9 +93,37 @@ func firstCommit() string {
8993
return string(bytes.TrimSpace(out))
9094
}
9195

96+
// Since git doesn't include the last day in rev-list we want to increase 1 day to include it in the interval.
97+
func increaseDateByOneDay(date string) (string, error) {
98+
layout := "2006-01-02"
99+
datetime, err := time.Parse(layout, date)
100+
if err != nil {
101+
return "", err
102+
}
103+
datetime = datetime.Add(time.Hour * 24)
104+
return datetime.Format(layout), nil
105+
}
106+
92107
func run() int {
93-
lastTag := lastTag()
94-
cmd := exec.Command("git", "rev-list", lastTag+"..HEAD", "--merges", "--pretty=format:%B") //nolint:gosec
108+
var commitRange string
109+
var cmd *exec.Cmd
110+
111+
if *since != "" && *until != "" {
112+
commitRange = fmt.Sprintf("%s - %s", *since, *until)
113+
114+
lastDay, err := increaseDateByOneDay(*until)
115+
if err != nil {
116+
fmt.Println(err)
117+
return 1
118+
}
119+
cmd = exec.Command("git", "rev-list", "HEAD", "--since=\""+*since+"\"", "--until=\""+lastDay+"\"", "--merges", "--pretty=format:%B") //nolint:gosec
120+
} else if *since != "" || *until != "" {
121+
fmt.Println("--since and --until are required together or both unset")
122+
return 1
123+
} else {
124+
commitRange = lastTag()
125+
cmd = exec.Command("git", "rev-list", commitRange+"..HEAD", "--merges", "--pretty=format:%B") //nolint:gosec
126+
}
95127

96128
merges := map[string][]string{
97129
features: {},
@@ -170,7 +202,7 @@ func run() int {
170202
}
171203

172204
// TODO Turn this into a link (requires knowing the project name + organization)
173-
fmt.Printf("Changes since %v\n---\n", lastTag)
205+
fmt.Printf("Changes since %v\n---\n", commitRange)
174206

175207
for _, key := range outputOrder {
176208
mergeslice := merges[key]

0 commit comments

Comments
 (0)