maintner/maintnerd/maintapi: use project~numericId ID type in goFindTryWork

In rare cases, the project~branch~Change-Id change ID type will not
uniquely identify a Gerrit CL. Switch to the suggested¹ identifier
type project~numericId which can handle those cases.

¹ https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-id

Fixes golang/go#43312.

Change-Id: I17b6afecd45fc456cd1a2aec3c727f9b90b5a3ef
Reviewed-on: https://go-review.googlesource.com/c/build/+/279672
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
diff --git a/maintner/maintnerd/maintapi/api.go b/maintner/maintnerd/maintapi/api.go
index f68beee..8b366dc 100644
--- a/maintner/maintnerd/maintapi/api.go
+++ b/maintner/maintnerd/maintapi/api.go
@@ -10,6 +10,7 @@
 	"errors"
 	"fmt"
 	"log"
+	"net/url"
 	"regexp"
 	"sort"
 	"strings"
@@ -262,9 +263,15 @@
 			log.Printf("nil Gerrit CL %v", ci.ChangeNumber)
 			continue
 		}
-		comments, err := gerritc.ListChangeComments(ctx, ci.ID)
+		// There are rare cases when the project~branch~Change-Id triplet doesn't
+		// uniquely identify a change, but project~numericId does. It's important
+		// we select the right and only one change in this context, so prefer the
+		// project~numericId identifier type. See golang.org/issue/43312 and
+		// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-id.
+		changeID := fmt.Sprintf("%s~%d", url.PathEscape(ci.Project), ci.ChangeNumber)
+		comments, err := gerritc.ListChangeComments(ctx, changeID)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("gerritc.ListChangeComments(ctx, %q): %v", changeID, err)
 		}
 		work := tryWorkItem(cl, ci, comments)
 		if work.Project == "go" {