forge

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 12 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

Index

Constants

View Source
const (
	// CacheTTL is how long cached PR data is considered fresh.
	CacheTTL = 5 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedForge

type CachedForge struct {
	// contains filtered or unexported fields
}

CachedForge wraps a Forge and caches ListPRs results to disk. Stale-while-revalidate: returns stale data immediately and refreshes in the background when the cache is expired.

func NewCachedForge

func NewCachedForge(inner Forge, gitCommonDir string) *CachedForge

NewCachedForge wraps a Forge with file-based PR caching. gitCommonDir should be the output of `git rev-parse --git-common-dir`.

func (*CachedForge) FetchRef

func (c *CachedForge) FetchRef(number int) string

FetchRef returns the git fetch refspec for the given PR number.

func (*CachedForge) GetPR

func (c *CachedForge) GetPR(ctx context.Context, number int) (*PR, error)

GetPR delegates directly to the inner forge (not cached).

func (*CachedForge) ListPRs

func (c *CachedForge) ListPRs(ctx context.Context) ([]PR, error)

ListPRs returns cached PR data if fresh, or stale data while refreshing in the background. On cache miss, fetches synchronously.

func (*CachedForge) ListPRsAsync

func (c *CachedForge) ListPRsAsync(ctx context.Context) <-chan PRResult

ListPRsAsync returns cached data immediately (if available) and always fetches fresh data in the background. The returned channel receives up to two results:

  1. Cached data (FromCache=true) — sent immediately if a cache file exists
  2. Fresh data (FromCache=false) — sent when the API call completes

The channel is closed after all results are sent.

func (*CachedForge) Name

func (c *CachedForge) Name() string

Name returns the name of the underlying forge.

func (*CachedForge) PRURL

func (c *CachedForge) PRURL(number int) string

PRURL returns the URL for the given PR number.

type Forge

type Forge interface {
	// ListPRs returns all open pull requests.
	ListPRs(ctx context.Context) ([]PR, error)

	// GetPR returns a specific PR by number.
	GetPR(ctx context.Context, number int) (*PR, error)

	// PRURL returns the web URL for a given PR number.
	PRURL(number int) string

	// FetchRef returns the git refspec to fetch a PR head.
	// For GitHub: "pull/{n}/head:pr-{n}"
	// For GitLab: "merge-requests/{n}/head:mr-{n}"
	FetchRef(number int) string

	// Name returns the forge name (e.g. "github", "gitlab").
	Name() string
}

Forge abstracts GitHub/GitLab API interactions.

func Detect

func Detect(remoteURL string, opts ...Option) (Forge, error)

Detect identifies the forge type from a git remote URL and returns an appropriate Forge implementation. Returns an error if the forge cannot be determined or authentication fails.

type Option

type Option func(*options)

Option configures Detect behavior.

func WithTokenFunc

func WithTokenFunc(fn TokenFunc) Option

WithTokenFunc overrides the default token retrieval for testing.

type PR

type PR struct {
	Number       int          `json:"number"`
	Title        string       `json:"title"`
	Branch       string       `json:"branch"`
	Author       string       `json:"author"`
	CreatedAt    time.Time    `json:"created_at"`
	ReviewStatus ReviewStatus `json:"review_status"`
	URL          string       `json:"url"`
	IsDraft      bool         `json:"is_draft"`
	State        PRState      `json:"state"`
}

PR represents a pull request or merge request.

type PRResult

type PRResult struct {
	PRs       []PR
	FromCache bool
	Err       error
}

PRResult holds PR data from either cache or a fresh API fetch.

type PRState

type PRState string

PRState represents the open/closed/merged state of a PR.

const (
	PROpen   PRState = "open"
	PRClosed PRState = "closed"
	PRMerged PRState = "merged"
)

PR state values.

type ReviewStatus

type ReviewStatus string

ReviewStatus represents the review state of a PR.

const (
	ReviewNone     ReviewStatus = ""
	ReviewApproved ReviewStatus = "approved"
	ReviewChanges  ReviewStatus = "changes_requested"
	ReviewPending  ReviewStatus = "pending"
)

Review status values for pull requests.

type TokenFunc

type TokenFunc func() (string, error)

TokenFunc retrieves an auth token. Abstracted for testability.

Jump to

Keyboard shortcuts

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