core

package
v0.0.0-...-df17592 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func ExtractPrNumber

func ExtractPrNumber(branchname string) (int, error)

func FileExists

func FileExists(file string) bool

func GetBaseBranch

func GetBaseBranch() string

func GetCleanMaster

func GetCleanMaster() bool

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 GetRemoteName

func GetRemoteName() 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 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
	HasState bool

	Repo *Repo
	// contains filtered or unexported fields
}

func NewLocalPr

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

func (*LocalPr) AddKnownTip

func (b *LocalPr) AddKnownTip(tip plumbing.Hash)

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) StateFile

func (b *LocalPr) StateFile() string

func (*LocalPr) Url

func (b *LocalPr) Url() string

type PrStates

type PrStates struct {
	Repo *Repo
}

func (PrStates) AllPrs

func (s PrStates) AllPrs(ctx context.Context) []LocalPr

func (PrStates) StatesPath

func (s PrStates) StatesPath() string

type Repo

type Repo struct {
	*git.Repository
}

func Current

func Current() *Repo

func (*Repo) AllLocalPrs

func (r *Repo) AllLocalPrs() (map[int]plumbing.Hash, 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(branch Branch) error

func (*Repo) CheckoutRef

func (r *Repo) CheckoutRef(ref *plumbing.Reference) error

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 plumbing.Hash) (Branch, []*object.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 plumbing.Hash) ([]*object.Commit, error)

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

func (*Repo) GetLocalTip

func (r *Repo) GetLocalTip(b Branch) (*object.Commit, error)

func (*Repo) GetRemoteTip

func (r *Repo) GetRemoteTip(b Branch) (*object.Commit, 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) 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 plumbing.Hash, 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) TryLocalRebaseOntoSilently

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

func (*Repo) TryRebaseBranchOnto

func (r *Repo) TryRebaseBranchOnto(ctx context.Context, parent plumbing.Hash, 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 plumbing.Hash, onto Branch, interactive bool) bool

func (*Repo) Worktree

func (r *Repo) Worktree() *git.Worktree

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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