core

package
v0.0.0-...-363660f Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAPrBranch = errors.New("not a pr branch")
View Source
var ErrReferenceNotFound = errors.New("reference not found")

Functions

func ClipboardWrite

func ClipboardWrite(pr *LocalPr, title string)

func EnrichPrBodyWithStoryEnabled

func EnrichPrBodyWithStoryEnabled() bool

func ExtractPrNumber

func ExtractPrNumber(branchname string) (int, error)

func FileExists

func FileExists(file string) bool

func GetBaseBranch

func GetBaseBranch() string

func GetGithubMergeMethod

func GetGithubMergeMethod() string

func GetGithubOwner

func GetGithubOwner() string

The first part of the repo, before the slash.

func GetGithubRepo

func GetGithubRepo() string

func GetGithubRepoName

func GetGithubRepoName() string

The second part of the repo, after the slash.

func GetGithubTimeout

func GetGithubTimeout() time.Duration

func GetGithubToken

func GetGithubToken() string

func GetGithubUsername

func GetGithubUsername() string

func GetPushCommand

func GetPushCommand() string

func GetRemoteName

func GetRemoteName() string

func GetStoryTool

func GetStoryTool() string

func GetStoryToolToken

func GetStoryToolToken() string

func GetStoryToolUrl

func GetStoryToolUrl() string

func LocalBranchForPr

func LocalBranchForPr(number int) string

func Must

func Must[K any](k K, err error) K

func RemoteBranchForPr

func RemoteBranchForPr(number int) string

Types

type Branch

type Branch interface {
	IsPr() bool
	LocalName() string
	RemoteName() string
}

func NewBranch

func NewBranch(repo *Repo, name string) Branch

type BranchState

type BranchState struct {
	Ancestor struct {
		Name      string
		KnownTips []string
	}
	KnownTips []string
}

type Commit

type Commit struct {
	Hash    string
	Message string
}

type Gh

type Gh interface {
	PullRequests() GhPullRequest
	Issues() GhIssues
}

type GhIssues

type GhIssues interface {
	ListByRepo(ctx context.Context, owner string, repo string, opts *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error)
	CreateComment(ctx context.Context, owner string, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
}

type GhPullRequest

type GhPullRequest interface {
	List(ctx context.Context, owner string, repo string, opt *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error)
	Create(ctx context.Context, owner string, repo string, pull *github.NewPullRequest) (*github.PullRequest, *github.Response, error)
	Get(ctx context.Context, owner string, repo string, number int) (*github.PullRequest, *github.Response, error)
	Merge(ctx context.Context, owner string, repo string, number int, commitMessage string, options *github.PullRequestOptions) (*github.PullRequestMergeResult, *github.Response, error)
}

type GithubClient

type GithubClient struct {
	*github.Client
}

func NewClient

func NewClient(ctx context.Context) *GithubClient

func (*GithubClient) Issues

func (c *GithubClient) Issues() GhIssues

func (*GithubClient) PullRequests

func (c *GithubClient) PullRequests() GhPullRequest

type LocalPr

type LocalPr struct {
	PrNumber int

	Repo *Repo
	// contains filtered or unexported fields
}

func NewLocalPr

func NewLocalPr(repo *Repo, prNumber int) *LocalPr

func (*LocalPr) AddKnownTip

func (b *LocalPr) AddKnownTip(tip string)

func (*LocalPr) AllAncestors

func (b *LocalPr) AllAncestors() []*LocalPr

Returns all ancestor but not itself.

func (*LocalPr) AncestorTips

func (b *LocalPr) AncestorTips() []string

func (*LocalPr) DeleteState

func (b *LocalPr) DeleteState()

func (*LocalPr) GetAncestor

func (b *LocalPr) GetAncestor() (Branch, error)

func (*LocalPr) IsPr

func (b *LocalPr) IsPr() bool

func (*LocalPr) LocalBranch

func (b *LocalPr) LocalBranch() string

func (*LocalPr) LocalName

func (b *LocalPr) LocalName() string

func (*LocalPr) Push

func (b *LocalPr) Push(ctx context.Context) error

func (*LocalPr) ReloadState

func (b *LocalPr) ReloadState()

func (*LocalPr) RememberCurrentTip

func (b *LocalPr) RememberCurrentTip()

func (*LocalPr) RemoteBranch

func (b *LocalPr) RemoteBranch() string

func (*LocalPr) RemoteName

func (b *LocalPr) RemoteName() string

func (*LocalPr) SetAncestor

func (b *LocalPr) SetAncestor(branch Branch)

func (*LocalPr) SetKnownTipsFromAncestor

func (b *LocalPr) SetKnownTipsFromAncestor(ancestor *LocalPr)

func (*LocalPr) StateIsLoaded

func (pr *LocalPr) StateIsLoaded() bool

func (*LocalPr) Url

func (b *LocalPr) Url() string

type Repo

type Repo struct {
	RootPath string
	// contains filtered or unexported fields
}

func Current

func Current() *Repo

func NewRepo

func NewRepo(folder string) *Repo

NewRepo creates a Repo rooted at the given folder. It walks up the directory tree to find the .git folder.

func (*Repo) AllLocalPrs

func (r *Repo) AllLocalPrs() (map[int]string, error)

func (*Repo) AllPrs

func (r *Repo) AllPrs(ctx context.Context) []LocalPr

func (*Repo) BaseBranch

func (r *Repo) BaseBranch() Branch

func (*Repo) Checkout

func (r *Repo) Checkout(ctx context.Context, branch Branch) error

func (*Repo) CheckoutRef

func (r *Repo) CheckoutRef(ctx context.Context, ref string) error

CheckoutRef checks out the given ref (branch name or commit hash).

func (*Repo) CleanupAfterMerge

func (r *Repo) CleanupAfterMerge(ctx context.Context, pr *LocalPr)

func (*Repo) CleanupMultiple

func (r *Repo) CleanupMultiple(ctx context.Context, toclean []*LocalPr, others []LocalPr)

func (*Repo) Config

func (r *Repo) Config() string

func (*Repo) CurrentBranch

func (r *Repo) CurrentBranch() (Branch, error)

func (*Repo) DeleteLocalAndRemoteBranch

func (r *Repo) DeleteLocalAndRemoteBranch(ctx context.Context, branch Branch) error

func (*Repo) DeleteRemoteBranch

func (r *Repo) DeleteRemoteBranch(ctx context.Context, branch Branch) error

func (*Repo) DetachHead

func (r *Repo) DetachHead(ctx context.Context) error

func (*Repo) DotOpDir

func (r *Repo) DotOpDir() string

func (*Repo) Fetch

func (r *Repo) Fetch(ctx context.Context) error

func (*Repo) FindBranchingPoint

func (r *Repo) FindBranchingPoint(headCommit string) (Branch, []Commit, error)

Takes all commit that are ancestors of headCommit and not in the base branch and walks them until it finds one that is the tip of an exisiting pr/XXX branch. Returns all the commits that were touched during the walk, in git children -> parent order. (e.g. the first commit is always headCommit)

func (*Repo) GetBranch

func (r *Repo) GetBranch(name string) (Branch, error)

func (*Repo) GetCommitsNotInBaseBranch

func (r *Repo) GetCommitsNotInBaseBranch(hash string) ([]Commit, error)

Returns all of the commits between the given hash and its merge-base with the base branch of the repository

func (*Repo) GetCurrentBranchName

func (r *Repo) GetCurrentBranchName(ctx context.Context) (string, error)

GetCurrentBranchName returns the name of the current branch. Returns an error if HEAD is detached (not on a branch). This replaces the pattern: head.Name().Short() and checking head.Name().IsBranch()

func (*Repo) GetHeadHash

func (r *Repo) GetHeadHash(ctx context.Context) (string, error)

GetHeadHash returns the SHA of the current HEAD commit. This replaces the pattern: Repository.Head().Hash()

func (*Repo) GetHeadRef

func (r *Repo) GetHeadRef(ctx context.Context) (string, error)

GetHeadRef returns a string representing the current HEAD. If on a branch, returns the branch name. If detached, returns the commit hash.

func (*Repo) GetLocalTip

func (r *Repo) GetLocalTip(b Branch) (string, error)

func (*Repo) GetMainBranch

func (r *Repo) GetMainBranch(ctx context.Context, remoteName string) (string, error)

func (*Repo) GetRefHash

func (r *Repo) GetRefHash(ctx context.Context, refName string) (string, error)

GetRefHash returns the commit hash that a reference points to. refName should be a full reference name like "refs/heads/main" or "refs/remotes/origin/main". Returns an error if the reference doesn't exist. This replaces the pattern: Repository.Reference(name, true).Hash()

func (*Repo) GetRemoteTip

func (r *Repo) GetRemoteTip(b Branch) (string, error)

func (*Repo) GitExec

func (r *Repo) GitExec(ctx context.Context, format string, args ...any) *exec.Cmd

func (*Repo) InteractiveRebase

func (r *Repo) InteractiveRebase(ctx context.Context, branch Branch) error

When remote is true, rebase on the distant version of the branch. When false, rebase on the local version.

func (*Repo) IsAncestor

func (r *Repo) IsAncestor(ctx context.Context, ancestor, descendant string) bool

IsAncestor returns true if ancestor is an ancestor of descendant.

func (*Repo) NoLocalChanges

func (r *Repo) NoLocalChanges(ctx context.Context) bool

NoLocalChanges returns true when all files are either unmodified or untracked.

func (*Repo) OppEnabled

func (r *Repo) OppEnabled() bool

func (*Repo) Path

func (r *Repo) Path() string

func (*Repo) PrForHead

func (r *Repo) PrForHead() (*LocalPr, bool)

func (*Repo) Push

func (r *Repo) Push(ctx context.Context, hash string, branch string) error

func (*Repo) Rebase

func (r *Repo) Rebase(ctx context.Context, branch Branch) error

When remote is true, rebase on the distant version of the branch. When false, rebase on the local version.

func (*Repo) SetTrackingBranch

func (r *Repo) SetTrackingBranch(localBranch Branch, remoteBranch Branch) error

func (*Repo) StateStore

func (r *Repo) StateStore() *StateStore

func (*Repo) TryLocalRebaseOntoSilently

func (r *Repo) TryLocalRebaseOntoSilently(
	ctx context.Context,
	first string,
	onto string,
) bool

func (*Repo) TryRebaseBranchOnto

func (r *Repo) TryRebaseBranchOnto(ctx context.Context, parent string, onto Branch) bool

func (*Repo) TryRebaseCurrentBranchSilently

func (r *Repo) TryRebaseCurrentBranchSilently(ctx context.Context, branch Branch) bool

func (*Repo) TryRebaseOntoSilently

func (r *Repo) TryRebaseOntoSilently(ctx context.Context, first string, onto Branch, interactive bool) bool

type StateStore

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

func NewStateStore

func NewStateStore(r *Repo) *StateStore

func (*StateStore) AllLocalPrNumbers

func (s *StateStore) AllLocalPrNumbers(ctx context.Context) []int

func (*StateStore) DeleteBranchState

func (s *StateStore) DeleteBranchState(b Branch)

func (*StateStore) GetBranchState

func (s *StateStore) GetBranchState(b Branch) *BranchState

func (*StateStore) SaveBranchState

func (s *StateStore) SaveBranchState(b Branch, state *BranchState) error

func (*StateStore) StateBranchFile

func (s *StateStore) StateBranchFile(b Branch) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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