forge

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateOpen   = "open"
	StateClosed = "closed"
	StateMerged = "merged" // PR only
	StateAll    = "all"    // list filter only
)

Issue and PR states.

Variables

View Source
var RemoteFn func() (string, error)

RemoteFn resolves the URL of the "origin" git remote. Defaults to shelling out to git; overridden in tests.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to the given bool value. Useful for constructing options structs with optional fields.

func Detect

func Detect(forgeFlag, repoFlag string) (forge, repo string, err error)

Detect determines the forge host and repository owner/name. If forgeFlag or repoFlag are provided, they override auto-detection.

func Int

func Int(i int) *int

Int returns a pointer to the given int value. Useful for constructing options structs with optional fields.

func ParseRemote

func ParseRemote(remote string) (forge, repo string, err error)

ParseRemote extracts forge host and owner/repo from a git remote URL. Handles HTTPS (https://github.com/owner/repo.git) and SSH (git@github.com:owner/repo.git).

func String

func String(s string) *string

String returns a pointer to the given string value. Useful for constructing options structs with optional fields.

Types

type BaseError

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

BaseError is a reusable implementation of StructuredError. Use NewBaseError to construct one.

func NewBaseError

func NewBaseError(msg, help string) *BaseError

NewBaseError creates a BaseError with a message and optional help hint.

func (*BaseError) Error

func (e *BaseError) Error() string

func (*BaseError) Help

func (e *BaseError) Help() string

func (*BaseError) Message

func (e *BaseError) Message() string

type CheckSummary

type CheckSummary struct {
	Passed int `json:"passed"`
	Total  int `json:"total"`
}

CheckSummary holds aggregate check/CI run status for a PR.

type Forge

type Forge interface {
	Issues() IssueService
	Labels() LabelService
	PRs() PRService
}

Forge is the central facade interface composed of service interfaces. Implementations provide access to a specific forge (GitHub, GitLab, Forgejo).

type Issue

type Issue struct {
	Number    int            `json:"number"`
	Title     string         `json:"title"`
	State     string         `json:"state"` // "open", "closed"
	Body      string         `json:"body"`
	Labels    []Label        `json:"labels"`
	Author    string         `json:"author"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	URL       string         `json:"url"`
	Extras    map[string]any `json:"extras,omitempty"`
}

Issue represents an issue with normalized fields across forges. Fields present in ≥2 forges are normalized; forge-specific fields go in Extras.

type IssueCloseOptions

type IssueCloseOptions struct {
	Number int // issue number
}

IssueCloseOptions holds parameters for closing an issue.

type IssueCreateOptions

type IssueCreateOptions struct {
	Title     *string  `json:"title,omitempty"` // required
	Body      *string  `json:"body,omitempty"`
	Labels    []string `json:"labels,omitempty"`
	Assignees []string `json:"assignees,omitempty"`
}

IssueCreateOptions holds parameters for creating an issue.

type IssueGetOptions

type IssueGetOptions struct {
	Number int // issue number
}

IssueGetOptions holds parameters for fetching a single issue.

type IssueListOptions

type IssueListOptions struct {
	State     string   // "open", "closed", "all"
	Labels    []string // filter by label names
	Sort      string   // "created", "updated", "comments"
	Direction string   // "asc", "desc"
	Limit     int      // max results per page
	Page      int      // page number (1-indexed)
}

IssueListOptions holds parameters for listing issues.

type IssueReopenOptions

type IssueReopenOptions struct {
	Number int // issue number
}

IssueReopenOptions holds parameters for reopening an issue.

type IssueService

type IssueService interface {
	List(ctx context.Context, opts IssueListOptions) ([]Issue, *ListMeta, error)
	Get(ctx context.Context, opts IssueGetOptions) (*Issue, error)
	Create(ctx context.Context, opts IssueCreateOptions) (*Issue, error)
	Update(ctx context.Context, opts IssueUpdateOptions) (*Issue, error)
	Close(ctx context.Context, opts IssueCloseOptions) (*Issue, error)
	Reopen(ctx context.Context, opts IssueReopenOptions) (*Issue, error)
}

IssueService defines operations for issue management.

type IssueUpdateOptions

type IssueUpdateOptions struct {
	Number    int      // issue number
	Title     *string  `json:"title,omitempty"`
	Body      *string  `json:"body,omitempty"`
	State     *string  `json:"state,omitempty"` // "open" or "closed"
	Labels    []string `json:"labels,omitempty"`
	Assignees []string `json:"assignees,omitempty"`
}

IssueUpdateOptions holds parameters for updating an issue.

type Label

type Label struct {
	Name        string         `json:"name"`
	Scope       string         `json:"scope,omitempty"` // empty for unscoped labels
	Color       string         `json:"color"`           // hex color without #
	Description string         `json:"description"`
	Exclusive   bool           `json:"exclusive"` // scoped labels: only one per scope
	Extras      map[string]any `json:"extras,omitempty"`
}

Label represents a label with normalized fields. Scope (e.g., "kind" from GitHub's "kind:bug" or GitLab's "kind::bug") and Exclusive are normalized across GitHub, GitLab, and Forgejo.

type LabelCreateOptions

type LabelCreateOptions struct {
	Scope       *string `json:"scope,omitempty"` // scope prefix (nil for unscoped)
	Name        string  `json:"name"`            // label name (required)
	Color       *string `json:"color,omitempty"` // hex color without #
	Description *string `json:"description,omitempty"`
	Exclusive   *bool   `json:"exclusive,omitempty"` // only one label allowed per scope
}

LabelCreateOptions holds parameters for creating a label.

type LabelDeleteOptions

type LabelDeleteOptions struct {
	Scope string // scope prefix (empty for unscoped)
	Name  string // label name
}

LabelDeleteOptions holds parameters for deleting a label.

type LabelListOptions

type LabelListOptions struct {
	Limit int // max results per page
	Page  int // page number (1-indexed)
}

LabelListOptions holds parameters for listing labels.

type LabelService

type LabelService interface {
	List(ctx context.Context, opts LabelListOptions) ([]Label, error)
	Create(ctx context.Context, opts LabelCreateOptions) (*Label, error)
	Update(ctx context.Context, opts LabelUpdateOptions) (*Label, error)
	Delete(ctx context.Context, opts LabelDeleteOptions) error
}

LabelService defines operations for label management.

type LabelUpdateOptions

type LabelUpdateOptions struct {
	Scope       string  // current scope
	Name        string  // current name
	NewName     *string `json:"new_name,omitempty"`
	NewScope    *string `json:"new_scope,omitempty"`
	Color       *string `json:"color,omitempty"`
	Description *string `json:"description,omitempty"`
	Exclusive   *bool   `json:"exclusive,omitempty"`
}

LabelUpdateOptions holds parameters for updating a label.

type ListMeta

type ListMeta struct {
	Total int `json:"total"` // total number of items matching the query
	Count int `json:"count"` // number of items in this response
}

ListMeta holds aggregate count information for list responses.

type PR

type PR struct {
	Number       int            `json:"number"`
	Title        string         `json:"title"`
	State        string         `json:"state"` // "open", "closed", "merged"
	Body         string         `json:"body"`
	BaseRef      string         `json:"base_ref"`        // target branch
	HeadRef      string         `json:"head_ref"`        // source branch
	Stack        string         `json:"stack,omitempty"` // stack name extracted from title prefix
	DependsOn    []int          `json:"depends_on"`      // PR numbers this depends on
	DependedOnBy []int          `json:"depended_on_by"`  // PR numbers that depend on this
	Reviewers    []ReviewState  `json:"reviewers,omitempty"`
	Checks       *CheckSummary  `json:"checks,omitempty"`
	Author       string         `json:"author"`
	CreatedAt    time.Time      `json:"created_at"`
	UpdatedAt    time.Time      `json:"updated_at"`
	URL          string         `json:"url"`
	Extras       map[string]any `json:"extras,omitempty"`
}

PR represents a pull request / merge request with normalized fields.

type PRCloseOptions

type PRCloseOptions struct {
	Number int // PR number
}

PRCloseOptions holds parameters for closing a pull request.

type PRCreateOptions

type PRCreateOptions struct {
	Title   *string `json:"title,omitempty"` // required
	Body    *string `json:"body,omitempty"`
	HeadRef *string `json:"head,omitempty"`  // source branch (default: current)
	BaseRef *string `json:"base,omitempty"`  // target branch (default: repo default)
	Stack   *string `json:"stack,omitempty"` // stack name; auto-derived from branch if nil
	Draft   *bool   `json:"draft,omitempty"`
}

PRCreateOptions holds parameters for creating a pull request.

type PRGetOptions

type PRGetOptions struct {
	Number int // PR number
}

PRGetOptions holds parameters for fetching a single pull request.

type PRListOptions

type PRListOptions struct {
	State     string // "open", "closed", "merged", "all"
	Sort      string // "created", "updated"
	Direction string // "asc", "desc"
	Limit     int    // max results per page
	Page      int    // page number (1-indexed)
}

PRListOptions holds parameters for listing pull requests.

type PRMergeOptions

type PRMergeOptions struct {
	Number int     // PR number
	Method *string `json:"merge_method,omitempty"` // "merge", "squash", "rebase"
	Title  *string `json:"title,omitempty"`
	Body   *string `json:"body,omitempty"`
}

PRMergeOptions holds parameters for merging a pull request.

type PRService

type PRService interface {
	List(ctx context.Context, opts PRListOptions) ([]PR, *ListMeta, error)
	Get(ctx context.Context, opts PRGetOptions) (*PR, error)
	Create(ctx context.Context, opts PRCreateOptions) (*PR, error)
	Update(ctx context.Context, opts PRUpdateOptions) (*PR, error)
	Merge(ctx context.Context, opts PRMergeOptions) (*PR, error)
	Close(ctx context.Context, opts PRCloseOptions) (*PR, error)
}

PRService defines operations for pull request management.

type PRUpdateOptions

type PRUpdateOptions struct {
	Number int     // PR number
	Title  *string `json:"title,omitempty"`
}

PRUpdateOptions holds parameters for updating a pull request.

type ReviewState

type ReviewState struct {
	Login string `json:"login"`
	State string `json:"state"` // APPROVED, CHANGES_REQUESTED, COMMENTED, PENDING
}

ReviewState represents a single reviewer's review status on a PR.

type StructuredError

type StructuredError interface {
	error
	// Message returns the user-facing error message.
	Message() string
	// Help returns an optional corrective action hint, or "".
	Help() string
}

StructuredError is an error that carries a user-facing message and an optional help hint. All architectural layers — adapters, commands, auth — return errors satisfying this interface so that main.go can format output with a single type-assertion.

Directories

Path Synopsis
Package github implements the forge.Forge interface backed by google/go-github.
Package github implements the forge.Forge interface backed by google/go-github.

Jump to

Keyboard shortcuts

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