forge

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package forge provides an abstraction over git hosting services (GitHub, GitLab).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreatePRParams added in v0.3.0

type CreatePRParams struct {
	Title string
	Body  string
	Base  string // base branch (empty = repo default)
	Head  string // head/source branch
	Draft bool
}

CreatePRParams contains parameters for creating a PR/MR

type CreatePRResult added in v0.3.0

type CreatePRResult struct {
	Number int
	URL    string
}

CreatePRResult contains the result of creating a PR/MR

type Forge

type Forge interface {
	// Name returns the forge name ("github" or "gitlab")
	Name() string

	// Check verifies the CLI is installed and authenticated
	Check() error

	// GetPRForBranch fetches PR info for a branch
	GetPRForBranch(repoURL, branch string) (*PRInfo, error)

	// GetPRBranch gets the source branch name for a PR number
	GetPRBranch(repoURL string, number int) (string, error)

	// CloneRepo clones a repository to destPath, returns the full clone path
	CloneRepo(repoSpec, destPath string) (string, error)

	// CreatePR creates a new PR/MR
	CreatePR(repoURL string, params CreatePRParams) (*CreatePRResult, error)

	// MergePR merges a PR by number with the given strategy
	// strategy: "squash", "rebase", or "merge"
	// Returns error if repo doesn't allow the requested merge strategy
	MergePR(repoURL string, number int, strategy string) error

	// ViewPR shows PR details or opens in browser
	// If web is true, opens in browser; otherwise shows details in terminal
	ViewPR(repoURL string, number int, web bool) error

	// FormatState returns a human-readable PR state
	FormatState(state string) string
}

Forge represents a git hosting service (GitHub, GitLab, etc.)

func ByName

func ByName(name string) Forge

ByName returns a Forge implementation by name. Supported names: "github", "gitlab" Returns GitHub as default for unknown names.

func Detect

func Detect(remoteURL string, hostMap map[string]string) Forge

Detect returns the appropriate Forge implementation based on the remote URL. If hostMap is provided, checks for exact domain matches first. Falls back to pattern matching, then defaults to GitHub.

func DetectFromRepo

func DetectFromRepo(repoPath string, hostMap map[string]string) Forge

DetectFromRepo detects the forge for a repository by reading its origin URL. Returns GitHub as default if detection fails.

type GitHub

type GitHub struct{}

GitHub implements Forge for GitHub repositories using the gh CLI.

func (*GitHub) Check

func (g *GitHub) Check() error

Check verifies that gh CLI is available and authenticated

func (*GitHub) CloneRepo

func (g *GitHub) CloneRepo(repoSpec, destPath string) (string, error)

CloneRepo clones a GitHub repo using gh CLI

func (*GitHub) CreatePR added in v0.3.0

func (g *GitHub) CreatePR(repoURL string, params CreatePRParams) (*CreatePRResult, error)

CreatePR creates a new PR using gh CLI

func (*GitHub) FormatState

func (g *GitHub) FormatState(state string) string

FormatState returns a human-readable PR state

func (*GitHub) GetPRBranch

func (g *GitHub) GetPRBranch(repoURL string, number int) (string, error)

GetPRBranch fetches the head branch name for a PR number using gh CLI

func (*GitHub) GetPRForBranch

func (g *GitHub) GetPRForBranch(repoURL, branch string) (*PRInfo, error)

GetPRForBranch fetches PR info for a branch using gh CLI

func (*GitHub) MergePR

func (g *GitHub) MergePR(repoURL string, number int, strategy string) error

MergePR merges a PR by number with the given strategy

func (*GitHub) Name

func (g *GitHub) Name() string

Name returns "github"

func (*GitHub) ViewPR added in v0.4.0

func (g *GitHub) ViewPR(repoURL string, number int, web bool) error

ViewPR shows PR details or opens in browser

type GitLab

type GitLab struct{}

GitLab implements Forge for GitLab repositories using the glab CLI.

func (*GitLab) Check

func (g *GitLab) Check() error

Check verifies that glab CLI is available and authenticated

func (*GitLab) CloneRepo

func (g *GitLab) CloneRepo(repoSpec, destPath string) (string, error)

CloneRepo clones a GitLab repo using glab CLI

func (*GitLab) CreatePR added in v0.3.0

func (g *GitLab) CreatePR(repoURL string, params CreatePRParams) (*CreatePRResult, error)

CreatePR creates a new MR using glab CLI

func (*GitLab) FormatState

func (g *GitLab) FormatState(state string) string

FormatState returns a human-readable PR state

func (*GitLab) GetPRBranch

func (g *GitLab) GetPRBranch(repoURL string, number int) (string, error)

GetPRBranch fetches the source branch name for a PR number using glab CLI

func (*GitLab) GetPRForBranch

func (g *GitLab) GetPRForBranch(repoURL, branch string) (*PRInfo, error)

GetPRForBranch fetches PR info for a branch using glab CLI

func (*GitLab) MergePR

func (g *GitLab) MergePR(repoURL string, number int, strategy string) error

MergePR merges a MR by number with the given strategy

func (*GitLab) Name

func (g *GitLab) Name() string

Name returns "gitlab"

func (*GitLab) ViewPR added in v0.4.0

func (g *GitLab) ViewPR(repoURL string, number int, web bool) error

ViewPR shows MR details or opens in browser

type PRInfo

type PRInfo = cache.PRInfo

PRInfo is an alias to cache.PRInfo for backward compatibility

Jump to

Keyboard shortcuts

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