diff options
Diffstat (limited to 'git-codereview/branch.go')
| -rw-r--r-- | git-codereview/branch.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/git-codereview/branch.go b/git-codereview/branch.go index 13193ff..982c739 100644 --- a/git-codereview/branch.go +++ b/git-codereview/branch.go @@ -7,6 +7,7 @@ package main import ( "bytes" "fmt" + "net/url" "os" "os/exec" "regexp" @@ -322,6 +323,33 @@ func (b *Branch) GerritChange(c *Commit, extra ...string) (*GerritChange, error) return readGerritChange(id) } +// GerritChange returns the change metadata from the Gerrit server +// for the given changes, which each be be the result of fullChangeID(b, c) for some c. +// The extra strings are passed to the Gerrit API request as o= parameters, +// to enable additional information. Typical values include "LABELS" and "CURRENT_REVISION". +// See https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html for details. +func (b *Branch) GerritChanges(ids []string, extra ...string) ([][]*GerritChange, error) { + q := "" + for _, id := range ids { + if q != "" { + q += "&" + } + if strings.HasSuffix(id, "~") { + // result of fullChangeID(b, c) with missing Change-Id; don't send + q += "q=is:closed+is:open" // cannot match anything + continue + } + q += "q=change:" + url.QueryEscape(id) + } + if q == "" { + return nil, fmt.Errorf("no changes found") + } + for _, x := range extra { + q += "&o=" + url.QueryEscape(x) + } + return readGerritChanges(q) +} + // CommitByRev finds a unique pending commit by its git <rev>. // It dies if rev cannot be resolved to a commit or that commit is not // pending on b using the action ("mail", "submit") in the failure message. |
