Skip to content

Commit 1a816d1

Browse files
scripts/bumper: allow looking through history for missing commits
Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 35da5f6 commit 1a816d1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/bumper/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os/signal"
1313
"path/filepath"
1414
"regexp"
15+
"strconv"
1516
"strings"
1617
"text/tabwriter"
1718
"time"
@@ -56,6 +57,7 @@ type options struct {
5657
logLevel string
5758
centralRef string
5859
fetchMode string
60+
history int
5961

6062
dryRun bool
6163
githubLogin string
@@ -79,6 +81,7 @@ func (o *options) Bind(fs *flag.FlagSet) {
7981
fs.StringVar(&o.logLevel, "log-level", logrus.InfoLevel.String(), "Logging level.")
8082
fs.StringVar(&o.centralRef, "central-ref", "origin/master", "Git ref for the central branch that will be updated, used as the base for determining what commits need to be cherry-picked.")
8183
fs.StringVar(&o.fetchMode, "fetch-mode", string(ssh), "Method to use for fetching from git remotes.")
84+
fs.IntVar(&o.history, "history", 1, "How many commits back to start searching for missing vendor commits.")
8285

8386
fs.BoolVar(&o.dryRun, "dry-run", true, "Whether to actually create the pull request with github client")
8487
fs.StringVar(&o.githubLogin, "github-login", githubLogin, "The GitHub username to use.")
@@ -164,7 +167,7 @@ func main() {
164167
logrus.WithError(err).Fatal("could not unmarshal input commits")
165168
}
166169
} else {
167-
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef, fetchMode(opts.fetchMode))
170+
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef, fetchMode(opts.fetchMode), opts.history)
168171
if err != nil {
169172
logger.WithError(err).Fatal("failed to detect commits")
170173
}
@@ -265,7 +268,7 @@ type commit struct {
265268
var repoRegex = regexp.MustCompile(`Upstream-repository: ([^ ]+)\n`)
266269
var commitRegex = regexp.MustCompile(`Upstream-commit: ([a-f0-9]+)\n`)
267270

268-
func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, centralRef string, mode fetchMode) ([]commit, error) {
271+
func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, centralRef string, mode fetchMode, history int) ([]commit, error) {
269272
lastCommits := map[string]string{}
270273
if err := fs.WalkDir(os.DirFS(stagingDir), ".", func(path string, d fs.DirEntry, err error) error {
271274
if err != nil {
@@ -283,11 +286,12 @@ func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, cen
283286
output, err := runCommand(logger, exec.CommandContext(ctx,
284287
"git", "log",
285288
centralRef,
286-
"-n", "1",
289+
"-n", strconv.Itoa(history),
287290
"--grep", "Upstream-repository: "+path,
288291
"--grep", "Upstream-commit",
289292
"--all-match",
290293
"--pretty=%B",
294+
"--reverse",
291295
"--",
292296
filepath.Join(stagingDir, path),
293297
))
@@ -334,6 +338,7 @@ func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, cen
334338
output, err := runCommand(logger, exec.CommandContext(ctx,
335339
"git", "log",
336340
"--pretty=%H",
341+
"--no-merges",
337342
lastCommit+"...FETCH_HEAD",
338343
))
339344
if err != nil {

0 commit comments

Comments
 (0)