Documentation
¶
Overview ¶
Package policy reads the bot PR sweep policy files and resolves them into the policy one repository is swept under.
Three files take part, applied in this order on top of the company defaults in pr.CompanyDefaults:
bot-prs-sweep/default.yaml company defaults bot-prs-sweep/team-<name>.yaml one team's deviations, owned by the team repositories/team-<name>.yaml one repository's exception, on its entry
Every file lives in giantswarm/github and is read from its default branch at the start of a sweep. A file that does not parse, or that names a key, a bot PR kind, an update type or a value the sweep does not know, is an error. A policy a team cannot read back is worse than no policy, so the sweep stops instead of quietly applying defaults.
Index ¶
- Constants
- func ChannelsFile(team string) string
- func ParseDeclarations(content, owner, path string) (map[string]Declaration, error)
- func ParseLanguages(content, owner, path string) (map[string]string, error)
- func ParseRepositories(content, owner, path string) ([]string, map[string]Exception, error)
- func RepositoriesFile(team string) string
- func TeamFile(team string) string
- type BudgetDocument
- type ChangelogDocument
- type Channel
- type Channels
- type ConcurrencyDocument
- type Declaration
- type Document
- type Exception
- type File
- type GitHubSource
- type Loader
- type RescueDocument
- type Scope
- type Set
- type Source
Constants ¶
const DefaultFile = "bot-prs-sweep/default.yaml"
DefaultFile holds the company defaults; TeamFile is one team's deviations and RepositoriesFile is the team's repository list, which also carries the per-repository exceptions.
const PolicyDir = "bot-prs-sweep"
PolicyDir holds the company defaults and every team's policy file.
const TeamFilePrefix = "bot-prs-sweep/team-"
TeamFilePrefix and teamFileSuffix bracket a team name in the path of its policy file, and are what Teams reads a team name back out of.
Variables ¶
This section is empty.
Functions ¶
func ChannelsFile ¶ added in v0.39.0
ChannelsFile returns the path of a team's channel file.
func ParseDeclarations ¶ added in v0.47.0
func ParseDeclarations(content, owner, path string) (map[string]Declaration, error)
ParseDeclarations returns the lifecycle of every entry of a team's repository list that is in the scope, keyed by owner/name, each with the file that declares it.
func ParseLanguages ¶ added in v0.47.0
ParseLanguages returns the gen.language of every entry of a team's repository list that declares one, keyed by owner/name. It is the one generator key the sweep reads: a rescue needs the toolchain that builds the repository.
func ParseRepositories ¶
ParseRepositories returns the owner/name entries of a team's repository list together with the botPRsSweep exception of every entry that carries one, keyed by the same owner/name. An entry whose lifecycle is archived or deleted is left out. Only the name, the lifecycle and that one key are read; every other key of the file belongs to the generators and changes without notice. The repositories live under the list's own owner.
func RepositoriesFile ¶
RepositoriesFile returns the path of a team's repository list.
Types ¶
type BudgetDocument ¶
type BudgetDocument struct {
PerRescue *float64 `yaml:"perRescue"`
Weekly *float64 `yaml:"weekly"`
}
BudgetDocument is the rescue budget in US dollars. Neither figure is enforced yet; see pr.BudgetEnforced.
type ChangelogDocument ¶ added in v0.32.0
type ChangelogDocument struct {
Enabled *bool `yaml:"enabled"`
Path *string `yaml:"path"`
Heading *string `yaml:"heading"`
Section *string `yaml:"section"`
Template *string `yaml:"template"`
}
ChangelogDocument is the changelog section of a policy file: the entry a team wants on a bot PR when a person asks for one.
type Channel ¶ added in v0.39.0
Channel is one Slack channel of a team: the ID a message is delivered to, so a renamed channel keeps receiving it, and the name that is shown.
type Channels ¶ added in v0.39.0
Channels is a team's channel file. Notices receives the messages that ask for nothing, the sweep's summary among them. Asks receives the messages that wait for the team; the sweep sends none, and the key is known only so a file that names it parses.
func ParseChannels ¶ added in v0.39.0
ParseChannels parses a team's channel file. A key the file does not know, a missing notices channel or a channel without a valid ID and name is an error: a summary is delivered by the ID alone, so an ID the sweep cannot trust must not reach the gateway.
type ConcurrencyDocument ¶
ConcurrencyDocument is the concurrency section of a policy file.
type Declaration ¶ added in v0.47.0
type Declaration struct {
// Lifecycle is the entry's lifecycle as written; empty when the entry
// declares none.
Lifecycle string
// File is the team file the entry is in.
File string
}
Declaration is how a team file declares one repository.
func (Declaration) String ¶ added in v0.47.0
func (d Declaration) String() string
String reads the declaration as the part of a sentence that names it.
type Document ¶
type Document struct {
UpdateTypes map[string][]string `yaml:"updateTypes"`
Rescue *RescueDocument `yaml:"rescue"`
Concurrency *ConcurrencyDocument `yaml:"concurrency"`
Changelog *ChangelogDocument `yaml:"changelog"`
ModelConfig *string `yaml:"modelConfig"`
Summary *bool `yaml:"summary"`
// contains filtered or unexported fields
}
Document is one policy file. Every field is optional and an absent field keeps what the file before it said. UpdateTypes replaces the list of the kinds it names and leaves every other kind alone.
The names a file writes are also held in their resolved form, which ParseDocument fills. Only ParseDocument builds a Document, so a Document that exists has been resolved, and applying one needs no second pass over the names and no error a caller has to discard.
func ParseDocument ¶
ParseDocument reads one policy file. An unknown key, a value of the wrong type and an unknown kind, update type or enumerated value are all errors naming path.
type Exception ¶
type Exception struct {
Enabled *bool `yaml:"enabled"`
UpdateTypes []string `yaml:"updateTypes"`
Rescue *bool `yaml:"rescue"`
}
Exception is one repository's deviation, written under the botPRsSweep key of its entry in repositories/team-<name>.yaml. Three keys are allowed and each one only narrows: switch the sweep off, restrict the update types that merge, switch the rescues off.
type File ¶
File is one policy file and the path it was read from. The path travels with the document so a resolved policy can name the files that made it.
type GitHubSource ¶
GitHubSource reads the files from the default branch of one repository, giantswarm/github in every real run.
func (GitHubSource) Read ¶
Read returns the content of path on the repository's default branch. GitHub answers 404 both for a file that is not there and for a repository the token cannot read, so neither is reported as an error here.
func (GitHubSource) String ¶
func (g GitHubSource) String() string
type Loader ¶
type Loader struct {
Source Source
// Owner is the GitHub organisation the repository lists name their
// entries under. It is a property of what the files say, not of where
// they are read from, so it stays on the loader.
Owner string
}
Loader resolves a sweep's scope and policy from the files of one Source.
func (Loader) Channels ¶ added in v0.39.0
Channels reads and parses the team's channel file. A file that is not there is an error: the caller reads it only for a team whose policy posts a summary, and that summary has nowhere else to go.
func (Loader) QueryScope ¶
QueryScope reads the company defaults alone. The query scope has no team, so no team file and no repository exception apply to it.
func (Loader) TeamScope ¶
TeamScope reads the team's repository list, the company defaults and the team's policy file, and resolves all three. A missing repository list is an error: without it the sweep has no scope. A missing policy file is not: the company defaults then apply on their own, and pr.Policy.Sources names the files that were read.
The repository list is read first. GitHub answers 404 for a repository the token cannot read, so an absent policy file and an unreadable giantswarm/github look the same. Reading the one file that must exist first turns that case into one error that names the access.
type RescueDocument ¶
type RescueDocument struct {
Enabled *bool `yaml:"enabled"`
Timeout *string `yaml:"timeout"`
Weekly *int `yaml:"weekly"`
Budget *BudgetDocument `yaml:"budget"`
Confirm *string `yaml:"confirm"`
// contains filtered or unexported fields
}
RescueDocument is the rescue section of a policy file.
type Scope ¶
type Scope struct {
Repos []string
Policies *Set
// Languages maps owner/name to the language the team file declares for
// the repository, for the entries that declare one. Nil outside the
// team scope.
Languages map[string]string
// Declarations maps owner/name to the team-file entry that puts the
// repository in the scope. Nil outside the team scope.
Declarations map[string]Declaration
}
Scope is what one sweep resolves before it starts: the repositories it covers and the policy they are swept under. Repos is nil outside the team scope, where the PRs come from a GitHub search instead.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is the policy of one sweep: the policy every repository of the scope is swept under, and the repositories whose own exception deviates from it. A Set is read-only once built, so the sweep's goroutines share one.
func NewSet ¶
NewSet resolves the base policy from the files, applies each repository exception on top of it, and returns the result. Exceptions are keyed by "owner/name", matched the way GitHub matches a repository, without case.
func (*Set) Base ¶
Base returns the policy of a repository without an exception. The sweep reads its concurrency and whether it posts a summary from it.
type Source ¶
type Source interface {
fmt.Stringer
Read(ctx context.Context, path string) (content string, found bool, err error)
}
Source holds the policy files. Read returns the content of path, and reports found false for a path the source does not hold, which is not an error: an absent policy file falls back to the company defaults. A Source names where it looked in its String, so an error can say so.
GitHubSource is the only source the sweep ships. Nothing else in the package knows where a file was read from.