operations

package
v0.0.0-...-5cb3387 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package operations defines the unified data model and configuration shared by the forge-specific clients and the forge CLI commands.

Index

Constants

View Source
const (
	EnvConfigPath        = "FORGIT_CONFIG"
	EnvGitHubToken       = "FORGIT_GITHUB_TOKEN"
	EnvGitLabToken       = "FORGIT_GITLAB_TOKEN"
	EnvGitLabURL         = "FORGIT_GITLAB_URL"
	EnvForgejoToken      = "FORGIT_FORGEJO_TOKEN"
	EnvForgejoURL        = "FORGIT_FORGEJO_URL"
	EnvSourceHutToken    = "FORGIT_SOURCEHUT_TOKEN"
	EnvSourceHutUsername = "FORGIT_SOURCEHUT_USERNAME"
	EnvBitbucketToken    = "FORGIT_BITBUCKET_TOKEN"
	EnvBitbucketUsername = "FORGIT_BITBUCKET_USERNAME"
)

Variables

View Source
var ErrIssuesUnsupported = errors.New("issue tracking not supported")

ErrIssuesUnsupported is returned by a forge whose issue tracker is not available. Bitbucket retired its issue tracker in 2023 and its issue API endpoints are deprecated, so the Bitbucket client returns this sentinel. Commands surface it as an informational note rather than a failure.

View Source
var ErrNotSupported = errors.New("not supported by this forge")

ErrNotSupported is returned by a forge that does not offer a feature the unified CLI surface supports elsewhere. Commands surface it as a note rather than a failure, keeping the CLI uniform across forges even when a particular forge has no equivalent concept or API.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

func ResolveConfigPath

func ResolveConfigPath(flagValue string) (string, error)

ResolveConfigPath returns the config path from a --config flag, the FORGIT_CONFIG environment variable, or the default location, in that order.

Types

type BitbucketConfig

type BitbucketConfig struct {
	Token    string `toml:"token"`
	Username string `toml:"username"`
}

type Client

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

Client talks to the GitHub Gist API.

func New

func New(token string) *Client

New builds a Gist client from a GitHub token.

func (*Client) Create

func (c *Client) Create(ctx context.Context, in GistInput) (Gist, error)

Create creates a new gist and returns it.

type Config

type Config struct {
	GitHub    GitHubConfig    `toml:"github"`
	GitLab    GitLabConfig    `toml:"gitlab"`
	Forgejo   ForgejoConfig   `toml:"forgejo"`
	SourceHut SourceHutConfig `toml:"sourcehut"`
	Bitbucket BitbucketConfig `toml:"bitbucket"`

	// Instances holds additional instances of any forge type. Each entry must
	// set Type (github, gitlab, forgejo, sourcehut, bitbucket) and Name.
	Instances []Instance `toml:"instance"`
}

Config holds credentials and settings for every supported forge.

func LoadConfig

func LoadConfig(path string) (Config, error)

func (Config) All

func (c Config) All() []Instance

All returns every configured instance: the per-forge sections (named after the forge type) followed by the [[instance]] entries. Sections with no token are skipped; [[instance]] entries without a name fall back to their type and entries without a token are skipped.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether any forge has credentials configured.

func (Config) Validate

func (c Config) Validate() error

Validate checks that every configured instance points at a known driver. Aliases (entries with Driver) are validated against knownDrivers; entries without Driver fall through to the existing per-forge-config path, which already filters out sections with no token via All(). The function is intentionally narrow because the variable-name vocabulary grows with each forge that gets added.

type FetchSpec

type FetchSpec struct {
	// Remote is the local repository remote name to fetch from.
	Remote string
	// Refspecs are the refspecs to fetch. Fetching an empty list falls back to
	// the remote's configured fetch refspec.
	Refspecs []string
	// LocalBranch is the branch name to create for the pull request. Ignored
	// when the caller asks to detach.
	LocalBranch string
	// HeadSHA is the resolved head commit, used to verify the checkout landed on
	// the commit the forge reports.
	HeadSHA string
	// ForkURL is set when the head branch exists only on a fork, so the fetch
	// must target that clone URL instead of the configured remote. When set, the
	// caller registers it as an additional remote before fetching.
	ForkURL string
}

FetchSpec describes how to obtain a remote ref in a local repository. Forge clients return a spec rather than a ready-made ref because forges expose pull request heads differently: GitHub and Forgejo publish a stable refs/pull/N/head namespace, GitLab publishes refs/merge-requests/N/head, and Bitbucket and SourceHut have no pull request ref namespace at all, so their clients resolve the head commit through the API instead.

type ForgejoConfig

type ForgejoConfig struct {
	Token string `toml:"token"`
	URL   string `toml:"url"`
}

type Gist

type Gist struct {
	ID          string              `json:"id"`
	Description string              `json:"description"`
	Public      bool                `json:"public"`
	URL         string              `json:"html_url"`
	Files       map[string]GistFile `json:"files"`
}

Gist is a GitHub Gist.

type GistFile

type GistFile struct {
	Filename string `json:"filename"`
	Content  string `json:"content"`
}

GistFile is a single file within a Gist.

type GistInput

type GistInput struct {
	Description string
	Public      bool
	Files       map[string]string // filename -> content
}

GistInput describes a gist to create.

type GitHubConfig

type GitHubConfig struct {
	Token string `toml:"token"`
}

type GitLabConfig

type GitLabConfig struct {
	Token string `toml:"token"`
	URL   string `toml:"url"`
}

type Instance

type Instance struct {
	Name     string `toml:"name"`
	Type     string `toml:"type"`
	Driver   string `toml:"driver"`
	Token    string `toml:"token"`
	URL      string `toml:"url"`
	Username string `toml:"username"`
}

Instance describes a single forge server/account. It is used for multiple instances of the same forge type (e.g. two self-hosted GitLab servers) and for user-named aliases of a built-in client (e.g. a Gitea server labelled "gitea" but driven by the Forgejo client via Driver).

type Issue

type Issue struct {
	Forge    string // forge type
	Instance string // instance name
	Repo     string // repository (or tracker) name
	Number   int
	Title    string
	State    string
	URL      string
}

Issue is a tracker item hosted on one of the supported forges.

type IssueDetail

type IssueDetail struct {
	Forge    string
	Instance string
	Repo     string
	Number   int
	Title    string
	State    string // open, closed
	URL      string
	Body     string

	Author string
	Labels []string

	Assignees []string

	CreatedAt time.Time
	UpdatedAt time.Time
}

IssueDetail is the full view of a single issue or ticket.

type IssueInput

type IssueInput struct {
	Repo  string
	Title string
	Body  string
	// Labels are label names to apply, when the forge supports labels.
	Labels []string
}

IssueInput describes an issue to create.

type MergeOptions

type MergeOptions struct {
	// MergeMethod is one of merge, squash or rebase. Forges that do not offer
	// a choice ignore it.
	MergeMethod string
	// DeleteBranch asks the forge to delete the head branch after merging.
	DeleteBranch bool
	// Title and OptionalMessage override the generated merge commit message.
	Title           string
	OptionalMessage string
}

MergeOptions controls how a pull request is merged.

type PR

type PR struct {
	Forge    string // forge type
	Instance string // instance name
	Repo     string // repository (or mailing list) name
	Number   int
	Title    string
	State    string
	URL      string
}

PR is a pull request, merge request or patchset on one of the forges.

type PRDetail

type PRDetail struct {
	Forge    string
	Instance string
	Repo     string
	Number   int
	Title    string
	State    string // open, closed, merged
	URL      string
	Body     string

	Draft  bool
	Merged bool

	Author string
	Labels []string

	HeadBranch string
	HeadSHA    string
	HeadOwner  string // owner of the head repository, for cross-fork PRs
	// HeadRepoName is the head repository's slug without its namespace. It is
	// used to build a fork clone URL on forges that have no pull request ref
	// namespace, where the head branch must be fetched from the fork.
	HeadRepoName string
	BaseBranch   string

	CreatedAt time.Time
	UpdatedAt time.Time
}

PRDetail is the full view of a single pull request, merge request or patchset. It extends the listing-level PR with the fields needed to act on it: the head commit for checking out, the draft state, and the base branch for merging.

type PRInput

type PRInput struct {
	Repo  string
	Title string
	Body  string
	Base  string // base branch; defaults to the repository's default branch
	Head  string // head branch; defaults to the current branch
	Draft bool
}

PRInput describes a pull request to create.

type Project

type Project struct {
	Forge    string // forge type
	Instance string // instance name
	FullName string // name or owner/name
	URL      string
	Private  bool
}

Project is a project or board on one of the forges.

type Repo

type Repo struct {
	Forge    string // forge type: github, gitlab, forgejo, sourcehut, bitbucket
	Instance string // instance name (e.g. "gitlab-main"); forge type when unnamed
	FullName string // owner/name
	URL      string // web URL
	Private  bool
}

Repo is a git repository hosted on one of the supported forges.

type RepoInput

type RepoInput struct {
	Name        string // required
	Owner       string // optional; defaults to the authenticated user
	Description string
	Private     bool
}

RepoInput describes a repository to create.

type Run

type Run struct {
	Forge    string // forge type
	Instance string // instance name
	Repo     string // repository name
	ID       int64
	Name     string
	Status   string
	Branch   string
	URL      string
}

Run is a CI run, pipeline or build job on one of the forges.

type SourceHutConfig

type SourceHutConfig struct {
	Token    string `toml:"token"`
	Username string `toml:"username"`
}

type Workflow

type Workflow struct {
	Forge    string // forge type
	Instance string // instance name
	Repo     string // repository name
	ID       int64
	Name     string
	State    string // e.g. active, disabled
	URL      string
}

Workflow is a CI workflow definition (GitHub Actions workflow) on a repo.

Directories

Path Synopsis
Package forgejo provides access to Forgejo via the forgejo-sdk.
Package forgejo provides access to Forgejo via the forgejo-sdk.
Package github provides access to GitHub via the go-github SDK.
Package github provides access to GitHub via the go-github SDK.
Package gitlab provides access to GitLab via the official client-go SDK.
Package gitlab provides access to GitLab via the official client-go SDK.
Package hut provides access to SourceHut (git.sr.ht, todo.sr.ht and lists.sr.ht) via their GraphQL APIs.
Package hut provides access to SourceHut (git.sr.ht, todo.sr.ht and lists.sr.ht) via their GraphQL APIs.

Jump to

Keyboard shortcuts

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