Documentation
¶
Overview ¶
Package gerritsdk provides a high-level Go client for Gerrit Code Review instances, with first-class support for Googlesource.com authentication.
Index ¶
- func ParseGitCookiesForHost(path, host string) (user, pass string, err error)
- type AuthMethod
- type BearerTokenAuth
- type BuildQuery
- func (q *BuildQuery) After(t time.Time) *BuildQuery
- func (q *BuildQuery) Before(t time.Time) *BuildQuery
- func (q *BuildQuery) File(path string) *BuildQuery
- func (q *BuildQuery) Owner(user string) *BuildQuery
- func (q *BuildQuery) Project(name string) *BuildQuery
- func (q *BuildQuery) Raw(fragment string) *BuildQuery
- func (q *BuildQuery) Status(status string) *BuildQuery
- func (q *BuildQuery) String() string
- type CL
- type CLFile
- type Client
- func (c *Client) GetChangeCommitMessage(ctx context.Context, changeID string) (string, error)
- func (c *Client) GetChangeDetail(ctx context.Context, changeID string) (*CL, error)
- func (c *Client) GetChangeDiff(ctx context.Context, changeID, filePath string) (*FileDiff, error)
- func (c *Client) GetChangeFiles(ctx context.Context, changeID string) ([]CLFile, error)
- func (c *Client) GetProject(ctx context.Context, name string) (*Project, error)
- func (c *Client) Host() string
- func (c *Client) Inner() *gogerrit.Client
- func (c *Client) ListProjectBranches(ctx context.Context, project string) ([]string, error)
- func (c *Client) ListProjects(ctx context.Context) ([]Project, error)
- func (c *Client) QueryChanges(ctx context.Context, query string, opts ...QueryOption) ([]CL, error)
- type DiffContent
- type FileDiff
- type GitCookiesAuth
- type HTTPBasicAuth
- type Link
- type Option
- type Project
- type QueryOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseGitCookiesForHost ¶
ParseGitCookiesForHost reads a .gitcookies file and returns credentials for the specified host.
Types ¶
type AuthMethod ¶
type AuthMethod interface {
// contains filtered or unexported methods
}
AuthMethod configures how the client authenticates with Gerrit.
type BearerTokenAuth ¶
type BearerTokenAuth struct {
Token string
}
BearerTokenAuth authenticates with an OAuth2 bearer token.
type BuildQuery ¶
type BuildQuery struct {
// contains filtered or unexported fields
}
BuildQuery is a helper for constructing Gerrit query strings.
func (*BuildQuery) After ¶
func (q *BuildQuery) After(t time.Time) *BuildQuery
After restricts to changes updated after a time.
func (*BuildQuery) Before ¶
func (q *BuildQuery) Before(t time.Time) *BuildQuery
Before restricts to changes updated before a time.
func (*BuildQuery) File ¶
func (q *BuildQuery) File(path string) *BuildQuery
File restricts to changes touching a file path (prefix match).
func (*BuildQuery) Owner ¶
func (q *BuildQuery) Owner(user string) *BuildQuery
Owner restricts to changes owned by a user.
func (*BuildQuery) Project ¶
func (q *BuildQuery) Project(name string) *BuildQuery
Project restricts to a project.
func (*BuildQuery) Raw ¶
func (q *BuildQuery) Raw(fragment string) *BuildQuery
Raw adds a raw query fragment.
func (*BuildQuery) Status ¶
func (q *BuildQuery) Status(status string) *BuildQuery
Status restricts to a change status.
func (*BuildQuery) String ¶
func (q *BuildQuery) String() string
String returns the assembled query.
type CL ¶
type CL struct {
Number int `json:"number"`
Project string `json:"project"`
Branch string `json:"branch"`
ChangeID string `json:"change_id"`
Subject string `json:"subject"`
Status string `json:"status"` // NEW, MERGED, ABANDONED
Owner string `json:"owner"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Submitted time.Time `json:"submitted,omitempty"`
Mergeable bool `json:"mergeable,omitempty"`
URL string `json:"url"`
Files []string `json:"files,omitempty"`
}
CL represents a Gerrit change (changelist).
type CLFile ¶
type CLFile struct {
Path string `json:"path"`
Status string `json:"status"` // ADDED, MODIFIED, DELETED, RENAMED, COPIED
OldPath string `json:"old_path,omitempty"`
Insertions int `json:"insertions"`
Deletions int `json:"deletions"`
}
CLFile represents a file changed in a CL revision.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a high-level Gerrit REST API client.
func NewAnonymousClient ¶
NewAnonymousClient creates an unauthenticated Gerrit client. Only public endpoints will be accessible.
func NewClient ¶
NewClient creates a Gerrit client for the given host. The host should be a bare hostname like "bazel-review.googlesource.com".
func (*Client) GetChangeCommitMessage ¶
GetChangeCommitMessage returns the commit message for a change.
func (*Client) GetChangeDetail ¶
GetChangeDetail returns detailed information about a single change.
func (*Client) GetChangeDiff ¶
GetChangeDiff returns the diff for a specific file in a change.
func (*Client) GetChangeFiles ¶
GetChangeFiles returns the list of files modified in the current patchset.
func (*Client) GetProject ¶
GetProject returns details about a specific project.
func (*Client) ListProjectBranches ¶
ListProjectBranches returns branches for a project.
func (*Client) ListProjects ¶
ListProjects returns all projects on the Gerrit instance.
func (*Client) QueryChanges ¶
QueryChanges searches for changes matching the given Gerrit query string. Example queries:
"project:bazel status:merged file:docs/" "status:open owner:self"
type DiffContent ¶
type DiffContent struct {
Common []string `json:"ab,omitempty"` // lines common to both
OldOnly []string `json:"a,omitempty"` // lines only in old version
NewOnly []string `json:"b,omitempty"` // lines only in new version
}
DiffContent represents a segment of a unified diff returned by Gerrit.
type FileDiff ¶
type FileDiff struct {
Path string `json:"path"`
Content []DiffContent `json:"content"`
}
FileDiff represents the diff for a single file.
type GitCookiesAuth ¶
type GitCookiesAuth struct {
Path string // path to .gitcookies file; empty = ~/.gitcookies
}
GitCookiesAuth authenticates using a .gitcookies file, the standard method for googlesource.com instances.
type HTTPBasicAuth ¶
HTTPBasicAuth authenticates with a username and password/token.
type Option ¶
type Option func(*clientConfig)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient sets a custom http.Client for the underlying transport.
type Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
State string `json:"state"` // ACTIVE, READ_ONLY, HIDDEN
WebLinks []Link `json:"web_links,omitempty"`
}
Project represents a Gerrit project (repository).
type QueryOption ¶
type QueryOption func(*queryConfig)
QueryOption modifies a change query.
func WithFields ¶
func WithFields(fields ...string) QueryOption
WithFields requests additional fields (e.g. "CURRENT_REVISION", "ALL_FILES").
func WithOffset ¶
func WithOffset(n int) QueryOption
WithOffset sets the result offset for pagination.