trust

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (
	AssociationOwner        = "OWNER"
	AssociationMember       = "MEMBER"
	AssociationCollaborator = "COLLABORATOR"
)

Author associations GitHub reports for an item's author. Only the first three are trusted.

View Source
const PrefBots = "trust.bots"

PrefBots is the preference that lists the trusted bots, as a JSON array of logins. The settings package writes it.

View Source
const TypeBot = "Bot"

TypeBot is the GraphQL type GitHub reports for a bot or GitHub App author.

Variables

View Source
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")
)
View Source
var ErrTooManyMergeBots = errors.New("too many auto-merge bots")

ErrTooManyMergeBots is returned for an auto-merge list over 100 bots.

Functions

func DecodeBots

func DecodeBots(raw string, stored bool) []string

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

func EncodeBots(bots []string) string

EncodeBots writes a trusted list for PrefBots, a nil list as an empty one.

func NormalizeBots

func NormalizeBots(logins []string) ([]string, error)

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

func NormalizeMergeBots(logins []string) ([]string, error)

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.

func (Author) IsBot

func (a Author) IsBot() bool

IsBot reports whether GitHub reports the author as a bot.

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

func DecodeMergeBots(stored map[string]string) MergeBots

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

func (m MergeBots) Match(approving []string) string

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

func NewPolicy(bots []string) Policy

NewPolicy returns a Policy that trusts the given bots. Logins are matched ignoring case and any "[bot]" suffix.

func (Policy) Classify

func (p Policy) Classify(a Author, isPR, crossRepo bool) Class

Classify returns an item's trust class: ClassMember, ClassBot, or ClassOutside. A pull request from a fork (crossRepo) is always outside.

func (Policy) Trusted

func (p Policy) Trusted(a Author, isPR, crossRepo bool) bool

Trusted reports whether an item's class is trusted: anything but ClassOutside.

Jump to

Keyboard shortcuts

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