go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/gerrit/client.go (about)

     1  // Copyright 2020 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package gerrit
    16  
    17  import (
    18  	"context"
    19  
    20  	"google.golang.org/grpc"
    21  
    22  	gerritpb "go.chromium.org/luci/common/proto/gerrit"
    23  )
    24  
    25  // Client defines a subset of Gerrit API used by CV.
    26  type Client interface {
    27  	// Lists changes that match a query.
    28  	//
    29  	// Note, although the Gerrit API supports multiple queries, for which
    30  	// it can return multiple lists of changes, this is not a foreseen use-case
    31  	// so this API just includes one query with one returned list of changes.
    32  	//
    33  	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
    34  	ListChanges(ctx context.Context, in *gerritpb.ListChangesRequest, opts ...grpc.CallOption) (*gerritpb.ListChangesResponse, error)
    35  
    36  	// Loads a change by id.
    37  	//
    38  	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-change
    39  	GetChange(ctx context.Context, in *gerritpb.GetChangeRequest, opts ...grpc.CallOption) (*gerritpb.ChangeInfo, error)
    40  
    41  	// Retrieves related changes of a revision.
    42  	//
    43  	// Related changes are changes that either depend on, or are dependencies of
    44  	// the revision.
    45  	//
    46  	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-related-changes
    47  	GetRelatedChanges(ctx context.Context, in *gerritpb.GetRelatedChangesRequest, opts ...grpc.CallOption) (*gerritpb.GetRelatedChangesResponse, error)
    48  
    49  	// Lists the files that were modified, added or deleted in a revision.
    50  	//
    51  	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-files
    52  	ListFiles(ctx context.Context, in *gerritpb.ListFilesRequest, opts ...grpc.CallOption) (*gerritpb.ListFilesResponse, error)
    53  
    54  	// Set various review bits on a change.
    55  	//
    56  	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#set-review
    57  	SetReview(ctx context.Context, in *gerritpb.SetReviewRequest, opts ...grpc.CallOption) (*gerritpb.ReviewResult, error)
    58  
    59  	// Submit a specific revision of a change.
    60  	//
    61  	// https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submit-revision
    62  	SubmitRevision(ctx context.Context, in *gerritpb.SubmitRevisionRequest, opts ...grpc.CallOption) (*gerritpb.SubmitInfo, error)
    63  }
    64  
    65  // Factory creates Client tied to Gerrit host and LUCI project.
    66  //
    67  // Gerrit host and LUCI project determine the authentication being used.
    68  type Factory interface {
    69  	MakeClient(ctx context.Context, gerritHost, luciProject string) (Client, error)
    70  	MakeMirrorIterator(ctx context.Context) *MirrorIterator
    71  }
    72  
    73  // NewFactory returns Factory for use in production.
    74  func NewFactory(ctx context.Context, mirrorHostPrefixes ...string) (Factory, error) {
    75  	f, err := newProd(ctx, mirrorHostPrefixes...)
    76  	if err != nil {
    77  		return nil, err
    78  	}
    79  	return CachingFactory(64, InstrumentedFactory(TimeLimitedFactory(f))), nil
    80  }