forge

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 4 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 forge defines what badil needs from the forge hosting the service repos: pull request reads, the preview comment and webhook deliveries, through neutral types.

Index

Constants

View Source
const MaxListedFiles = 3000

MaxListedFiles is the most files a forge lists for a pull request: GitHub responses "include a maximum of 3000 files".

Variables

View Source
var (
	// ErrUnverified is a webhook delivery whose signature is missing or bad.
	ErrUnverified = errors.New("forge: webhook signature rejected")
	// ErrForbidden is a webhook delivery from an installation that is not
	// allowed.
	ErrForbidden = errors.New("forge: installation not allowed")
	// ErrNotFound is a pull request, or a comment target, that does not
	// exist.
	ErrNotFound = errors.New("gitops: not found")
	// ErrUnauthorized is a request the forge refused for its credentials.
	ErrUnauthorized = errors.New("gitops: unauthorized")
)

Sentinel errors. Callers test them with errors.Is.

Functions

This section is empty.

Types

type ChangedFile

type ChangedFile struct {
	Filename         string
	PreviousFilename string
}

ChangedFile is a file a pull request changes, its path relative to the repository root. PreviousFilename is its path before a rename, empty otherwise.

type Event

type Event struct {
	// Name is the delivery's event, the event label of the webhook
	// deliveries metric: ping, installation, installation_repositories,
	// pull_request, push or other.
	Name string
	Kind Kind
	// PullRequest is set when Kind is KindPullRequest.
	PullRequest PullRequestEvent
	// Push is set when Kind is KindPush.
	Push PushEvent
}

Event is a webhook delivery.

type Forge

type Forge interface {
	// GetPullRequest reads owner/repo#number. Lookup failures are returned
	// as errors.
	GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)
	// ListChangedFiles lists the files owner/repo#number changes, every page,
	// at most MaxListedFiles. A failure on any page is returned as an error.
	ListChangedFiles(ctx context.Context, owner, repo string, number int) ([]ChangedFile, error)
	// ListOpenPullRequests lists the open pull requests of owner/repo, every
	// page. Their ChangedFiles is 0: the listing does not return it. A
	// failure on any page is returned as an error.
	ListOpenPullRequests(ctx context.Context, owner, repo string) ([]PullRequest, error)
	// UpsertComment posts body as badil's comment on owner/repo#number: the
	// existing one is updated, or a new one is created.
	UpsertComment(ctx context.Context, owner, repo string, number int, body string) error
	// ParseWebhook verifies, parses and checks a webhook delivery. A bad or
	// missing signature returns ErrUnverified and a zero Event. Otherwise the
	// Event has its Name, also with a parse error, or with ErrForbidden for a
	// delivery from an installation that is not allowed.
	ParseWebhook(r *http.Request) (Event, error)
}

Forge reads pull requests, upserts badil's comment on them and parses webhook deliveries.

type Kind

type Kind int

Kind is what a webhook delivery is to badil.

const (
	// KindOther is a delivery badil does not act on.
	KindOther Kind = iota
	// KindPullRequest is a pull request delivery; Event.PullRequest is set.
	KindPullRequest
	// KindPush is a push delivery; Event.Push is set.
	KindPush
)

Kinds of webhook deliveries.

type PullRequest

type PullRequest struct {
	// Open is true when the state is open; a merged PR is closed.
	Open    bool
	HeadRef string
	HeadSHA string
	// Author is the PR author's login.
	Author string
	// URL is the PR's html_url.
	URL string
	// Labels holds the names of the PR's labels.
	Labels []string
	// FullName is the base repository's owner/repo.
	FullName string
	// HeadFullName is the head repository's owner/repo; it differs from
	// FullName on a fork PR.
	HeadFullName string
	// Number is the PR's number in FullName.
	Number int
	// ChangedFiles is the number of files the PR changes (changed_files).
	ChangedFiles int
}

PullRequest is the state of a pull request as read from the forge.

func (PullRequest) Fork

func (p PullRequest) Fork() bool

Fork reports whether p's head repository is not its base repository.

type PullRequestEvent

type PullRequestEvent struct {
	// Owner and Repo name the repository; FullName is owner/repo.
	Owner    string
	Repo     string
	FullName string
	Number   int
	// Action is the webhook action (opened, labeled, ...).
	Action string
	// Label is the added or removed label, on labeled and unlabeled.
	Label string
	// Labels holds the names of the PR's labels.
	Labels  []string
	HeadRef string
	HeadSHA string
	// Author is the PR author's login.
	Author string
}

PullRequestEvent is a pull request delivery's payload.

type PushEvent

type PushEvent struct {
	// FullName is the pushed repository's owner/repo.
	FullName string
	// Ref is the pushed ref, e.g. refs/heads/main.
	Ref string
	// DefaultBranch is the repository's default branch.
	DefaultBranch string
	// After is the SHA the ref points to after the push.
	After string
	// Deleted is true when the push deleted the ref.
	Deleted bool
}

PushEvent is a push delivery's payload.

Directories

Path Synopsis
Package github implements forge.Forge over the GitHub API, authenticated as the GitHub App installation.
Package github implements forge.Forge over the GitHub API, authenticated as the GitHub App installation.

Jump to

Keyboard shortcuts

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