gerrit

package
v0.0.0-...-a70aae3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 25 Imported by: 28

Documentation

Index

Constants

View Source
const (
	// GerritTimestampLayout is the timestamp format used in Gerrit.
	//
	// Timestamp is given in UTC and has the format 'yyyy-mm-dd hh:mm:ss.fffffffff' where
	// 'ffffffffff' represents nanoseconds. See:
	// https://gerrit-review.googlesource.com/Documentation/rest-api.html#timestamp
	GerritTimestampLayout = "2006-01-02 15:04:05.000000000"
)
View Source
const (
	// OAuthScope is the OAuth 2.0 scope that must be included when acquiring an
	// access token for Gerrit RPCs.
	OAuthScope = "https://www.googleapis.com/auth/gerritcodereview"
)

Variables

View Source
var (
	RevisionRework                 RevisionKind = "REWORK"
	RevisionTrivialRebase                       = "TRIVIAL_REBASE"
	RevisionMergeFirstParentUpdate              = "MERGE_FIRST_PARENT_UPDATE"
	RevisionNoCodeChange                        = "NO_CODE_CHANGE"
	RevisionNoChange                            = "NO_CHANGE"
)

Known revision kinds.

Functions

func FormatTime

func FormatTime(t time.Time) string

FormatTime formats time.Time for Gerrit consumption.

func FuzzyParseURL

func FuzzyParseURL(s string) (string, int64, error)

FuzzyParseURL attempts to match the given URL to a Gerrit change, as identified by a host and change number.

NOTE that this is not guaranteed to be correct, as there is room for some ambiguity in Gerrit URLs

func NewRESTClient

func NewRESTClient(httpClient *http.Client, host string, auth bool) (gerritpb.GerritClient, error)

NewRESTClient creates a new Gerrit client based on Gerrit's REST API.

The host must be a full Gerrit host, e.g. "chromium-review.googlesource.com".

If `auth` is true, this indicates that the given HTTP client sends authenticated requests. If so, the requests to Gerrit will include "/a/" URL path prefix.

RPC methods of the returned client return an error if a grpc.CallOption is passed.

func NormalizeGerritURL

func NormalizeGerritURL(gerritURL string) (string, error)

NormalizeGerritURL returns canonical for Gerrit URL.

error is returned if validation fails.

func PagingListChanges

PagingListChanges is a wrapper around Gerrit.ListChanges RPC that correctly "pages" through responses.

Unlike typical but incorrect paging via ListChangesRequest.Offset argument, this function correctly fetches all changes up to a desired limit relying on undocumented ordering of changes in the ListChanges response by descending ChangeInfo.Updated timestamp.

ListChangesRequest.Limit and ListChangesRequest.Offset must not be set.

ListChangesRequest.Query may contain before: until: since: after: predicates, but it's more efficient to specify those via PagingListChangesOptions UpdatedAfter and UpdatedBefore options.

On error, also returns partial results fetched so far and .MoreChanges=true.

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime returns time.Time givne its Gerrit representation.

func UseGerritMirror

func UseGerritMirror(altHost func(host string) string) grpc.CallOption

UseGerritMirror can be passed as grpc.CallOption to Gerrit client to select an alternative Gerrit host to the one configured in the client "on the fly".

func ValidateGerritURL

func ValidateGerritURL(gerritURL string) error

ValidateGerritURL validates Gerrit URL for use in this package.

Types

type AbandonInput

type AbandonInput struct {
	// Message to be added as review comment to the change when abandoning it.
	Message string `json:"message,omitempty"`

	// Notify is an enum specifying whom to send notifications to.
	//
	// Valid values are NONE, OWNER, OWNER_REVIEWERS, and ALL.
	//
	// Optional. The default is ALL.
	Notify string `json:"notify,omitempty"`
}

AbandonInput contains information for abandoning a change.

This struct is intended to be one-to-one with the AbandonInput structure described in Gerrit's documentation: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#abandon-input

TODO(mknyszek): Support notify_details.

type AccountInfo

type AccountInfo struct {
	// AccountID is the numeric ID of the account managed by Gerrit, and is guaranteed to
	// be unique.
	AccountID int `json:"_account_id,omitempty"`

	// Name is the full name of the user.
	Name string `json:"name,omitempty"`

	// Email is the email address the user prefers to be contacted through.
	Email string `json:"email,omitempty"`

	// SecondaryEmails is a list of secondary email addresses of the user.
	SecondaryEmails []string `json:"secondary_emails,omitempty"`

	// Username is the username of the user.
	Username string `json:"username,omitempty"`

	// MoreAccounts represents whether the query would deliver more results if not limited.
	// Only set on the last account that is returned.
	MoreAccounts bool `json:"_more_accounts,omitempty"`
}

AccountInfo contains information about an account.

type AccountQueryParams

type AccountQueryParams struct {
	// Actual query string, see
	// https://gerrit-review.googlesource.com/Documentation/user-search-accounts.html#_search_operators
	Query string `json:"q"`
	// How many changes to include in the response.
	N int `json:"n"`
	// Skip this many from the list of results (unreliable for paging).
	S int `json:"S"`
	// Include these options in the queries. Certain options will make
	// Gerrit fill in additional fields of the response. These require
	// additional database searches and may delay the response.
	//
	// The supported strings for options are listed in Gerrit's api
	// documentation at the link below:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html
	Options []string `json:"o"`
}

AccountQueryParams contains the parameters necessary for querying accounts from Gerrit.

type AddReviewerResult

type AddReviewerResult struct {
	// Input is the value of the `reviewer` field from ReviewerInput set while adding the reviewer.
	Input string `json:"input"`

	// Reviewers is a list of newly added reviewers.
	Reviewers []ReviewerInfo `json:"reviewers,omitempty"`

	// CCs is a list of newly CCed accounts. This field will only appear if the requested `state`
	// for the reviewer was CC and NoteDb is enabled on the server.
	CCs []ReviewerInfo `json:"ccs,omitempty"`

	// Error is a message explaining why the reviewer could not be added.
	//
	// If a group was specified in the input and an error is returned, that means none of the
	// members were added as reviewer.
	Error string `json:"error,omitempty"`

	// Confirm represents whether adding the reviewer requires confirmation.
	Confirm bool `json:"confirm,omitempty"`
}

AddReviewerResult describes the result of adding a reviewer to a change.

type BranchInfo

type BranchInfo struct {
	// Ref is the ref of the branch.
	Ref string `json:"ref"`

	// Revision is the revision to which the branch points.
	Revision string `json:"revision"`
}

BranchInfo contains information about a branch.

type BranchInput

type BranchInput struct {
	// Ref is the name of the branch.
	Ref string `json:"ref,omitempty"`

	// Revision is the base revision of the new branch.
	Revision string `json:"revision,omitempty"`
}

BranchInput contains information for creating a branch.

type Change

type Change struct {
	ChangeNumber           int                     `json:"_number"`
	ID                     string                  `json:"id"`
	ChangeID               string                  `json:"change_id"`
	Project                string                  `json:"project"`
	Branch                 string                  `json:"branch"`
	Topic                  string                  `json:"topic"`
	Hashtags               []string                `json:"hashtags"`
	Subject                string                  `json:"subject"`
	Status                 string                  `json:"status"`
	Created                string                  `json:"created"`
	Updated                string                  `json:"updated"`
	Mergeable              bool                    `json:"mergeable,omitempty"`
	Messages               []ChangeMessageInfo     `json:"messages"`
	Submittable            bool                    `json:"submittable,omitempty"`
	Submitted              string                  `json:"submitted"`
	SubmitType             string                  `json:"submit_type"`
	Insertions             int                     `json:"insertions"`
	Deletions              int                     `json:"deletions"`
	UnresolvedCommentCount int                     `json:"unresolved_comment_count"`
	HasReviewStarted       bool                    `json:"has_review_started"`
	Owner                  AccountInfo             `json:"owner"`
	Labels                 map[string]LabelInfo    `json:"labels"`
	Submitter              AccountInfo             `json:"submitter"`
	Reviewers              Reviewers               `json:"reviewers"`
	RevertOf               int                     `json:"revert_of"`
	CurrentRevision        string                  `json:"current_revision"`
	WorkInProgress         bool                    `json:"work_in_progress,omitempty"`
	CherryPickOfChange     int                     `json:"cherry_pick_of_change"`
	CherryPickOfPatchset   int                     `json:"cherry_pick_of_patch_set"`
	Revisions              map[string]RevisionInfo `json:"revisions"`
	// MoreChanges is not part of a Change, but gerrit piggy-backs on the
	// last Change in a page to set this flag if there are more changes
	// in the results of a query.
	MoreChanges bool `json:"_more_changes"`
}

Change represents a Gerrit CL. Information about these fields in: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-info

Note that not all fields will be filled for all CLs and queries depending on query options, and not all fields exposed by Gerrit are captured by this struct. Adding more fields to this struct should be okay (but only Gerrit-supported keys will be populated).

TODO(nodir): replace this type with https://godoc.org/go.chromium.org/luci/common/proto/gerrit#ChangeInfo.

type ChangeDetailsParams

type ChangeDetailsParams struct {
	// Options is a set of optional details to add as additional fieldsof the response.
	// These require additional database searches and may delay the response.
	//
	// The supported strings for options are listed in Gerrit's api
	// documentation at the link below:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
	Options []string `json:"o"`
}

ChangeDetailsParams contains optional parameters for getting change details from Gerrit.

type ChangeInput

type ChangeInput struct {
	// Project is the name of the project for this change.
	Project string `json:"project"`

	// Branch is the name of the target branch for this change.
	// refs/heads/ prefix is omitted.
	Branch string `json:"branch"`

	// Subject is the header line of the commit message.
	Subject string `json:"subject"`

	// Topic is the topic to which this change belongs. Optional.
	Topic string `json:"topic,omitempty"`

	// IsPrivate sets whether the change is marked private.
	IsPrivate bool `json:"is_private,omitempty"`

	// WorkInProgress sets the work-in-progress bit for the change.
	WorkInProgress bool `json:"work_in_progress,omitempty"`

	// BaseChange is the change this new change is based on. Optional.
	//
	// This can be anything Gerrit expects as a ChangeID. We recommend <numericId>,
	// but the full list of supported formats can be found here:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-id
	BaseChange string `json:"base_change,omitempty"`

	// NewBranch allows for creating a new branch when set to true.
	NewBranch bool `json:"new_branch,omitempty"`

	// Notify is an enum specifying whom to send notifications to.
	//
	// Valid values are NONE, OWNER, OWNER_REVIEWERS, and ALL.
	//
	// Optional. The default is ALL.
	Notify string `json:"notify,omitempty"`
}

ChangeInput contains the parameters necessary for creating a change in Gerrit.

This struct is intended to be one-to-one with the ChangeInput structure described in Gerrit's documentation: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-input

The exception is only status, which is always "NEW" and is therefore unavailable in this struct.

TODO(mknyszek): Support merge and notify_details.

type ChangeMessageInfo

type ChangeMessageInfo struct {
	ID         string      `json:"id"`
	Author     AccountInfo `json:"author,omitempty"`
	RealAuthor AccountInfo `json:"real_author,omitempty"`
	Date       Timestamp   `json:"date"`
	Message    string      `json:"message"`
	Tag        string      `json:"tag,omitempty"`
}

ChangeMessageInfo contains information about a message attached to a change: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-message-info

type ChangeQueryParams

type ChangeQueryParams struct {
	// Actual query string, see
	// https://gerrit-review.googlesource.com/Documentation/user-search.html#_search_operators
	Query string `json:"q"`
	// How many changes to include in the response.
	N int `json:"n"`
	// Skip this many from the list of results (unreliable for paging).
	S int `json:"S"`
	// Include these options in the queries. Certain options will make
	// Gerrit fill in additional fields of the response. These require
	// additional database searches and may delay the response.
	//
	// The supported strings for options are listed in Gerrit's api
	// documentation at the link below:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
	Options []string `json:"o"`
}

ChangeQueryParams contains the parameters necessary for querying changes from Gerrit.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a production Gerrit client, instantiated via NewClient(), and uses an http.Client along with a validated url to communicate with Gerrit.

func NewClient

func NewClient(c *http.Client, gerritURL string) (*Client, error)

NewClient creates a new instance of Client and validates and stores the URL to reach Gerrit. The result is wrapped inside a Client so that the apis can be called directly on the value returned by this function.

func (*Client) AbandonChange

func (c *Client) AbandonChange(ctx context.Context, changeID string, ai *AbandonInput) (*Change, error)

AbandonChange abandons an existing change in Gerrit.

Returns a Change referenced by changeID, with status ABANDONED, if abandoned.

AbandonInput is optional (that is, may be nil).

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

func (*Client) AccountQuery

func (c *Client) AccountQuery(ctx context.Context, qr AccountQueryParams) ([]*AccountInfo, bool, error)

AccountQuery gets all matching accounts.

Only the .Query property of the qr parameter is required.

Returns a slice of AccountInfo, whether there are more accounts to fetch, and an error.

https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html

func (*Client) ChangeDetails

func (c *Client) ChangeDetails(ctx context.Context, changeID string, options ChangeDetailsParams) (*Change, error)

ChangeDetails gets details about a single change with optional fields.

This method returns a single *Change and an error.

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

options is a list of strings like {"CURRENT_REVISION"} which tells Gerrit to return non-default properties for Change. The supported strings for options are listed in Gerrit's api documentation at the link below: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes

func (*Client) ChangeQuery

func (c *Client) ChangeQuery(ctx context.Context, qr ChangeQueryParams) ([]*Change, bool, error)

ChangeQuery returns a list of Gerrit changes for a given ChangeQueryParams.

One example use case for this is getting the CL for a given commit hash. Only the .Query property of the qr parameter is required.

Returns a slice of Change, whether there are more changes to fetch and an error.

func (*Client) ChangesSubmittedTogether

func (c *Client) ChangesSubmittedTogether(ctx context.Context, changeID string, options ChangeDetailsParams) (*SubmittedTogetherInfo, error)

ChangesSubmittedTogether returns a list of Gerrit changes which are submitted when Submit is called for the given change, including the current change itself. As a special case, the list is empty if this change would be submitted by itself (without other changes).

Returns a slice of Change and an error.

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submitted-together

options is a list of strings like {"CURRENT_REVISION"} which tells Gerrit to return non-default properties for each Change. The supported strings for options are listed in Gerrit's api documentation at the link below: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes

func (*Client) CreateBranch

func (c *Client) CreateBranch(ctx context.Context, projectID string, bi *BranchInput) (*BranchInfo, error)

CreateBranch creates a branch.

Returns BranchInfo, or an error if the branch could not be created.

See the link below for API documentation. https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#create-branch

func (*Client) CreateChange

func (c *Client) CreateChange(ctx context.Context, ci *ChangeInput) (*Change, error)

CreateChange creates a new change in Gerrit.

Returns a Change describing the newly created change or an error.

func (*Client) GetMergeable

func (c *Client) GetMergeable(ctx context.Context, changeID string, revisionID string) (*MergeableResult, error)

GetMergeable API checks if a change is ready to be submitted cleanly.

Returns a MergeableResult that has details if the change be merged or not.

func (*Client) IsChangePureRevert

func (c *Client) IsChangePureRevert(ctx context.Context, changeID string) (bool, error)

IsChangePureRevert determines if a change is a pure revert of another commit.

This method returns a bool and an error.

To determine which commit the change is purportedly reverting, use the revert_of property of the change.

Gerrit's doc for the api: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-pure-revert

func (*Client) ListAccountEmails

func (c *Client) ListAccountEmails(email string) ([]*EmailInfo, error)

ListAccountEmails returns the email addresses linked in the given Gerrit account.

func (*Client) ListChangeComments

func (c *Client) ListChangeComments(ctx context.Context, changeID string, revisionID string) (map[string][]Comment, error)

ListChangeComments gets all comments on a single change.

This method returns a list of comments for each file path (including pseudo-files like '/PATCHSET_LEVEL' and '/COMMIT_MSG') and an error.

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

func (*Client) ListRobotComments

func (c *Client) ListRobotComments(ctx context.Context, changeID string, revisionID string) (map[string][]RobotComment, error)

ListRobotComments gets all robot comments on a single change.

This method returns a list of robot comments for each file path (including pseudo-files like '/PATCHSET_LEVEL' and '/COMMIT_MSG') and an error.

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

func (*Client) Ready

func (c *Client) Ready(ctx context.Context, changeID string, ri *WipInput) (any, error)

Ready marks a change as ready-for-review in Gerrit.

Returns a Change referenced by changeID, if successful.

WipInput is optional (that is, may be nil).

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

func (*Client) RebaseChange

func (c *Client) RebaseChange(ctx context.Context, changeID string, ri *RebaseInput) (*Change, error)

RebaseChange rebases an open change on top of a specified revision (or its parent change, if no revision is specified).

Returns a Change referenced by changeID, if rebased.

RebaseInput is optional (that is, may be nil).

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

func (*Client) RestoreChange

func (c *Client) RestoreChange(ctx context.Context, changeID string, ri *RestoreInput) (*Change, error)

RestoreChange restores an existing abandoned change in Gerrit.

Returns a Change referenced by changeID, if restored.

RestoreInput is optional (that is, may be nil).

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

func (*Client) SetReview

func (c *Client) SetReview(ctx context.Context, changeID string, revisionID string, ri *ReviewInput) (*ReviewResult, error)

SetReview sets a review on a revision, optionally also publishing draft comments, setting labels, adding reviewers or CCs, and modifying the work in progress property.

Returns a ReviewResult which describes the applied labels and any added reviewers.

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

The revisionID parameter may be in any of the forms supported by Gerrit:

  • "current"
  • a commit ID
  • "0" or the literal "edit" for a change edit
  • etc. See the link below.

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

func (*Client) Submit

func (c *Client) Submit(ctx context.Context, changeID string, si *SubmitInput) (*Change, error)

Submit submits a change to the repository. It bypasses the Commit Queue.

Returns a Change.

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

func (*Client) Wip

func (c *Client) Wip(ctx context.Context, changeID string, ri *WipInput) (any, error)

Wip marks a change as work-in-progress in Gerrit.

Returns a Change referenced by changeID, if successful.

WipInput is optional (that is, may be nil).

The changeID parameter may be in any of the forms supported by Gerrit:

  • "4247"
  • "I8473b95934b5732ac55d26311a706c9c2bde9940"
  • etc. See the link below.

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

type Comment

type Comment struct {
	ID              string       `json:"id"`
	Owner           AccountInfo  `json:"author"`
	ChangeMessageID string       `json:"change_message_id"`
	PatchSet        int          `json:"patch_set"`
	Line            int          `json:"line"`
	Range           CommentRange `json:"range"`
	Updated         string       `json:"updated"`
	Message         string       `json:"message"`
	Unresolved      bool         `json:"unresolved"`
	InReplyTo       string       `json:"in_reply_to"`
	CommitID        string       `json:"commit_id"`
}

Comment represents a comment on a Gerrit CL. Information about these fields is in: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#comment-info

Note that not all fields will be filled for all comments depending on the way the comment was added to Gerrit, and not all fields exposed by Gerrit are captured by this struct. Adding more fields to this struct should be okay (but only Gerrit-supported keys will be populated).

type CommentInput

type CommentInput struct {
	// The URL encoded UUID of the comment if an existing draft comment should be updated.
	// Optional
	ID string `json:"id,omitempty"`

	// The file path for which the inline comment should be added.
	// Doesn’t need to be set if contained in a map where the key is the file path.
	// Optional
	Path string `json:"path,omitempty"`

	// The side on which the comment should be added.
	// Allowed values are REVISION and PARENT.
	// If not set, the default is REVISION.
	// Optional
	Side string `json:"side,omitempty"`

	// The number of the line for which the comment should be added.
	// 0 if it is a file comment.
	// If neither line nor range is set, a file comment is added.
	// If range is set, this value is ignored in favor of the end_line of the range.
	// Optional
	Line int `json:"line,omitempty"`

	// The range of the comment as a CommentRange entity.
	// Optional
	Range CommentRange `json:"range,omitempty"`

	// The URL encoded UUID of the comment to which this comment is a reply.
	// Optional
	InReplyTo string `json:"in_reply_to,omitempty"`

	// The comment message.
	// If not set and an existing draft comment is updated, the existing draft comment is deleted.
	// Optional
	Message string `json:"message,omitempty"`

	// Value of the tag field. Only allowed on draft comment inputs;
	// for published comments, use the tag field in ReviewInput.
	// Votes/comments that contain tag with 'autogenerated:' prefix can be filtered out in the web UI.
	// Optional
	Tag string `json:"tag,omitempty"`

	// Whether or not the comment must be addressed by the user.
	// This value will default to false if the comment is an orphan, or the
	// value of the in_reply_to comment if it is supplied.
	// Optional
	Unresolved bool `json:"unresolved,omitempty"`
}

The CommentInput entity contains information for creating an inline comment.

type CommentRange

type CommentRange struct {
	StartLine      int `json:"start_line,omitempty"`
	StartCharacter int `json:"start_character,omitempty"`
	EndLine        int `json:"end_line,omitempty"`
	EndCharacter   int `json:"end_character,omitempty"`
}

CommentRange is included within Comment. See Comment for more details.

type CommitInfo

type CommitInfo struct {
	Commit    string       `json:"commit,omitempty"`
	Parents   []CommitInfo `json:"parents,omitempty"`
	Author    AccountInfo  `json:"author,omitempty"`
	Committer AccountInfo  `json:"committer,omitempty"`
	Subject   string       `json:"subject,omitempty"`
	Message   string       `json:"message,omitempty"`
}

CommitInfo contains information about a commit. https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#commit-info

TODO(kjharland): Support remaining fields.

type EmailInfo

type EmailInfo struct {
	// Email address linked to the user account.
	Email string `json:"email"`

	// Set true if the email address is set as preferred.
	Preferred bool `json:"preferred"`

	// Set true if the user must confirm control of the email address by following
	// a verification link before Gerrit will permit use of this address.
	PendingConfirmation bool `json:"pending_confirmation"`
}

EmailInfo contains the response fields from ListAccountEmails.

type FileInfo

type FileInfo struct {
	Status        string `json:"status,omitempty"`
	Binary        bool   `json:"binary,omitempty"`
	OldPath       string `json:"old_path,omitempty"`
	LinesInserted int    `json:"lines_inserted,omitempty"`
	LinesDeleted  int    `json:"lines_deleted,omitempty"`
	SizeDelta     int64  `json:"size_delta"`
	Size          int64  `json:"size"`
}

FileInfo contains information about a file in a patch set. https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#file-info

type FixSuggestion

type FixSuggestion struct {
	Description  string        `json:"description"`
	Replacements []Replacement `json:"replacements"`
}

FixSuggestion represents a suggested fix for a robot comment.

type LabelInfo

type LabelInfo struct {
	// Optional reflects whether the label is optional (neither necessary
	// for nor blocking submission).
	Optional bool `json:"optional,omitempty"`

	// Approved refers to one user who approved this label (max value).
	Approved *AccountInfo `json:"approved,omitempty"`

	// Rejected refers to one user who rejected this label (min value).
	Rejected *AccountInfo `json:"rejected,omitempty"`

	// Recommended refers to one user who recommended this label (positive
	// value, but not max).
	Recommended *AccountInfo `json:"recommended,omitempty"`

	// Disliked refers to one user who disliked this label (negative value
	// but not min).
	Disliked *AccountInfo `json:"disliked,omitempty"`

	// Blocking reflects whether this label block the submit operation.
	Blocking bool `json:"blocking,omitempty"`

	All    []VoteInfo        `json:"all,omitempty"`
	Values map[string]string `json:"values,omitempty"`
}

LabelInfo contains information about a label on a change, always corresponding to the current patch set.

Only one of Approved, Rejected, Recommended, and Disliked will be set, with priority Rejected > Approved > Recommended > Disliked if multiple users have given the label different values.

TODO(mknyszek): Support 'value' and 'default_value' fields, as well as the fields given with the query parameter DETAILED_LABELS.

type MergeableResult

type MergeableResult struct {

	// Mergeable marks if the change is ready to be submitted cleanly, false otherwise
	Mergeable bool `json:"mergeable"`
}

MergeableResult contains information if the change for the revision can be merged or not.

type PagingListChangesClient

type PagingListChangesClient interface {
	ListChanges(context.Context, *gerritpb.ListChangesRequest, ...grpc.CallOption) (*gerritpb.ListChangesResponse, error)
}

PagingListChangesClient defines what PageListChanges actually needs from Gerrit client.

type PagingListChangesOptions

type PagingListChangesOptions struct {
	// Limit limits how many changes to fetch in total. Required. Must be >0.
	Limit int

	// PageSize limits how many change to fetch per RPC request.
	// Defaults to 100. Maximum allowed is 1000.
	PageSize int

	// MoreChangesTrustFactor limits trust in MoreChanges=false from a
	// Gerrit RPC response to only when RPC returned fewer changes
	// than PageSize*MoreChangesTrustFactor.
	//
	// Must be in (0, 1] range. 1 means always trust. Defaults to 0.9.
	//
	// Lower value is recommended when a query matches many changes which are not
	// visible to the account making the request. Due to internal Gerrit
	// implementation quirk, in such cases .MoreChanges=false can be set
	// incorrectly, meaning even when there are more results than requested.
	//
	// For certainty, set this to 0.001. In the worst case, it'd result in one
	// additional ListChanges RPC.
	MoreChangesTrustFactor float64

	// UpdatedAfter can be used to limit which changes the query should cover.
	// NOTE: it is inclusive, just like Gerrit's `after:` query predicate.
	// Defaults to no restriction.
	UpdatedAfter time.Time
	// UpdatedBefore can be used to limit which changes the query should cover.
	// NOTE: it is inclusive, just like Gerrit's `before:` query predicate.
	// Defaults to no restriction.
	UpdatedBefore time.Time
}

PagingListChangesOptions customizes behavior of PagingListChanges function.

type RebaseInput

type RebaseInput struct {
	// Base is the revision to rebase on top of.
	Base string `json:"base,omitempty"`

	// AllowConflicts allows the rebase to succeed even if there are conflicts.
	AllowConflicts bool `json:"allow_conflicts,omitempty"`

	// OnBehalfOfUploader causes the rebase to be done on behalf of the
	// uploader. This means the uploader of the current patch set will also be
	// the uploader of the rebased patch set.
	//
	// Rebasing on behalf of the uploader is only supported for trivial rebases.
	// This means this option cannot be combined with the `allow_conflicts`
	// option.
	OnBehalfOfUploader bool `json:"on_behalf_of_uploader,omitempty"`
}

RebaseInput contains information for rebasing a change.

type Replacement

type Replacement struct {
	Path        string        `json:"path"`
	Replacement string        `json:"replacement"`
	Range       *CommentRange `json:"range,omitempty"`
}

Replacement represents a potential source replacement for applying a suggested fix.

type RestoreInput

type RestoreInput struct {
	// Message is the message to be added as review comment to the change when restoring the change.
	Message string `json:"message,omitempty"`
}

RestoreInput contains information for restoring a change.

type ReviewInput

type ReviewInput struct {
	// Inline comments to be added to the revision.
	Comments map[string][]CommentInput `json:"comments,omitempty"`

	// Robot comments to be added to the revision.
	RobotComments map[string][]RobotCommentInput `json:"robot_comments,omitempty"`

	// Message is the message to be added as a review comment.
	Message string `json:"message,omitempty"`

	// Tag represents a tag to apply to review comment messages, votes, and inline comments.
	//
	// Tags may be used by CI or other automated systems to distinguish them from human
	// reviews.
	Tag string `json:"tag,omitempty"`

	// Labels represents the votes that should be added to the revision as a map of label names
	// to voting values.
	Labels map[string]int `json:"labels,omitempty"`

	// Notify is an enum specifying whom to send notifications to.
	//
	// Valid values are NONE, OWNER, OWNER_REVIEWERS, and ALL.
	//
	// Optional. The default is ALL.
	Notify string `json:"notify,omitempty"`

	// OnBehalfOf is an account-id which the review should be posted on behalf of.
	//
	// To use this option the caller must have granted labelAs-NAME permission for all keys
	// of labels.
	//
	// More information on account-id may be found here:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#account-id
	OnBehalfOf string `json:"on_behalf_of,omitempty"`

	// Reviewers is a list of ReviewerInput representing reviewers that should be added to the change. Optional.
	Reviewers []ReviewerInput `json:"reviewers,omitempty"`

	// Ready, if set to true, will move the change from WIP to ready to review if possible.
	//
	// It is an error for both Ready and WorkInProgress to be true.
	Ready bool `json:"ready,omitempty"`

	// WorkInProgress sets the work-in-progress bit for the change.
	//
	// It is an error for both Ready and WorkInProgress to be true.
	WorkInProgress bool `json:"work_in_progress,omitempty"`
}

ReviewInput contains information for adding a review to a revision.

TODO(mknyszek): Add support for drafts, notify, and omit_duplicate_comments.

type ReviewResult

type ReviewResult struct {
	// Labels is a map of labels to values after the review was posted.
	//
	// nil if any reviewer additions were rejected.
	Labels map[string]int `json:"labels,omitempty"`

	// Reviewers is a map of accounts or group identifiers to an AddReviewerResult representing
	// the outcome of adding the reviewer.
	//
	// Absent if no reviewer additions were requested.
	Reviewers map[string]AddReviewerResult `json:"reviewers,omitempty"`

	// Ready marks if the change was moved from WIP to ready for review as a result of this action.
	Ready bool `json:"ready,omitempty"`
}

ReviewResult contains information regarding the updates that were made to a review.

type ReviewerInfo

type ReviewerInfo struct {
	AccountInfo

	// Approvals maps label names to the approval values given by this reviewer.
	Approvals map[string]string `json:"approvals,omitempty"`
}

ReviewerInfo contains information about a reviewer and their votes on a change.

It has the same fields as AccountInfo, except the AccountID is optional if an unregistered reviewer was added.

type ReviewerInput

type ReviewerInput struct {
	// Reviewer is an account-id that should be added as a reviewer, or a group-id for which
	// all members should be added as reviewers. If Reviewer identifies both an account and a
	// group, only the account is added as a reviewer to the change.
	//
	// More information on account-id may be found here:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#account-id
	//
	// More information on group-id may be found here:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#group-id
	Reviewer string `json:"reviewer"`

	// State is the state in which to add the reviewer. Possible reviewer states are REVIEWER
	// and CC. If not given, defaults to REVIEWER.
	State string `json:"state,omitempty"`

	// Confirmed represents whether adding the reviewer is confirmed.
	//
	// The Gerrit server may be configured to require a confirmation when adding a group as
	// a reviewer that has many members.
	Confirmed bool `json:"confirmed"`

	// Notify is an enum specifying whom to send notifications to.
	//
	// Valid values are NONE, OWNER, OWNER_REVIEWERS, and ALL.
	//
	// Optional. The default is ALL.
	Notify string `json:"notify,omitempty"`
}

ReviewerInput contains information for adding a reviewer to a change.

TODO(mknyszek): Add support for notify_details.

type Reviewers

type Reviewers struct {
	CC       []AccountInfo `json:"CC"`
	Reviewer []AccountInfo `json:"REVIEWER"`
	Removed  []AccountInfo `json:"REMOVED"`
}

Reviewers is a map that maps a type of reviewer to its account info.

type RevisionInfo

type RevisionInfo struct {
	// PatchSetNumber is the number associated with the given patch set.
	PatchSetNumber int `json:"_number"`

	// Kind is the kind of revision this is.
	//
	// Allowed values are specified in the RevisionKind type.
	Kind RevisionKind `json:"kind"`

	// Ref is the Git reference for the patchset.
	Ref string `json:"ref"`

	// Uploader represents the account which uploaded this patch set.
	Uploader AccountInfo `json:"uploader"`

	// The description of this patchset, as displayed in the patchset selector menu.
	Description string `json:"description,omitempty"`

	// The commit associated with this revision.
	Commit CommitInfo `json:"commit,omitempty"`

	// A map of modified file paths to FileInfos.
	Files map[string]FileInfo `json:"files,omitempty"`
}

RevisionInfo contains information about a specific patch set.

Corresponds with https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#revision-info. TODO(mknyszek): Support the rest of that structure.

type RevisionKind

type RevisionKind string

RevisionKind represents the "kind" field for a patch set.

type RobotComment

type RobotComment struct {
	Comment

	RobotID    string            `json:"robot_id"`
	RobotRunID string            `json:"robot_run_id"`
	URL        string            `json:"url"`
	Properties map[string]string `json:"properties"`
}

RobotComment represents a robot comment on a Gerrit CL. Information about these fields is in: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#robot-comment-info

RobotComment shares most of the same fields with Comment. Note that robot comments do not have the `unresolved` field so it will always be false.

type RobotCommentInput

type RobotCommentInput struct {
	// The name of the robot that generated this comment.
	// Required
	RobotID string `json:"robot_id"`

	// A unique ID of the run of the robot.
	// Required
	RobotRunID string `json:"robot_run_id"`

	// The file path for which the inline comment should be added.
	Path string `json:"path,omitempty"`

	// The side on which the comment should be added.
	// Allowed values are REVISION and PARENT.
	// If not set, the default is REVISION.
	// Optional
	Side string `json:"side,omitempty"`

	// The number of the line for which the comment should be added.
	// 0 if it is a file comment.
	// If neither line nor range is set, a file comment is added.
	// If range is set, this value is ignored in favor of the end_line of the range.
	// Optional
	Line int `json:"line,omitempty"`

	// The range of the comment as a CommentRange entity.
	// Optional
	Range *CommentRange `json:"range,omitempty"`

	// The URL encoded UUID of the comment to which this comment is a reply.
	// Optional
	InReplyTo string `json:"in_reply_to,omitempty"`

	// The comment message.
	// If not set and an existing draft comment is updated, the existing draft comment is deleted.
	// Optional
	Message string `json:"message,omitempty"`

	// Suggested fixes.
	FixSuggestions []FixSuggestion `json:"fix_suggestions,omitempty"`
}

The RobotCommentInput entity contains information for creating an inline robot comment.

type SubmitInput

type SubmitInput struct {
	// Notify is an enum specifying whom to send notifications to.
	//
	// Valid values are NONE, OWNER, OWNER_REVIEWERS, and ALL.
	//
	// Optional. The default is ALL.
	Notify string `json:"notify,omitempty"`

	// OnBehalfOf is an account-id which the review should be posted on behalf of.
	//
	// To use this option the caller must have granted labelAs-NAME permission for all keys
	// of labels.
	//
	// More information on account-id may be found here:
	// https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#account-id
	OnBehalfOf string `json:"on_behalf_of,omitempty"`
}

SubmitInput contains information for submitting a change.

type SubmittedTogetherInfo

type SubmittedTogetherInfo struct {

	// A list of ChangeInfo entities representing the changes to be submitted together.
	Changes []Change `json:"changes"`

	// The number of changes to be submitted together that the current user cannot see.
	NonVisibleChanges int `json:"non_visible_changes,omitempty"`
}

SubmittedTogetherInfo contains information about a collection of changes that would be submitted together.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp is time.Time for Gerrit JSON interop.

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type VoteInfo

type VoteInfo struct {
	AccountInfo       // Embedded type
	Value       int64 `json:"value"`
}

VoteInfo is AccountInfo plus a value field, used to represent votes on a label.

type WipInput

type WipInput struct {
	// Message is the message to be added as review comment to the change when
	// changing the WIP state.
	Message string `json:"message,omitempty"`
}

WipInput contains information for marking a change as work-in-progress or ready-for-review.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL