buildbucket

package
v0.0.0-...-2dffccf Latest Latest
Warning

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

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

Documentation

Overview

Package buildbucket provides a Buildbucket client with helper methods for interacting with builds.

Index

Constants

View Source
const (
	UserAgentTagKey    = "user_agent"
	CrosfleetUserAgent = "crosfleet"
)

Variables

This section is empty.

Functions

func AddServiceVersion

func AddServiceVersion(props map[string]interface{}) map[string]interface{}

AddServiceVersion marshals the max service version proto to a JSON-encoded string, adds it to the given Buildbucket property map, and returns the property map.

func FindDimValInFinalDims

func FindDimValInFinalDims(dim string, build *buildbucketpb.Build) string

FindDimValInFinalDims finds the given dimension value in the build's requested dimensions.

func FindDimValInRequestedDims

func FindDimValInRequestedDims(dim string, build *buildbucketpb.Build) string

FindDimValInRequestedDims finds the given dimension value in the build's requested dimensions, which are of type []*buildbucketpb.RequestedDimension.

Since the dimensions looped through are not of type []*buildbucketpb.StringPair, some duplicate code is unfortunately required.

func FindTagVal

func FindTagVal(tag string, build *buildbucketpb.Build) string

FindTagVal finds the given tag value in the build's tags.

Types

type BuildsClient

BuildsClient is a subset of buildbucketpb.BuildsClient providing a smaller surface area for unit tests

type Client

type Client interface {
	GetBuildsClient() BuildsClient
	GetBuilderID() *buildbucketpb.BuilderID
	ScheduleBuild(ctx context.Context, props map[string]interface{}, dims map[string]string, tags map[string]string, priority int32) (*buildbucketpb.Build, error)
	WaitForBuildStepStart(ctx context.Context, id int64, stepNames ...string) (*buildbucketpb.Build, error)
	GetAllBuildsWithTags(ctx context.Context, tags map[string]string, searchBuildsRequest *buildbucketpb.SearchBuildsRequest) ([]*buildbucketpb.Build, error)
	GetBuild(ctx context.Context, ID int64, fields ...string) (*buildbucketpb.Build, error)
	GetLatestGreenBuild(ctx context.Context) (*buildbucketpb.Build, error)
	AnyIncompleteBuildsWithTags(ctx context.Context, tags map[string]string) (bool, int64, error)
	GetIncompleteBuildsWithTags(ctx context.Context, tags map[string]string) ([]*buildbucketpb.Build, error)
	CancelBuildsByUser(ctx context.Context, printer common.CLIPrinter, earliestCreateTime *timestamppb.Timestamp, user string, ids []string, reason string) error
	GetAllBuildsByUser(ctx context.Context, user string, searchBuildsRequest *buildbucketpb.SearchBuildsRequest) ([]*buildbucketpb.Build, error)
	BuildURL(ID int64) string
}

Client provides helper methods to interact with Buildbucket builds.

func NewClient

func NewClient(ctx context.Context, builder *buildbucketpb.BuilderID, bbService string, authFlags authcli.Flags) (Client, error)

NewClient returns a new client to interact with Buildbucket builds from the given builder.

func NewClientForTesting

func NewClientForTesting(builder *buildbucketpb.BuilderID) Client

NewClientForTesting returns a new client with only the builderID configured.

type ExpectedGetWithTagsCall

type ExpectedGetWithTagsCall struct {
	Tags     map[string]string
	Response []*buildbucketpb.Build
}

type ExpectedScheduleCall

type ExpectedScheduleCall struct {
	Tags map[string]string
	// Properties may be nested, '.' is used as a delimiter.
	Props    map[string]interface{}
	Response *buildbucketpb.Build
}

type FakeBuildClient

type FakeBuildClient struct {
	ExpectedSchedule []ScheduleParams
}

func (FakeBuildClient) CancelBuild

func (FakeBuildClient) ScheduleBuild

type FakeClient

type FakeClient struct {
	Client FakeBuildClient
	// Test data for ScheduleBuild.
	ExpectedScheduleBuild []*ExpectedScheduleCall
	// Test data for GetIncompleteBuildsWithTags.
	ExpectedGetIncompleteBuildsWithTags []*ExpectedGetWithTagsCall
	ExpectedAnyIncompleteBuildsWithTags []*ExpectedGetWithTagsCall
	// Test data for GetAllBuildsWithTags.
	ExpectedGetAllBuildsWithTags []*ExpectedGetWithTagsCall
}

func (*FakeClient) AnyIncompleteBuildsWithTags

func (c *FakeClient) AnyIncompleteBuildsWithTags(ctx context.Context, tags map[string]string) (bool, int64, error)

func (*FakeClient) BuildURL

func (c *FakeClient) BuildURL(ID int64) string

func (*FakeClient) CancelBuildsByUser

func (c *FakeClient) CancelBuildsByUser(ctx context.Context, printer common.CLIPrinter, earliestCreateTime *timestamppb.Timestamp, user string, ids []string, reason string) error

func (*FakeClient) GetAllBuildsByUser

func (c *FakeClient) GetAllBuildsByUser(ctx context.Context, user string, searchBuildsRequest *buildbucketpb.SearchBuildsRequest) ([]*buildbucketpb.Build, error)

func (*FakeClient) GetAllBuildsWithTags

func (c *FakeClient) GetAllBuildsWithTags(ctx context.Context, tags map[string]string, searchBuildsRequest *buildbucketpb.SearchBuildsRequest) ([]*buildbucketpb.Build, error)

func (*FakeClient) GetBuild

func (c *FakeClient) GetBuild(ctx context.Context, ID int64, fields ...string) (*buildbucketpb.Build, error)

func (*FakeClient) GetBuilderID

func (c *FakeClient) GetBuilderID() *buildbucketpb.BuilderID

func (*FakeClient) GetBuildsClient

func (c *FakeClient) GetBuildsClient() BuildsClient

func (*FakeClient) GetIncompleteBuildsWithTags

func (c *FakeClient) GetIncompleteBuildsWithTags(ctx context.Context, tags map[string]string) ([]*buildbucketpb.Build, error)

func (*FakeClient) GetLatestGreenBuild

func (c *FakeClient) GetLatestGreenBuild(ctx context.Context) (*buildbucketpb.Build, error)

func (*FakeClient) ScheduleBuild

func (c *FakeClient) ScheduleBuild(ctx context.Context, props map[string]interface{}, dims map[string]string, tags map[string]string, priority int32) (*buildbucketpb.Build, error)

func (*FakeClient) WaitForBuildStepStart

func (c *FakeClient) WaitForBuildStepStart(ctx context.Context, id int64, stepNames ...string) (*buildbucketpb.Build, error)

type ScheduleParams

type ScheduleParams struct {
	BuilderName string
	Props       map[string]interface{}
	Tags        map[string]string
}

ScheduleParams encapsulates a subset of ScheduleBuildRequest fields to match against in the fake client.

Jump to

Keyboard shortcuts

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