forge

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented is returned by Forge methods that are not yet implemented.

Functions

func FormatRemoteID

func FormatRemoteID(ft ForgeType, number int) string

FormatRemoteID returns a display ID like "github#42".

func ParseHostOwnerRepo

func ParseHostOwnerRepo(remoteURL string) (host, owner, repo string, err error)

ParseHostOwnerRepo extracts the host, owner, and repo name from a git remote URL. For self-hosted instances (e.g., gitlab.example.com), the host is needed so CLIs like glab can target the correct server.

func ParseOwnerRepo

func ParseOwnerRepo(remoteURL string) (owner, repo string, err error)

ParseOwnerRepo extracts the owner and repo name from a git remote URL. Supports both SSH (git@host:owner/repo.git) and HTTPS (https://host/owner/repo.git) formats. For nested groups (e.g., GitLab subgroups), owner includes the full path (group/subgroup).

Types

type Comment

type Comment struct {
	ID        int       `json:"id"`
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
}

Comment represents a comment on an issue or diff.

type Diff

type Diff struct {
	Number    int       `json:"number"`
	Title     string    `json:"title"`
	Body      string    `json:"body,omitempty"`
	State     string    `json:"state"`
	URL       string    `json:"url"`
	Author    string    `json:"author,omitempty"`
	Branch    string    `json:"branch"`
	Base      string    `json:"base"`
	CreatedAt time.Time `json:"created_at"`
}

Diff represents a remote pull request / merge request.

type Forge

type Forge interface {
	Type() ForgeType

	// Issues
	ListIssues(ctx context.Context, owner, repo, state string) ([]Issue, error)
	GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)
	CreateIssue(ctx context.Context, owner, repo, title, body string) (*Issue, error)
	CommentOnIssue(ctx context.Context, owner, repo string, number int, body string) error

	// Diffs (pull requests / merge requests)
	ListDiffs(ctx context.Context, owner, repo, state string) ([]Diff, error)
	GetDiff(ctx context.Context, owner, repo string, number int) (*Diff, error)
	CreateDiff(ctx context.Context, owner, repo, title, body, head, base string) (*Diff, error)
	ListDiffComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)
	CommentOnDiff(ctx context.Context, owner, repo string, number int, body string) error

	// Availability
	CheckAvailable() error
	CheckAuthenticated() error
}

Forge abstracts issue and diff operations on GitHub/GitLab.

func ForForgeType

func ForForgeType(ft ForgeType) (Forge, error)

ForForgeType returns the Forge implementation for the given type. The returned forge targets the default SaaS host (github.com / gitlab.com). Use ResolveForge to get a host-aware forge for self-hosted instances.

func ResolveForge

func ResolveForge(name, repoURL, forgeStr string) (Forge, string, string, error)

ResolveForge determines the forge, owner, and repo for a resolved repo config. The returned Forge is configured with the correct host from the repo URL, so self-hosted instances (e.g., gitlab.example.com) work automatically.

type ForgeType

type ForgeType string

ForgeType identifies the forge provider.

const (
	GitHub ForgeType = "github"
	GitLab ForgeType = "gitlab"
)

func ParseRemoteID

func ParseRemoteID(id string) (ForgeType, int, bool)

ParseRemoteID parses "github#42" or "gitlab#42" into forge type and number. Returns false if the ID doesn't match the remote pattern.

type GitHubForge

type GitHubForge struct {
	Host string // e.g., "github.com" or a GitHub Enterprise host
}

GitHubForge implements Forge using the gh CLI.

func (*GitHubForge) CheckAuthenticated

func (g *GitHubForge) CheckAuthenticated() error

func (*GitHubForge) CheckAvailable

func (g *GitHubForge) CheckAvailable() error

func (*GitHubForge) CommentOnDiff

func (g *GitHubForge) CommentOnDiff(ctx context.Context, owner, repo string, number int, body string) error

func (*GitHubForge) CommentOnIssue

func (g *GitHubForge) CommentOnIssue(ctx context.Context, owner, repo string, number int, body string) error

func (*GitHubForge) CreateDiff

func (g *GitHubForge) CreateDiff(ctx context.Context, owner, repo, title, body, head, base string) (*Diff, error)

func (*GitHubForge) CreateIssue

func (g *GitHubForge) CreateIssue(ctx context.Context, owner, repo, title, body string) (*Issue, error)

func (*GitHubForge) GetDiff

func (g *GitHubForge) GetDiff(ctx context.Context, owner, repo string, number int) (*Diff, error)

func (*GitHubForge) GetIssue

func (g *GitHubForge) GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)

func (*GitHubForge) ListDiffComments

func (g *GitHubForge) ListDiffComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)

func (*GitHubForge) ListDiffs

func (g *GitHubForge) ListDiffs(ctx context.Context, owner, repo, state string) ([]Diff, error)

func (*GitHubForge) ListIssues

func (g *GitHubForge) ListIssues(ctx context.Context, owner, repo, state string) ([]Issue, error)

func (*GitHubForge) Type

func (g *GitHubForge) Type() ForgeType

type GitLabForge

type GitLabForge struct {
	Host string // e.g., "gitlab.com" or "gitlab.example.com"
}

GitLabForge implements Forge using the glab CLI.

func (*GitLabForge) CheckAuthenticated

func (g *GitLabForge) CheckAuthenticated() error

func (*GitLabForge) CheckAvailable

func (g *GitLabForge) CheckAvailable() error

func (*GitLabForge) CommentOnDiff

func (g *GitLabForge) CommentOnDiff(ctx context.Context, owner, repo string, number int, body string) error

func (*GitLabForge) CommentOnIssue

func (g *GitLabForge) CommentOnIssue(ctx context.Context, owner, repo string, number int, body string) error

func (*GitLabForge) CreateDiff

func (g *GitLabForge) CreateDiff(ctx context.Context, owner, repo, title, body, head, base string) (*Diff, error)

func (*GitLabForge) CreateIssue

func (g *GitLabForge) CreateIssue(ctx context.Context, owner, repo, title, body string) (*Issue, error)

func (*GitLabForge) GetDiff

func (g *GitLabForge) GetDiff(ctx context.Context, owner, repo string, number int) (*Diff, error)

func (*GitLabForge) GetIssue

func (g *GitLabForge) GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)

func (*GitLabForge) ListDiffComments

func (g *GitLabForge) ListDiffComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)

func (*GitLabForge) ListDiffs

func (g *GitLabForge) ListDiffs(ctx context.Context, owner, repo, state string) ([]Diff, error)

func (*GitLabForge) ListIssues

func (g *GitLabForge) ListIssues(ctx context.Context, owner, repo, state string) ([]Issue, error)

func (*GitLabForge) Type

func (g *GitLabForge) Type() ForgeType

type Issue

type Issue struct {
	Number    int       `json:"number"`
	Title     string    `json:"title"`
	Body      string    `json:"body,omitempty"`
	State     string    `json:"state"`
	URL       string    `json:"url"`
	Labels    []string  `json:"labels,omitempty"`
	Author    string    `json:"author,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

Issue represents a remote issue/ticket.

Jump to

Keyboard shortcuts

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