keeper

package
v1.16.5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SyncPeriodString compiles into SyncPeriod at load time.
	SyncPeriodString string `json:"sync_period,omitempty"`
	// SyncPeriod specifies how often Keeper will sync jobs with Github. Defaults to 1m.
	SyncPeriod time.Duration `json:"-"`
	// StatusUpdatePeriodString compiles into StatusUpdatePeriod at load time.
	StatusUpdatePeriodString string `json:"status_update_period,omitempty"`
	// StatusUpdatePeriod specifies how often Keeper will update Github status contexts.
	// Defaults to the value of SyncPeriod.
	StatusUpdatePeriod time.Duration `json:"-"`
	// Queries represents a list of GitHub search queries that collectively
	// specify the set of PRs that meet merge requirements.
	Queries Queries `json:"queries,omitempty"`
	// The default merge type for lighthouse to use, and the merge_method list will override this. Defaults to "merge"
	DefaultMergeType PullRequestMergeType `json:"default_merge_method,omitempty"`
	// A key/value pair of an org/repo as the key and merge method to override
	// the default method of merge. Valid options are squash, rebase, and merge.
	MergeType map[string]PullRequestMergeType `json:"merge_method,omitempty"`
	// A key/value pair of an org/repo as the key and Go template to override
	// the default merge commit title and/or message. Template is passed the
	// PullRequest struct (prow/github/types.go#PullRequest)
	MergeTemplate map[string]MergeCommitTemplate `json:"merge_commit_template,omitempty"`
	// URL for keeper status contexts.
	// We can consider allowing this to be set separately for separate repos, or
	// allowing it to be a template.
	TargetURL string `json:"target_url,omitempty"`
	// PRStatusBaseURL is the base URL for the PR status page.
	// This is used to link to a merge requirements overview
	// in the keeper status context.
	PRStatusBaseURL string `json:"pr_status_base_url,omitempty"`
	// BlockerLabel is an optional label that is used to identify merge blocking
	// Github issues.
	// Leave this blank to disable this feature and save 1 API token per sync loop.
	BlockerLabel string `json:"blocker_label,omitempty"`
	// SquashLabel is an optional label that is used to identify PRs that should
	// always be squash merged.
	// Leave this blank to disable this feature.
	SquashLabel string `json:"squash_label,omitempty"`
	// RebaseLabel is an optional label that is used to identify PRs that should
	// always be rebased and merged.
	// Leave this blank to disable this feature.
	RebaseLabel string `json:"rebase_label,omitempty"`
	// MergeLabel is an optional label that is used to identify PRs that should
	// always be merged with all individual commits from the PR.
	// Leave this blank to disable this feature.
	MergeLabel string `json:"merge_label,omitempty"`
	// MaxGoroutines is the maximum number of goroutines spawned inside the
	// controller to handle org/repo:branch pools. Defaults to 20. Needs to be a
	// positive number.
	MaxGoroutines int `json:"max_goroutines,omitempty"`
	// KeeperContextPolicyOptions defines merge options for context. If not set it will infer
	// the required and optional contexts from the prow jobs configured and use the github
	// combined status; otherwise it may apply the branch protection setting or let user
	// define their own options in case branch protection is not used.
	ContextOptions ContextPolicyOptions `json:"context_options,omitempty"`
	// BatchSizeLimitMap is a key/value pair of an org or org/repo as the key and
	// integer batch size limit as the value. The empty string key can be used as
	// a global default.
	// Special values:
	//  0 => unlimited batch size
	// -1 => batch merging disabled :(
	BatchSizeLimitMap map[string]int `json:"batch_size_limit,omitempty"`
}

Config is the config for the keeper pool.

func (*Config) BatchSizeLimit

func (c *Config) BatchSizeLimit(org, repo string) int

BatchSizeLimit return the batch size limit for the given repo

func (*Config) MergeCommitTemplate

func (c *Config) MergeCommitTemplate(org, repo string) MergeCommitTemplate

MergeCommitTemplate returns a struct with Go template string(s) or nil

func (*Config) MergeMethod

func (c *Config) MergeMethod(org, repo string) PullRequestMergeType

MergeMethod returns the merge method to use for a repo. The default of merge is returned when not overridden.

func (*Config) Parse

func (c *Config) Parse() error

Parse initializes and validates the Config

type ContextPolicy

type ContextPolicy struct {
	// whether to consider unknown contexts optional (skip) or required.
	SkipUnknownContexts       *bool    `json:"skip-unknown-contexts,omitempty"`
	RequiredContexts          []string `json:"required-contexts,omitempty"`
	RequiredIfPresentContexts []string `json:"required-if-present-contexts"`
	OptionalContexts          []string `json:"optional-contexts,omitempty"`
	// Infer required and optional jobs from Branch Protection configuration
	FromBranchProtection *bool `json:"from-branch-protection,omitempty"`
}

ContextPolicy configures options about how to handle various contexts.

func (*ContextPolicy) IsOptional

func (cp *ContextPolicy) IsOptional(c string) bool

IsOptional checks whether a context can be ignored. Will return true if - context is registered as optional - required contexts are registered and the context provided is not required Will return false otherwise. Every context is required.

func (ContextPolicy) Merge

func (cp ContextPolicy) Merge(other ContextPolicy) ContextPolicy

Merge merges one ContextPolicy with another one

func (*ContextPolicy) MissingRequiredContexts

func (cp *ContextPolicy) MissingRequiredContexts(contexts []string) []string

MissingRequiredContexts discard the optional contexts and only look of extra required contexts that are not provided.

func (*ContextPolicy) Validate

func (cp *ContextPolicy) Validate() error

Validate returns an error if any contexts are listed more than once in the config.

type ContextPolicyOptions

type ContextPolicyOptions struct {
	ContextPolicy
	// Github Orgs
	Orgs map[string]OrgContextPolicy `json:"orgs,omitempty"`
}

ContextPolicyOptions holds the default policy, and any org overrides.

func (ContextPolicyOptions) Parse

func (options ContextPolicyOptions) Parse(org, repo, branch string) ContextPolicy

Parse returns the context policy for an org/repo/branch

type MergeCommitTemplate

type MergeCommitTemplate struct {
	TitleTemplate string `json:"title,omitempty"`
	BodyTemplate  string `json:"body,omitempty"`

	Title *template.Template `json:"-"`
	Body  *template.Template `json:"-"`
}

MergeCommitTemplate holds templates to use for merge commits.

type OrgContextPolicy

type OrgContextPolicy struct {
	ContextPolicy
	Repos map[string]RepoContextPolicy `json:"repos,omitempty"`
}

OrgContextPolicy overrides the policy for an org, and any repo overrides.

type PullRequestMergeType

type PullRequestMergeType string

PullRequestMergeType inidicates the type of the pull request

const (
	MergeMerge  PullRequestMergeType = "merge"
	MergeRebase PullRequestMergeType = "rebase"
	MergeSquash PullRequestMergeType = "squash"
)

Possible types of merges for the GitHub merge API

func (PullRequestMergeType) IsValid

func (c PullRequestMergeType) IsValid() bool

IsValid checks that the merge type is valid

type Queries

type Queries []Query

Queries is a Query slice.

func (Queries) OrgExceptionsAndRepos

func (tqs Queries) OrgExceptionsAndRepos() (map[string]sets.String, sets.String)

OrgExceptionsAndRepos determines which orgs and repos a set of queries cover. Output is returned as a mapping from 'included org'->'repos excluded in the org' and a set of included repos.

func (Queries) QueryMap

func (tqs Queries) QueryMap() *QueryMap

QueryMap creates a QueryMap from KeeperQueries

type Query

type Query struct {
	Orgs                   []string `json:"orgs,omitempty"`
	Repos                  []string `json:"repos,omitempty"`
	ExcludedRepos          []string `json:"excludedRepos,omitempty"`
	ExcludedBranches       []string `json:"excludedBranches,omitempty"`
	IncludedBranches       []string `json:"includedBranches,omitempty"`
	Labels                 []string `json:"labels,omitempty"`
	MissingLabels          []string `json:"missingLabels,omitempty"`
	Milestone              string   `json:"milestone,omitempty"`
	ReviewApprovedRequired bool     `json:"reviewApprovedRequired,omitempty"`
}

Query is turned into a GitHub search query. See the docs for details: https://help.github.com/articles/searching-issues-and-pull-requests/

func (Query) ForRepo

func (tq Query) ForRepo(org, repo string) bool

ForRepo indicates if the keeper query applies to the specified repo.

func (*Query) Query

func (tq *Query) Query() string

Query returns the corresponding github search string for the keeper query.

func (*Query) Validate

func (tq *Query) Validate() error

Validate returns an error if the query has any errors.

Examples include: * an org name that is empty or includes a / * repos that are not org/repo * a label that is in both the labels and missing_labels section * a branch that is in both included and excluded branch set.

type QueryMap

type QueryMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

QueryMap is a struct mapping from "org/repo" -> KeeperQueries that apply to that org or repo. It is lazily populated, but threadsafe.

func (*QueryMap) ForRepo

func (qm *QueryMap) ForRepo(org, repo string) Queries

ForRepo returns the keeper queries that apply to a repo.

type RepoContextPolicy

type RepoContextPolicy struct {
	ContextPolicy
	Branches map[string]ContextPolicy `json:"branches,omitempty"`
}

RepoContextPolicy overrides the policy for repo, and any branch overrides.

Jump to

Keyboard shortcuts

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