provider

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

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentBranch

func CurrentBranch(nfo *Info) (string, error)

CurrentBranch returns the current branch name of the repository detected from Info.

func DefaultBranchBitbucket

func DefaultBranchBitbucket(ctx context.Context, bb *bitbucket.Client, nfo *Info) (string, error)

DefaultBranchBitbucket returns the main branch (default) for a Bitbucket Cloud repository.

func DefaultBranchGitHub

func DefaultBranchGitHub(ctx context.Context, gh *githublib.Client, nfo *Info) (string, error)

DefaultBranchGitHub returns the default branch for a GitHub repository.

func DefaultBranchGitLab

func DefaultBranchGitLab(ctx context.Context, gl *gitlab.Client, nfo *Info) (string, error)

DefaultBranchGitLab returns the default branch for a GitLab project.

func FindRepoRoot

func FindRepoRoot(path string) (root, gitdir, wt string, err error)

FindRepoRoot returns the absolute path to the root of the repository and git related dir locations: - wt: if "" => the git checkout at root is not a worktree or path to git worktree folder - gitdir: absolute path to root of git repository dir ($root/.git if not in worktree)

func LastCommitTitle

func LastCommitTitle(nfo *Info) (string, error)

LastCommitTitle returns the first line of the last commit message on HEAD.

func LocalBranchDelete

func LocalBranchDelete(repo *git.Repository, name string, force bool) error

LocalBranchDelete deletes a local branch reference. It refuses to delete the currently checked out branch. The force flag is currently ignored for safety (git also refuses deletion of the current branch).

func LocalBranchRename

func LocalBranchRename(repo *git.Repository, oldName, newName string) error

LocalBranchRename renames a local branch reference and updates HEAD if needed.

func ParallelMap

func ParallelMap[T, U any](iter iter.Seq[T], f func(T) (U, error)) ([]U, error)

func ParallelMapValues

func ParallelMapValues[T, U any](elems []T, f func(T) (U, error)) ([]U, error)

func ResolvePRTitle

func ResolvePRTitle(inTitle string, nfo *Info) (string, error)

ResolvePRTitle ensures a non-empty title, using last commit subject when missing.

Types

type BranchDeleteOptions

type BranchDeleteOptions struct {
	Force bool
}

type BranchInfo

type BranchInfo struct {
	Name       string
	CommitDate time.Time
	Author     string
}

type BranchListOptions

type BranchListOptions struct {
	Pattern string
	Sort    string // name|date|author
	Author  string // case-insensitive substring match on author
	Since   string // human duration like 72h, 10d, 3w
}

type BranchRenameOptions

type BranchRenameOptions struct {
	NoUpdatePRs bool
}

type CreateOptions

type CreateOptions struct {
	Title string
	Body  string
	Base  string // target branch
	Head  string // source branch
	Draft bool
	// SquashByDefault indicates the PR/MR should default to squashing commits when merged
	// (provider support varies; ignored where unsupported)
	SquashByDefault  bool
	DeleteAfterMerge bool
}

CreateOptions controls PR/MR creation.

type Info

type Info struct {
	LocalRepo

	Provider Provider // enum: github|gitlab|bitbucket|unknown
	Variant  string   // cloud|self-hosted|unknown
	Evidence string   // method used (e.g. api_v4_version, headers, url-heuristic)
	HTTPBase string   // http(s) base used for probing, if any

	Host   string // e.g. github.com
	Owner  string // e.g. user or project
	Repo   string // repository name without .git
	Remote string // remote name used (e.g. origin)
	URL    string // original remote URL used

	Config *config.Config // user configuration (may be nil)
}

Info contains parsed repository and provider details inferred from git remotes.

func DetectFromRepo

func DetectFromRepo(localRepo *LocalRepo, cfg *config.Config) (*Info, error)

DetectFromRepo infers provider and repo info for an already detected local repository by inspecting remotes (preferring origin, then upstream, then first). It also performs light network probing (like the Python reference) to identify self-hosted services.

type ListOptions

type ListOptions struct {
	State    string // open|closed|merged|all
	Author   string
	Assignee string
	Base     string
	Head     string
	Limit    int
}

ListOptions are filters for PR list queries.

type LocalRepo

type LocalRepo struct {
	Root     string          // absolute repository root directory (worktree), respects -C
	GitDir   string          // absolute path to /../.git dir (resolved .git file if inside worktree)
	Worktree string          // absolute path to /../.git/worktrees/<name>
	GitRepo  *git.Repository // handle to git repository instance or nil if not available
}

func FindLocalRepo

func FindLocalRepo(path string) (*LocalRepo, error)

type MergeOptions

type MergeOptions struct {
	Method       string // merge|squash|rebase (provider support varies)
	DeleteBranch bool
}

MergeOptions controls how a PR/MR is merged.

type PRComment

type PRComment struct {
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
	// Optional location for inline comments (when available)
	Path string `json:"path,omitempty"`
	Line int    `json:"line,omitempty"`
	URL  string `json:"url,omitempty"`
}

PRComment represents a single review comment on a PR/MR.

type PRDetails

type PRDetails struct {
	Number    int
	Title     string
	Body      string
	Author    string
	State     string
	CreatedAt time.Time
	UpdatedAt time.Time
	Merged    bool
	Draft     bool
	Base      string
	Head      string
	URL       string
}

PRDetails is a provider-agnostic view of a single PR/MR.

type Provider

type Provider int

Provider represents a supported git hosting provider.

const (
	ProviderUnknown Provider = iota
	ProviderGitHub
	ProviderGitLab
	ProviderBitbucket
)

func (Provider) BranchDelete

func (p Provider) BranchDelete(ctx context.Context, nfo *Info, name string, opts BranchDeleteOptions) error

BranchDelete deletes a remote branch across providers. It prevents deleting the default branch unless Force is true (where detectable).

func (Provider) BranchListRemote

func (p Provider) BranchListRemote(ctx context.Context, nfo *Info, opts BranchListOptions) ([]BranchInfo, error)

BranchListRemote lists remote branches using provider APIs.

func (Provider) BranchRename

func (p Provider) BranchRename(ctx context.Context, nfo *Info, oldName, newName string, opts BranchRenameOptions) error

BranchRename renames a remote branch across providers.

func (Provider) BranchWebURL

func (p Provider) BranchWebURL(nfo *Info, branch string) (string, error)

BranchWebURL constructs a web URL for viewing a branch for the given repo info. It supports GitHub, GitLab, and Bitbucket Cloud. For self-hosted instances, it uses Info.HTTPBase if available; otherwise it falls back to https://<host>.

func (Provider) PrClose

func (p Provider) PrClose(ctx context.Context, nfo *Info, number int) (*PRDetails, error)

PrClose closes a pull/merge request without merging.

func (Provider) PrComments

func (p Provider) PrComments(ctx context.Context, nfo *Info, number int) ([]PRComment, error)

PrComments lists review comments for a PR number. For now only GitLab is supported.

func (Provider) PrCreate

func (p Provider) PrCreate(ctx context.Context, nfo *Info, in CreateOptions) (*PRDetails, error)

PrCreate creates a pull/merge request on the detected provider.

func (Provider) PrList

func (p Provider) PrList(ctx context.Context, nfo *Info, opts ListOptions) ([]PullRequest, error)

PrList lists pull/merge requests for a detected provider.

func (Provider) PrMerge

func (p Provider) PrMerge(ctx context.Context, nfo *Info, number int, opts MergeOptions) (*PRDetails, error)

PrMerge merges a pull/merge request across supported providers.

func (Provider) PrView

func (p Provider) PrView(ctx context.Context, nfo *Info, number int) (*PRDetails, error)

PrView retrieves details for a single pull/merge request.

func (Provider) String

func (p Provider) String() string

type PullRequest

type PullRequest struct {
	Number    int
	Title     string
	Author    string
	State     string
	CreatedAt time.Time
	URL       string
}

PullRequest is a provider-agnostic PR representation for output.

Jump to

Keyboard shortcuts

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