Documentation ¶
Overview ¶
Package gerrit contains Gerrit utility functions.
Index ¶
- Constants
- Variables
- func EquivalentPatchsetRange(info *gerritpb.ChangeInfo) (minEquiPatchset, currentPatchset int, err error)
- func Tag(name string, suffix string) string
- func TruncateMessage(msg string) string
- func UnhandledError(ctx context.Context, err error, format string, args ...any) error
- type Client
- type Factory
- type MirrorIterator
- type Whom
- type Whoms
Constants ¶
const MaxMessageLength = 16384
MaxMessageLength is the max message length for Gerrit as of Jun 2020 based on error messages.
const PlaceHolder = "\n...[truncated too long message]"
PlaceHolder is added to the message when the length of the message exceeds `MaxMessageLength` and human message gets truncated.
Variables ¶
var ( Whom_name = map[int32]string{ 0: "NONE", 1: "OWNER", 2: "REVIEWERS", 3: "CQ_VOTERS", 4: "PS_UPLOADER", } Whom_value = map[string]int32{ "NONE": 0, "OWNER": 1, "REVIEWERS": 2, "CQ_VOTERS": 3, "PS_UPLOADER": 4, } )
Enum value maps for Whom.
var ErrGerritDeadlineExceeded = errors.New("Gerrit took too long to respond", transient.Tag)
var ErrOutOfQuota = errors.New("out of Gerrit Quota", transient.Tag)
var ErrStaleData = errors.New("fetched stale Gerrit data", transient.Tag)
var File_go_chromium_org_luci_cv_internal_gerrit_storage_proto protoreflect.FileDescriptor
Functions ¶
func EquivalentPatchsetRange ¶
func EquivalentPatchsetRange(info *gerritpb.ChangeInfo) (minEquiPatchset, currentPatchset int, err error)
EquivalentPatchsetRange computes range of patchsets code-wise equivalent to the current patchset.
Gerrit categorises each new patchset (aka Revision) according to difference from prior one. The rebases are counted as equivalent, even though dependencies may have changed. Thus, only REWORK changes code.
Generally, all patchsets are numbered 1,2,3,...n without gaps. But this function doesn't assume this, thus Gerrit might potentially support wiping out individual patchsets, creating gaps without affecting CV.
func Tag ¶
Tag constructs a CV specific Gerrit Tag for SetReview request.
See: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-input Panics if name is not provided or name contains "~". suffix is optional.
func TruncateMessage ¶
TruncateMessage truncates the message and appends `PlaceHolder` so that the string doesn't exceed `MaxMessageLength`.
If the input message is a valid utf-8 string, the result string will also be a valid utf-8 string
Types ¶
type Client ¶
type Client interface { // Lists changes that match a query. // // Note, although the Gerrit API supports multiple queries, for which // it can return multiple lists of changes, this is not a foreseen use-case // so this API just includes one query with one returned list of changes. // // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes ListChanges(ctx context.Context, in *gerritpb.ListChangesRequest, opts ...grpc.CallOption) (*gerritpb.ListChangesResponse, error) // Loads a change by id. // // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-change GetChange(ctx context.Context, in *gerritpb.GetChangeRequest, opts ...grpc.CallOption) (*gerritpb.ChangeInfo, error) // Retrieves related changes of a revision. // // Related changes are changes that either depend on, or are dependencies of // the revision. // // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-related-changes GetRelatedChanges(ctx context.Context, in *gerritpb.GetRelatedChangesRequest, opts ...grpc.CallOption) (*gerritpb.GetRelatedChangesResponse, error) // Lists the files that were modified, added or deleted in a revision. // // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-files ListFiles(ctx context.Context, in *gerritpb.ListFilesRequest, opts ...grpc.CallOption) (*gerritpb.ListFilesResponse, error) // Set various review bits on a change. // // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#set-review SetReview(ctx context.Context, in *gerritpb.SetReviewRequest, opts ...grpc.CallOption) (*gerritpb.ReviewResult, error) // Submit a specific revision of a change. // // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submit-revision SubmitRevision(ctx context.Context, in *gerritpb.SubmitRevisionRequest, opts ...grpc.CallOption) (*gerritpb.SubmitInfo, error) // Returns the email addresses linked in the given Gerrit account. // // https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#list-account-emails ListAccountEmails(ctx context.Context, req *gerritpb.ListAccountEmailsRequest, opts ...grpc.CallOption) (*gerritpb.ListAccountEmailsResponse, error) }
Client defines a subset of Gerrit API used by CV.
type Factory ¶
type Factory interface { MakeClient(ctx context.Context, gerritHost, luciProject string) (Client, error) MakeMirrorIterator(ctx context.Context) *MirrorIterator }
Factory creates Client tied to Gerrit host and LUCI project.
Gerrit host and LUCI project determine the authentication being used.
func CachingFactory ¶
CachingFactory caches clients produced by another Factory.
func InstrumentedFactory ¶
InstrumentedFactory instruments RPCs.
func NewFactory ¶
NewFactory returns Factory for use in production.
func TimeLimitedFactory ¶
TimeLimitedFactory limits duration per each kind of Gerrit RPC.
type MirrorIterator ¶
type MirrorIterator []string
MirrorIterator starts with the Gerrit host as is and then iterates over mirrors.
Fail-safe: if all mirrors have been used, uses the host as is. However, users should use Empty() to detect this and if necessary should construct a new MirrorIterator.
Not goroutine-safe.
func (*MirrorIterator) Empty ¶
func (it *MirrorIterator) Empty() bool
Empty returns true if MirrorIterator has already iterated over all the mirrors.
func (*MirrorIterator) Next ¶
func (it *MirrorIterator) Next() grpc.CallOption
Next returns a grpc.CallOption.
func (*MirrorIterator) RetryIfStale ¶
func (it *MirrorIterator) RetryIfStale(f func(opt grpc.CallOption) error) error
RetryIfStale retries the given function so long as it returns ErrStaleData and there is not yet tried mirror.
Executes the given function at least once. If there are no mirrors, defaults to virtual gerrit host.
Provides the given function with the grpc.CallOption which should be passed to the respective Client RPC call.
Returns whatever error the given function returned last.
type Whom ¶
type Whom int32
Whom identifies one or a group of Gerrit users involved in the code review workflow.
func (Whom) Descriptor ¶
func (Whom) Descriptor() protoreflect.EnumDescriptor
func (Whom) EnumDescriptor
deprecated
func (Whom) Number ¶
func (x Whom) Number() protoreflect.EnumNumber
func (Whom) Type ¶
func (Whom) Type() protoreflect.EnumType
type Whoms ¶
type Whoms []Whom
Whoms is a collection of `Whom`s.
func (Whoms) Dedupe ¶
func (whoms Whoms) Dedupe()
Dedupe removes duplicates and sorts the whoms in-place.
func (Whoms) ToAccountIDsSorted ¶
func (whoms Whoms) ToAccountIDsSorted(ci *gerritpb.ChangeInfo) []int64
ToAccountIDsSorted translates whom to actual Gerrit account ids in a CL.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package botdata implements parsing and generation logic for BotData.
|
Package botdata implements parsing and generation logic for BotData. |
Package cfgmatcher efficiently matches a CL to 0+ ConfigGroupID for a single LUCI project.
|
Package cfgmatcher efficiently matches a CL to 0+ ConfigGroupID for a single LUCI project. |
Package cqdepend parses CQ-Depend directives in CL description.
|
Package cqdepend parses CQ-Depend directives in CL description. |
Package gerritfake implements fake Gerrit for needs of CV tests.
|
Package gerritfake implements fake Gerrit for needs of CV tests. |
Package gobmap finds relevant LUCI project config given a Gerrit CL.
|
Package gobmap finds relevant LUCI project config given a Gerrit CL. |
gobmaptest
Package gobmaptest eases use of gobmap package in tests.
|
Package gobmaptest eases use of gobmap package in tests. |
Package listener listens to Gerrit events.
|
Package listener listens to Gerrit events. |
Package metadata can extract metadata from Gerrit CLs.
|
Package metadata can extract metadata from Gerrit CLs. |
Package poller polls Gerrit for interesting CV changes.
|
Package poller polls Gerrit for interesting CV changes. |
Package trigger determines if and how Gerrit CL is triggered.
|
Package trigger determines if and how Gerrit CL is triggered. |
Package updater implements changelist.Updater backend for Gerrit.
|
Package updater implements changelist.Updater backend for Gerrit. |