trust

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 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.

Index

Constants

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")
)

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.

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 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