gerrit

package
v0.0.0-...-9994f1b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 34 Imported by: 0

Documentation

Overview

Package gerrit contains functions for interacting with gerrit/gitiles.

Package gerrit contains functions for interacting with gerrit/gitiles.

Package gerrit contains functions for interacting with gerrit/gitiles.

Package gerrit contains functions for interacting with gerrit/gitiles.

Package gerrit contains functions for interacting with gerrit/gitiles.

Copyright 2021 The Chromium Authors Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadFileRequestEq

func DownloadFileRequestEq(req *gitilespb.DownloadFileRequest) gomock.Matcher

func ListFilesRequestEq

func ListFilesRequestEq(req *gitilespb.ListFilesRequest) gomock.Matcher

func RefsRequestEq

func RefsRequestEq(req *gitilespb.RefsRequest) gomock.Matcher

Types

type APIClient

type APIClient interface {
	Projects() ([]string, error)
	DownloadFileFromGitiles(project, branch, path string) (string, error)
	DownloadFileFromGitilesToPath(project, branch, path, saveToPath string) error
}

type Change

type Change struct {
	// This does not include all fields
	Project        string `json:"project"`
	ChangeNumber   int    `json:"_change_number"`
	RevisionNumber int    `json:"_revision_number"`
}

type ChangeRev

type ChangeRev struct {
	ChangeRevKey
	Project string
	// Ref that this change targets, e.g.: "refs/heads/main"
	Branch string
	// The Git reference for the patch set, e.g. "refs/changes/23/123/5"
	Ref           string
	Files         []string
	ChangeCreated *timestamppb.Timestamp
}

ChangeRev contains data about a Gerrit change,revision pair.

func GetChangeRev

func GetChangeRev(ctx context.Context, authedClient *http.Client, changeNum int64, revision int32, host string, retryOpts shared.Options) (*ChangeRev, error)

GetChangeRev gets details from Gerrit about a change,revision pair.

type ChangeRevData

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

ChangeRevData encapsulates a bunch of Gerrit change revisions.

func GetChangeRevData

func GetChangeRevData(ctx context.Context, authedClient *http.Client, changeIds []ChangeRevKey) (*ChangeRevData, error)

GetChangeRevData fetches the Gerrit changes for the provided ChangeIdKeys, and bundles the result into a ChangeRevData.

func GetChangeRevsForTest

func GetChangeRevsForTest(cr []*ChangeRev) *ChangeRevData

GetChangeRevsForTest is intended for testing only, and it allows creation of a ChangeRevData through the supplied ChangeRevs.

func (ChangeRevData) GetChangeRev

func (crv ChangeRevData) GetChangeRev(host string, changeNum int64, revision int32) (*ChangeRev, error)

GetChangeRev extracts a single Gerrit change revision from the ChangeRevData.

type ChangeRevKey

type ChangeRevKey struct {
	Host      string
	ChangeNum int64
	Revision  int32
}

ChangeRevKey is the necessary set of data for looking up a single Gerrit revision.

func ParseCLURL

func ParseCLURL(rawurl string) (*ChangeRevKey, error)

ParseCLURL parses a url for a CL into a ChangeRevKey.

The url must be of the form: "https://<host>-review.googlesource.com/c/<project>/+/<change number>/<patchset>".

func (ChangeRevKey) String

func (cik ChangeRevKey) String() string

type Client

type Client interface {
	FetchFilesFromGitiles(ctx context.Context, host, project, ref string, paths []string, timeoutOpts shared.Options) (*map[string]string, error)
	DownloadFileFromGitiles(ctx context.Context, host, project, ref, path string, timeoutOpts shared.Options) (string, error)
	DownloadFileFromGitilesToPath(ctx context.Context, host, project, ref, path, saveToPath string, timeoutOpts shared.Options) error
	Branches(ctx context.Context, host, project string) (map[string]string, error)
	Projects(ctx context.Context, host string) ([]string, error)
	ListFiles(ctx context.Context, host, project, ref, path string) ([]string, error)
	GetFileLog(ctx context.Context, host, project, ref, filepath string) ([]Commit, error)
	QueryChanges(ctx context.Context, host string, query gerrit.ChangeQueryParams) ([]*gerrit.Change, error)
	GetRelatedChanges(ctx context.Context, host string, changeNumber int) ([]Change, error)
	SetReview(ctx context.Context, host, changeID string, review *gerrit.ReviewInput) (*gerrit.ReviewResult, error)
	SubmitChange(ctx context.Context, host, changeID string) error
}

type Commit

type Commit struct {
	Commit    string   `json:"commit"`
	Tree      string   `json:"tree"`
	Parents   []string `json:"parents"`
	Author    User     `json:"author"`
	Committer User     `json:"committer"`
	Message   string   `json:"message"`
}

type DownloadFileRequestMatcher

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

Native gomock.Eq does not work on protos.

func (DownloadFileRequestMatcher) Matches

func (m DownloadFileRequestMatcher) Matches(x interface{}) bool

func (DownloadFileRequestMatcher) String

type ExpectedFetch

type ExpectedFetch struct {
	Host    string
	Project string
	Ref     string
}

type ExpectedPathParams

type ExpectedPathParams struct {
	Host    string
	Project string
	Ref     string
	Path    string
}

type FakeAPIClient

type FakeAPIClient struct {
	T *testing.T
	// ExpectedDownloads is indexed by project, then branch, then file.
	ExpectedDownloads map[string]map[string]map[string]string
	ExpectedProjects  []string
}

func (*FakeAPIClient) DownloadFileFromGitiles

func (g *FakeAPIClient) DownloadFileFromGitiles(project, branch, path string) (string, error)

DownloadFileFromGitiles downloads a file from Gitiles.

func (*FakeAPIClient) DownloadFileFromGitilesToPath

func (g *FakeAPIClient) DownloadFileFromGitilesToPath(project, branch, path, saveToPath string) error

DownloadFileFromGitilesToPath downloads a file from Gitiles to a specified path.

func (*FakeAPIClient) Projects

func (c *FakeAPIClient) Projects() ([]string, error)

Projects returns a list of projects.

type ListFilesRequestMatcher

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

func (ListFilesRequestMatcher) Matches

func (m ListFilesRequestMatcher) Matches(x interface{}) bool

func (ListFilesRequestMatcher) String

func (m ListFilesRequestMatcher) String() string

type MockClient

type MockClient struct {
	T               *testing.T
	ExpectedFetches map[ExpectedFetch]map[string]string
	// If the string pointer is nil, will raise a "file does not exist" err.
	ExpectedDownloads map[ExpectedPathParams]*string
	// Indexed by host and then by project.
	ExpectedBranches map[string]map[string]map[string]string
	ExpectedProjects map[string][]string
	ExpectedLists    map[ExpectedPathParams][]string
	ExpectedFileLogs map[ExpectedPathParams][]Commit
	// Maps query string to query results.
	// If an entry is set for "*", that result will be returned for all queries.
	ExpectedQuery map[string][]*gerrit.Change
	// Indexed by change ID.
	ExpectedReview map[string]*gerrit.ReviewInput
	// Indexed by change ID.
	ExpectedSubmit map[string]bool
	// Maps host and changeNumber to list of changes
	ExpectedRelatedChanges map[string]map[int][]Change
}

func (*MockClient) Branches

func (c *MockClient) Branches(ctx context.Context, host, project string) (map[string]string, error)

Branches returns a map of branches (to revisions) for a given repo.

func (*MockClient) DownloadFileFromGitiles

func (c *MockClient) DownloadFileFromGitiles(ctx context.Context, host, project, ref, path string, timeoutOpts shared.Options) (string, error)

DownloadFileFromGitiles downloads a file from Gitiles.

func (*MockClient) DownloadFileFromGitilesToPath

func (c *MockClient) DownloadFileFromGitilesToPath(ctx context.Context, host, project, ref, path, saveToPath string, timeoutOpts shared.Options) error

DownloadFileFromGitilesToPath downloads a file from Gitiles to a specified path.

func (*MockClient) FetchFilesFromGitiles

func (c *MockClient) FetchFilesFromGitiles(ctx context.Context, host, project, ref string, paths []string, timeoutOpts shared.Options) (*map[string]string, error)

FetchFilesFromGitiles fetches file contents from gitiles.

func (*MockClient) GetFileLog

func (c *MockClient) GetFileLog(ctx context.Context, host, project, ref, filepath string) ([]Commit, error)

GetFileLog returns a list of commits that touch the specified file.

func (*MockClient) GetRelatedChanges

func (c *MockClient) GetRelatedChanges(ctx context.Context, host string, changeNumber int) ([]Change, error)

GetRelatedChanges queries a gerrit host for changes related to the supplied change number

func (*MockClient) ListFiles

func (c *MockClient) ListFiles(ctx context.Context, host, project, ref, path string) ([]string, error)

ListFiles returns a list of files/directories for a given host/project/ref/path.

func (*MockClient) Projects

func (c *MockClient) Projects(ctx context.Context, host string) ([]string, error)

Projects returns a list of projects for a given host.

func (*MockClient) QueryChanges

func (c *MockClient) QueryChanges(ctx context.Context, host string, query gerrit.ChangeQueryParams) ([]*gerrit.Change, error)

QueryChanges queries a gerrit host for changes matching the supplied query.

func (*MockClient) SetReview

func (c *MockClient) SetReview(ctx context.Context, host, changeID string, review *gerrit.ReviewInput) (*gerrit.ReviewResult, error)

SetReview applies labels/performs other review operations on the specified CL.

func (*MockClient) SubmitChange

func (c *MockClient) SubmitChange(ctx context.Context, host, changeID string) error

SubmitChange submits the specified CL.

type ProdAPIClient

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

func NewProdAPIClient

func NewProdAPIClient(ctx context.Context, host, gitcookiesPath string) (*ProdAPIClient, error)

func (*ProdAPIClient) DownloadFileFromGitiles

func (g *ProdAPIClient) DownloadFileFromGitiles(project, branch, path string) (string, error)

DownloadFileFromGitiles downloads a file from Gitiles.

func (*ProdAPIClient) DownloadFileFromGitilesToPath

func (g *ProdAPIClient) DownloadFileFromGitilesToPath(project, branch, path, saveToPath string) error

DownloadFileFromGitilesToPath downloads a file from Gitiles to a specified path.

func (*ProdAPIClient) Projects

func (c *ProdAPIClient) Projects() ([]string, error)

Projects returns a list of projects.

type ProdClient

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

Client is a client for interacting with gerrit.

func NewClient

func NewClient(authedClient *http.Client) (*ProdClient, error)

NewClient returns a new Client object.

func NewTestClient

func NewTestClient(gitilesClients map[string]gitilespb.GitilesClient) *ProdClient

NewTestClient returns a new Client that uses the provided client objects.

func (*ProdClient) Branches

func (c *ProdClient) Branches(ctx context.Context, host, project string) (map[string]string, error)

Branches returns a map of branches (to revisions) for a given repo.

func (*ProdClient) DownloadFileFromGitiles

func (c *ProdClient) DownloadFileFromGitiles(ctx context.Context, host, project, ref, path string, timeoutOpts shared.Options) (string, error)

DownloadFileFromGitiles downloads a file from Gitiles.

func (*ProdClient) DownloadFileFromGitilesToPath

func (c *ProdClient) DownloadFileFromGitilesToPath(ctx context.Context, host, project, ref, path, saveToPath string, timeoutOpts shared.Options) error

DownloadFileFromGitilesToPath downloads a file from Gitiles to a specified path.

func (*ProdClient) FetchFilesFromGitiles

func (c *ProdClient) FetchFilesFromGitiles(ctx context.Context, host, project, ref string, paths []string, timeoutOpts shared.Options) (*map[string]string, error)

FetchFilesFromGitiles fetches file contents from gitiles.

project is the git project to fetch from. ref is the git-ref to fetch from. paths lists the paths inside the git project to fetch contents for.

fetchFilesFromGitiles returns a map from path in the git project to the contents of the file at that path for each requested path.

If one of paths is not found, an error is returned.

func (*ProdClient) GetFileLog

func (c *ProdClient) GetFileLog(ctx context.Context, host, project, ref, filepath string) ([]Commit, error)

GetFileLog returns a list of commits that touch the specified file. Times are in UTC.

func (*ProdClient) GetRelatedChanges

func (c *ProdClient) GetRelatedChanges(ctx context.Context, host string, changeNumber int) ([]Change, error)

GetRelatedChanges queries a gerrit host for related changes. It returns a list of Changes describing the related changes. Sorted by git commit order, newest to oldest. Empty if there are no related changes. Requires OAuthScope. See https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-related-changes.

func (*ProdClient) ListFiles

func (c *ProdClient) ListFiles(ctx context.Context, host, project, ref, path string) ([]string, error)

ListFiles returns a list of files/directories for a given host/project/ref/path.

func (*ProdClient) Projects

func (c *ProdClient) Projects(ctx context.Context, host string) ([]string, error)

Projects returns a list of projects for a given host.

func (*ProdClient) QueryChanges

func (c *ProdClient) QueryChanges(ctx context.Context, host string, query gerrit.ChangeQueryParams) ([]*gerrit.Change, error)

QueryChanges queries a gerrit host for changes matching the supplied query.

func (*ProdClient) SetReview

func (c *ProdClient) SetReview(ctx context.Context, host, changeID string, review *gerrit.ReviewInput) (*gerrit.ReviewResult, error)

SetReview applies labels/performs other review operations on the specified CL.

func (*ProdClient) SubmitChange

func (c *ProdClient) SubmitChange(ctx context.Context, host, changeID string) error

SubmitChange submits the specified CL.

type RefsRequestMatcher

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

func (RefsRequestMatcher) Matches

func (m RefsRequestMatcher) Matches(x interface{}) bool

func (RefsRequestMatcher) String

func (m RefsRequestMatcher) String() string

type User

type User struct {
	Name  string `json:"name"`
	Email string `json:"email"`
	Time  string `json:"time"`
}

Jump to

Keyboard shortcuts

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