Documentation
¶
Overview ¶
Package trust decides whether a pull request or issue comes from someone trusted with the repository. Launches on untrusted items start in plan mode, because their content (code, descriptions, comments) was written by someone outside the project.
An item falls in one of three classes:
- member: its author is the repository's owner, a member of its org, or a collaborator, and a pull request's branch is in the repository itself;
- bot: GitHub reports its author as a bot (a GitHub App), the bot is on the user's trusted list, and a pull request's branch is in the repository itself;
- outside: everyone and everything else, including bots not on the list, unknown associations, and every pull request from a fork.
A bot is matched by both its type and its login, so a person whose login resembles a bot's never borrows its trust.
The package also keeps the user's auto-merge bots (MergeBots, off and empty until the user fills them in): bots, such as an org's own GitHub App, that approve a pull request and merge it once its checks pass. Listing one trusts nothing: a pull request's card only says that a listed bot's latest review approved it, the bot matched by its type and its login as a trusted bot is.
Index ¶
Constants ¶
const ( PrefMergeBotsOn = "trust.mergeBotsOn" PrefMergeBots = "trust.mergeBots" )
PrefMergeBotsOn is whether a pull request's card says when one of the user's auto-merge bots approved it, as prefval writes a switch: off until the user turns it on. PrefMergeBots lists those bots, as a JSON array of logins: none until the user adds one, and no build ships a name. The settings package writes both.
const ( AssociationOwner = "OWNER" AssociationMember = "MEMBER" AssociationCollaborator = "COLLABORATOR" )
Author associations GitHub reports for an item's author. Only the first three are trusted.
const PrefBots = "trust.bots"
PrefBots is the preference that lists the trusted bots, as a JSON array of logins. The settings package writes it.
const TypeBot = "Bot"
TypeBot is the GraphQL type GitHub reports for a bot or GitHub App author.
Variables ¶
var ( // ErrInvalidBot is returned for a bot login that GitHub could not have issued. ErrInvalidBot = errors.New("not a bot login") // ErrTooManyBots is returned for a trusted list over 100 bots. ErrTooManyBots = errors.New("too many trusted bots") )
var ErrTooManyMergeBots = errors.New("too many auto-merge bots")
ErrTooManyMergeBots is returned for an auto-merge list over 100 bots.
Functions ¶
func DecodeBots ¶
DecodeBots reads PrefBots: the defaults while the preference is unset (stored false) or unreadable, else the stored list, which may be empty.
func DefaultBots ¶
func DefaultBots() []string
DefaultBots returns the bots trusted until the user changes the list: GitHub's Dependabot and Actions, and Renovate.
func EncodeBots ¶
EncodeBots writes a trusted list for PrefBots, a nil list as an empty one.
func NormalizeBots ¶
NormalizeBots cleans a trusted list as the user entered it: each login is trimmed and lowercased, an "app/" prefix or "[bot]" suffix is dropped, empty entries and duplicates are removed, and the list is sorted. A login GitHub could not have issued is an ErrInvalidBot.
func NormalizeMergeBots ¶
NormalizeMergeBots cleans an auto-merge list as the user entered it, as NormalizeBots cleans a trusted list: each login trimmed and lowercased, an "app/" prefix or "[bot]" suffix dropped, empty entries and duplicates removed, and the list sorted. A login GitHub could not have issued is an ErrInvalidBot, and a list over 100 bots an ErrTooManyMergeBots.
Types ¶
type Author ¶
type Author struct {
// Login is the author's login. GitHub reports a bot by its app's slug, such as
// "dependabot", without the "[bot]" suffix its REST login carries.
Login string
// Type is the author's GraphQL type: User, Bot, or another actor type; "" before a
// refresh has read it.
Type string
// Association is the author's relationship to the repository.
Association string
}
Author is who opened an item.
type Class ¶ added in v0.2.0
type Class string
Class is how far an item's author is trusted.
const ( // ClassMember is an item from the repository's owner, an org member, or a collaborator. ClassMember Class = "member" // ClassBot is an item from a trusted bot. ClassBot Class = "bot" // ClassOutside is an item from an outside contributor, an untrusted bot, or a fork. ClassOutside Class = "outside" )
Trust classes.
type MergeBots ¶
type MergeBots struct {
// On is whether a card says that a listed bot approved its pull request.
On bool
// Bots are the listed logins, normalized and sorted (NormalizeMergeBots); never nil.
Bots []string
}
MergeBots are the user's auto-merge bots: the bots (GitHub Apps) that approve a pull request and merge it once its checks pass, such as "acme-org-automerge", and whether a card says so.
func DecodeMergeBots ¶
DecodeMergeBots reads the auto-merge bots from the stored prefs: off when PrefMergeBotsOn is unset or unreadable, and none when PrefMergeBots is.
func (MergeBots) Match ¶
Match returns the first listed bot, in the list's order, among approving, the bots whose latest review approves a pull request (by login, as GitHub gives an app's slug), matched ignoring case and any "[bot]" suffix. It returns "" while the setting is off, and when no listed bot approved.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy decides items' trust with a list of trusted bots.
func NewPolicy ¶
NewPolicy returns a Policy that trusts the given bots. Logins are matched ignoring case and any "[bot]" suffix.