gerritchangelists

package
v0.0.0-...-be266f5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package gerritchangelists contains methods for maintaining a cache of whether gerrit changelists were authored by humans or automation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOrUpdate

func CreateOrUpdate(g *GerritChangelist) (*spanner.Mutation, error)

CreateOrUpdate returns a Spanner mutation that inserts the given gerrit changelist record.

func FetchOwnerKinds

func FetchOwnerKinds(ctx context.Context, reqs map[Key]LookupRequest) (map[Key]pb.ChangelistOwnerKind, error)

FetchOwnerKinds retrieves the owner kind of each of the nominated gerrit changelists.

For each changelist for which the owner kind is not cached in Spanner, this method will make an RPC to gerrit.

This method must NOT be called within a Spanner transaction context, as it will create its own transactions to access the changelist cache.

func PopulateOwnerKinds

func PopulateOwnerKinds(ctx context.Context, project string, sources *rdbpb.Sources) (*pb.Sources, error)

PopulateOwnerKinds augments the given sources to include the owner kind of each changelist.

If you have multiple sources objects, prefer to use the batch method PopulateOwnerKindsBatch instead.

For each changelist for which the owner kind is not cached in Spanner, this method will make an RPC to gerrit.

This method must NOT be called within a Spanner transaction context, as it will create its own transactions.

func PopulateOwnerKindsBatch

func PopulateOwnerKindsBatch(ctx context.Context, project string, sourcesByID map[string]*rdbpb.Sources) (map[string]*pb.Sources, error)

PopulateOwnerKindsBatch augments the given sources information to include the owner kind of each changelist.

For each changelist for which the owner kind is not cached in Spanner, this method will make an RPC to gerrit.

This method must NOT be called within a Spanner transaction context, as it will create its own transactions to access the changelist cache.

func Read

func Read(ctx context.Context, keys map[Key]struct{}) (map[Key]*GerritChangelist, error)

Read reads the gerrit changelists with the given keys.

ctx must be a Spanner transaction context.

func SetGerritChangelistsForTesting

func SetGerritChangelistsForTesting(ctx context.Context, gs []*GerritChangelist) error

SetGerritChangelistsForTesting replaces the set of stored gerrit changelists to match the given set. Provided for testing only.

Types

type GerritChangelist

type GerritChangelist struct {
	// Project is the name of the LUCI Project. This is the project
	// for which the cache is being maintained and the project we authenticated
	// as to gerrit.
	Project string
	// Host is the gerrit hostname. E.g. "chromium-review.googlesource.com".
	Host string
	// Change is the gerrit change number.
	Change int64
	// The kind of owner that created the changelist. This could be
	// a human (user) or automation.
	OwnerKind pb.ChangelistOwnerKind
	// The time the record was created in Spanner.
	CreationTime time.Time
}

GerritChangelist is a record used to cache whether a gerrit changelist was authored by a human or by automation.

The cache is per-project to avoid confused deputy problems. Each project will use its own project-scoped service account to access to gerrit to retrieve change owner information and store this data in its own cache.

func ReadAll

func ReadAll(ctx context.Context) ([]*GerritChangelist, error)

ReadAll reads all gerrit changelists. Provided for testing only.

type Key

type Key struct {
	// Project is the name of the LUCI Project.
	Project string
	// Host is the gerrit hostname. E.g. "chromium-review.googlesource.com".
	Host string
	// Change is the gerrit change number.
	Change int64
}

Key represents the key fields of a GerritChangelist record.

type LookupRequest

type LookupRequest struct {
	// Gerrit project in which the changelist is. Optional, but
	// gerrit prefers this be set to speed up lookups.
	GerritProject string
}

LookupRequest represents parameters to a request to lookup up the owner kind of a gerrit changelist.

Jump to

Keyboard shortcuts

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