Skip to content

Commit fbd4ec9

Browse files
thepuddsgopherbot
authored andcommitted
cmd/gerritbot: fix ID used to post comments with PR rule findings
Use the more modern "<project>~<changeNumber>" format for a change and properly specify the first revision. While we are here, we add a few comments to the gerrit package to help avoid confusion in the future. This is a follow-up to CL 513397, which was failing to post the new PR rule findings for a test PR with error: 2023/08/15 22:06:38 processPullRequest: importGerritChangeFromPR(#71, nil): could not add findings comment to CL for #71: HTTP status 404 Not Found on request to https://go-review.googlesource.com/a/changes/If1a8ae9e4b76a05b13139ddf9fda1cdf67b50b33/revisions/build~master~If1a8ae9e4b76a05b13139ddf9fda1cdf67b50b33/review; Not found: build~master~If1a8ae9e4b76a05b13139ddf9fda1cdf67b50b33 Updates golang/go#61573 Change-Id: Ib0fef88ae05b10e623c2c1af614aa932dbfcc043 Reviewed-on: https://go-review.googlesource.com/c/build/+/519796 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: t hepudds <[email protected]>
1 parent e0cbf39 commit fbd4ec9

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

cmd/gerritbot/gerritbot.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,8 @@ Please visit Gerrit at %s.
810810
"/PATCHSET_LEVEL": {{Message: msg, Unresolved: &unresolved}},
811811
},
812812
}
813-
// TODO: instead of gcl.ID, we might need to do something similar to changeTriple in cmd/coordinator.
814-
err = b.gerritClient.SetReview(ctx, gcl.ChangeID, gcl.ID, ri)
813+
changeID := fmt.Sprintf("%s~%d", url.PathEscape(gcl.Project), gcl.ChangeNumber)
814+
err = b.gerritClient.SetReview(ctx, changeID, "1", ri)
815815
if err != nil {
816816
return fmt.Errorf("could not add findings comment to CL for %s: %v", prShortLink(pr), err)
817817
}

gerrit/gerrit.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,22 @@ const (
221221
// ChangeInfo is a Gerrit data structure.
222222
// See https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-info
223223
type ChangeInfo struct {
224-
// ID is the ID of the change in the format
225-
// "'<project>~<branch>~<Change-Id>'", where 'project',
226-
// 'branch' and 'Change-Id' are URL encoded. For 'branch' the
227-
// refs/heads/ prefix is omitted.
228-
ID string `json:"id"`
229-
ChangeNumber int `json:"_number"`
230-
ChangeID string `json:"change_id"`
224+
// The ID of the change. Subject to a 'GerritBackendFeature__return_new_change_info_id' experiment,
225+
// the format is either "'<project>~<_number>'" (new format),
226+
// or "'<project>~<branch>~<Change-Id>'" (old format).
227+
// 'project', '_number', and 'branch' are URL encoded.
228+
// For 'branch' the refs/heads/ prefix is omitted.
229+
// The callers must not rely on the format.
230+
ID string `json:"id"`
231+
232+
// ChangeNumber is a change number like "4247".
233+
ChangeNumber int `json:"_number"`
234+
235+
// ChangeID is the Change-Id footer value like "I8473b95934b5732ac55d26311a706c9c2bde9940".
236+
// Note that some of the functions in this package take a changeID parameter that is a {change-id},
237+
// which is a distinct concept from a Change-Id footer. (See the documentation links for details,
238+
// including https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-id).
239+
ChangeID string `json:"change_id"`
231240

232241
Project string `json:"project"`
233242

0 commit comments

Comments
 (0)