cmd

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const VERSION = "v0.0.13"

VERSION number: changed in CI

Variables

View Source
var (
	BranchFlag = Flag{
		Short: "B",
		Long:  "branch",
		Description: "The name of the target branch of the commit. When used in conjunction with the --use-pr " +
			"flag, the branch is the base ref of the PR created. Otherwise, the commit is pushed directly to the " +
			"branch.",
		Required: true,
		Type:     "string",
	}

	MessageFlag = Flag{
		Short: "m",
		Long:  "message",
		Description: "The message connected to the commit. When used in conjunction with --use-pr, the " +
			"commit message is used as the PR title and PR description, unless overridden.",
		Required: true,
		Type:     "string",
	}

	UsePrFlag = Flag{
		Short: "P",
		Long:  "use-pr",
		Description: "Create a PR rather than committing directly to the branch. Unless a head-ref is " +
			"specified manually, the head ref name is generated in the format of <BASE REF>-<RANDOM SALT>.",
		Required: false,
		Type:     "bool",
	}

	HeadRefFlag = Flag{Short: "H", Long: "head-ref", Description: "The name of the branch created with the base ref being `--branch`. Only relevant if used in conjunction with the --use-pr flag.", Type: "string"}
	PrTitleFlag = Flag{Short: "T", Long: "title", Description: "The title of the PR created. Only relevant if used in conjunction with the --use-pr flag. If not specified, the PR title will be the commit message.", Type: "string"}
	PrDescFlag  = Flag{Short: "D", Long: "pr-description", Description: "The description of the PR created. Only relevant if used in conjunction with the --use-pr flag. If not specified, the PR title will be the commit message.", Type: "string"}
	PrLabelFlag = Flag{Short: "l", Long: "label", Description: "A list of labels to add to the PR created. Only relevant if used in conjunction with the --use-pr flag. Labels can be added recursively -- i.e. -l feature -l blocked.", Type: "stringSlice"}
	AllFlag     = Flag{Short: "A", Long: "all", Description: "Commit all tracked files that have changed. Only relevant if the target branch is the same as the local branch.", Type: "bool", Default: "false"}
	Untracked   = Flag{Short: "U", Long: "untracked", Description: "Include untracked files in the commit. Only relevant if used in conjunction with the --all flag.", Type: "bool", Default: "false"}
	DryRun      = Flag{Short: "d", Long: "dry-run", Description: "Show which files would be committed.", Type: "bool", Default: "false"}
)

Functions

func AssociateCommitWithBranch added in v0.0.9

func AssociateCommitWithBranch(branch string, commitSha string) error

func CreateBlob added in v0.0.9

func CreateBlob(file string) (string, error)

func CreateCommitFromTree added in v0.0.9

func CreateCommitFromTree(latestCommit, treeSha, commitMessage string) (string, error)

func CreatePullRequest added in v0.0.9

func CreatePullRequest(baseRef, headRef, title, description string, labels []string) error

func CreateTree added in v0.0.9

func CreateTree(baseTree string, blobs []BlobInfo) (string, error)

func EnsureBranchesExist added in v0.0.8

func EnsureBranchesExist(targetBranch, intermediateBranch string, repoSettings *RepoSettings) (string, error)

func Execute

func Execute()

func GetFileSelection added in v0.0.7

func GetFileSelection(args []string, commitAll bool, commitUntracked bool) ([]string, error)

func GetTreeTip added in v0.0.9

func GetTreeTip(commitSha string) (string, error)

func ListAllFilesByPattern added in v0.0.7

func ListAllFilesByPattern(patterns ...string) ([]string, error)

func ListStagedFiles added in v0.0.7

func ListStagedFiles() ([]string, error)

func ListUntrackedFiles added in v0.0.7

func ListUntrackedFiles() ([]string, error)

func ValidateAllLabels added in v0.0.9

func ValidateAllLabels(labels []string) error

func ValidateLocalGit added in v0.0.8

func ValidateLocalGit() (string, error)

Types

type BlobInfo added in v0.0.9

type BlobInfo struct {
	Path string  `json:"path"`
	Mode string  `json:"mode"`
	Type string  `json:"type"`
	Sha  *string `json:"sha"`
}

func CreateBlobs added in v0.0.9

func CreateBlobs(files []string) ([]BlobInfo, error)

CreateBlobs creates the leaves of the trees that commits reference.

type BranchDescriptionResponse added in v0.0.8

type BranchDescriptionResponse struct {
	Commit struct {
		SHA string `json:"sha"`
	} `json:"commit"`
}

type CommandExecutor added in v0.0.12

type CommandExecutor interface {
	RunCommand(name string, arg ...string) ([]byte, error)
}

CommandExecutor is an interface for executing commands.

type CommitSettings added in v0.0.7

type CommitSettings struct {
	CommitMessage  string
	CommitToBranch string
}

type DefaultCommandExecutor added in v0.0.12

type DefaultCommandExecutor struct{}

DefaultCommandExecutor is the default implementation of CommandExecutor.

func (*DefaultCommandExecutor) RunCommand added in v0.0.12

func (d *DefaultCommandExecutor) RunCommand(name string, arg ...string) ([]byte, error)

RunCommand executes a command and returns its output.

type Flag added in v0.0.7

type Flag struct {
	Short       string
	Long        string
	Description string
	Required    bool
	Type        string // "bool", "string", "stringSlice"
	Default     string
}

type LabelRequest added in v0.0.9

type LabelRequest struct {
	Labels []string `json:"labels"`
}

type LabelResponse added in v0.0.9

type LabelResponse struct {
	Name string `json:"name"`
}

type PrRequest added in v0.0.9

type PrRequest struct {
	Title string `json:"title"`
	Body  string `json:"body"`
	Head  string `json:"head"`
	Base  string `json:"base"`
}

type PrResponse added in v0.0.9

type PrResponse struct {
	Url    string `json:"url"`
	Number int    `json:"number"`
}

type PrSettings added in v0.0.7

type PrSettings struct {
	BaseRef     string
	HeadRef     string
	Title       string
	Description string
	Labels      []string
}

type RepoDescriptionResponse added in v0.0.8

type RepoDescriptionResponse struct {
	DefaultBranch string `json:"default_branch"`
}

type RepoSettings added in v0.0.8

type RepoSettings struct {
	DefaultBranch    string
	DefaultBranchSha string
}

func ValidateGitRemote added in v0.0.8

func ValidateGitRemote() (*RepoSettings, error)

type RunSettings added in v0.0.7

type RunSettings struct {
	PrSettings     *PrSettings
	CommitSettings *CommitSettings
	RepoSettings   *RepoSettings
	FileSelection  []string
	DryRun         bool
}

func ValidateAndConfigureRun added in v0.0.8

func ValidateAndConfigureRun(args []string, cmd *cobra.Command, rs *RepoSettings) (*RunSettings, error)

func (*RunSettings) Commit added in v0.0.7

func (rn *RunSettings) Commit() error

func (*RunSettings) ExecuteDryRun added in v0.0.7

func (rn *RunSettings) ExecuteDryRun()

type ShaResponse added in v0.0.9

type ShaResponse struct {
	Sha string `json:"sha"`
}

Jump to

Keyboard shortcuts

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