Skip to content

Commit ed3dfff

Browse files
JohnChen0SkCQ
authored andcommitted
[CBB] Make commit hash optional on CBB runner command line
Change-Id: Id9c35734cda0b46e6ba90e3d45ee1c329cd2688b Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/1062425 Reviewed-by: Farid (Mojtaba) Faridzad <[email protected]> Commit-Queue: John Chen <[email protected]>
1 parent ede0e57 commit ed3dfff

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

pinpoint/go/workflows/sample/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ go_library(
88
deps = [
99
"//go/skerr",
1010
"//go/sklog",
11+
"//pinpoint/go/backends",
1112
"//pinpoint/go/common",
1213
"//pinpoint/go/workflows",
1314
"//pinpoint/go/workflows/catapult",

pinpoint/go/workflows/sample/main.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
apipb "go.chromium.org/luci/swarming/proto/api_v2"
1616
"go.skia.org/infra/go/skerr"
1717
"go.skia.org/infra/go/sklog"
18+
"go.skia.org/infra/pinpoint/go/backends"
1819
"go.skia.org/infra/pinpoint/go/common"
1920
"go.skia.org/infra/pinpoint/go/workflows"
2021
"go.skia.org/infra/pinpoint/go/workflows/catapult"
@@ -326,13 +327,35 @@ func triggerCbbRunner(c client.Client) (*internal.CommitRun, error) {
326327
if len(flag.Args()) != 0 {
327328
return nil, fmt.Errorf("Unrecognized command line arguments: %v", flag.Args())
328329
}
329-
if *commit == "" {
330-
return nil, errors.New("Please specify a commit hash using --commit switch")
331-
}
332330
if *commitPosition == 0 {
333331
return nil, errors.New("Please specify a commit position using --commit-position switch")
334332
}
335333
ctx := context.Background()
334+
// If the user didn't specify a commit hash (so that *commit has the
335+
// default value), or the user specified an empty commit hash,
336+
// we try to get the commit hash from the commit position.
337+
if *commit == flag.Lookup("commit").DefValue || *commit == "" {
338+
crrev, err := backends.NewCrrevClient(ctx)
339+
if err != nil {
340+
return nil, skerr.Wrapf(err, "unable to create crrev client")
341+
}
342+
ci, err := crrev.GetCommitInfo(ctx, strconv.Itoa(*commitPosition))
343+
if err != nil {
344+
return nil, skerr.Wrapf(err, "unable to get commit info")
345+
}
346+
if len(ci.GitHash) != 40 {
347+
// When given an invalid commit position, NewCrrevClient doesn't
348+
// return an error, but converts the commit position into a string.
349+
// Since a valid commit hash must be 40 characters long, we assume
350+
// an error if the length is incorrect.
351+
return nil, fmt.Errorf(
352+
"commit position %d appears invalid, GetCommitInfo returned %s",
353+
*commitPosition, ci.GitHash,
354+
)
355+
}
356+
*commit = ci.GitHash
357+
fmt.Println("Using commit hash", *commit, "based on commit position", *commitPosition)
358+
}
336359
p := &internal.CbbRunnerParams{
337360
BotConfig: *configuration,
338361
Commit: common.NewCombinedCommit(common.NewChromiumCommit(*commit)),

0 commit comments

Comments
 (0)