@@ -28,6 +28,7 @@ import (
28
28
"os/exec"
29
29
"regexp"
30
30
"strings"
31
+ "time"
31
32
)
32
33
33
34
/*
60
61
61
62
fromTag = flag .String ("from" , "" , "The tag or commit to start from." )
62
63
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
+
63
67
tagRegex = regexp .MustCompile (`^\[release-[\w-\.]*\]` )
64
68
)
65
69
@@ -89,9 +93,37 @@ func firstCommit() string {
89
93
return string (bytes .TrimSpace (out ))
90
94
}
91
95
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
+
92
107
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
+ }
95
127
96
128
merges := map [string ][]string {
97
129
features : {},
@@ -170,7 +202,7 @@ func run() int {
170
202
}
171
203
172
204
// 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 )
174
206
175
207
for _ , key := range outputOrder {
176
208
mergeslice := merges [key ]
0 commit comments