meta

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRepoNotInitialized = errors.New("this repository not initialized: please run `av init`")

Functions

func DeleteBranch

func DeleteBranch(repo *git.Repo, name string) error

func PreviousBranches added in v0.0.6

func PreviousBranches(branches map[string]Branch, name string) ([]string, error)

Find all the ancestor branches of the given branch name and append them to the given slice (in topological order: a comes before b if a is an ancestor of b).

func ReadAllBranches

func ReadAllBranches(repo *git.Repo) (map[string]Branch, error)

ReadAllBranches fetches all branch metadata stored in the git repository. It returns a map where the key is the name of the branch.

func SubsequentBranches added in v0.0.6

func SubsequentBranches(branches map[string]Branch, name string) ([]string, error)

Find all the child branches of the given branch name and append them to the given slice (in topological order: a comes before b if a is an ancestor of b).

func Trunk added in v0.0.7

func Trunk(repo *git.Repo, branchName string) (string, error)

func WriteBranch

func WriteBranch(repo *git.Repo, s Branch) error

WriteBranch writes branch metadata to the git repository. It can be loaded again with ReadBranch.

func WriteRepository

func WriteRepository(repo *git.Repo, meta Repository) error

WriteRepository writes repository metadata to the git repo. It can be loaded again with ReadRepository.

Types

type Branch

type Branch struct {
	// The branch name associated with this stack.
	// Not stored in JSON because the name can always be derived from the name
	// of the git ref.
	Name string `json:"-"`

	// Information about the parent branch.
	Parent BranchState `json:"parent,omitempty"`

	// The children branches of this branch within the stack (if any).
	Children []string `json:"children,omitempty"`

	// The associated pull request information, if any.
	PullRequest *PullRequest `json:"pullRequest,omitempty"`

	// The merge commit onto the trunk branch, if any
	MergeCommit string `json:"mergeCommit,omitempty"`
}

func FindStackRoot added in v0.0.7

func FindStackRoot(branches map[string]Branch, name string) (Branch, bool)

func ReadBranch

func ReadBranch(repo *git.Repo, branchName string) (Branch, bool)

ReadBranch loads information about the branch from the git repository. Returns the branch metadata and a boolean indicating if the branch metadata already existed and was loaded. If the branch metadata does not exist, a useful default is returned.

func (Branch) BaseCommit added in v0.0.5

func (b Branch) BaseCommit(r *git.Repo) (string, error)

BaseCommit determines the base commit for the given branch. The base commit is defined as the latest commit on the branch that should not be considered one of the critical commits on the stacked branch itself. This is essentially the merge-base of the branch and its parent and should be used as the `<upstream>` in the `git rebase --onto <parent-branch> <upstream>` command.

func (*Branch) IsStackRoot added in v0.0.5

func (b *Branch) IsStackRoot() bool

func (*Branch) UnmarshalJSON added in v0.0.5

func (b *Branch) UnmarshalJSON(bytes []byte) error

type BranchState added in v0.0.5

type BranchState struct {
	// The branch name associated with the parent of the stack (if any).
	// If empty, this branch (potentially*) is considered a stack root.
	// (*depending on the context, we only consider the branch a stack root if
	// it also has children branches; for example, any "vanilla" branch off of
	// trunk will have no parent, but we usually don't explicitly consider it a
	// stack unless it also has stack children)
	Name string `json:"name"`

	// If true, consider the branch a trunk branch. A trunk branch is one that
	// that stacks can target for merge. Usually, the only trunk branch for a
	// repository is main or master.
	Trunk bool `json:"trunk,omitempty"`

	// The commit SHA of the parent's latest commit. This is used when syncing
	// the branch with the parent to identify the commits that belong to the
	// child branch (since the HEAD of the parent branch may change).
	// This will be unset if Trunk is true.
	Head string `json:"head,omitempty"`
}

func ReadBranchState added in v0.0.5

func ReadBranchState(repo *git.Repo, branch string, trunk bool) (BranchState, error)

type PullRequest

type PullRequest struct {
	// The GitHub (GraphQL) ID of the pull request.
	ID string `json:"id"`
	// The pull request number.
	Number int64 `json:"number"`
	// The web URL for the pull request.
	Permalink string `json:"permalink"`
	// The state of the pull request (open, closed, or merged).
	State githubv4.PullRequestState
}

func (*PullRequest) GetNumber added in v0.0.8

func (p *PullRequest) GetNumber() int64

GetNumber returns the number of the pull request or zero if the PullRequest is nil.

type Repository

type Repository struct {
	// The GitHub (GraphQL) ID of the repository (e.g., R_kgDOHMmHmg).
	ID string `json:"id"`
	// The owner of the repository (e.g., aviator-co)
	Owner string `json:"owner"`
	// The name of the repository (e.g., av)
	Name string `json:"name"`
}

func ReadRepository

func ReadRepository(repo *git.Repo) (Repository, error)

ReadRepository reads repository metadata from the git repo. Returns the metadata and a boolean indicating if the metadata was found.

Jump to

Keyboard shortcuts

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