@@ -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