utils

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetBranchName = sync.OnceValue(func() string { return GetCurrentBranch().Unwrap() })

Functions

func Add

func Add(files ...string) error

Add stages files for commit.

func BranchExists

func BranchExists(branch string) (bool, error)

func Commit

func Commit(message string) error

Commit creates a commit with the given message.

func CommitAmend

func CommitAmend(message string) error

CommitAmend amends the last commit with a new message.

func Context

func Context() context.Context

func CreateWorktree

func CreateWorktree(issueNumberOrBranch, baseBranch string) (string, error)

CreateWorktree creates a new git worktree

func CreateWorktreeFromBranch

func CreateWorktreeFromBranch(worktreePath, sourceBranch, targetBranch string) error

CreateWorktreeFromBranch creates a new git worktree from an existing branch

func DeleteBranch

func DeleteBranch(branch string) error

func DetermineWorktreeNames

func DetermineWorktreeNames(input string) (branchName, dirSuffix string)

DetermineWorktreeNames determines the branch name and directory suffix based on input If input contains a slash, it's treated as a full branch name Otherwise, "/impl" is appended to create the branch name

func Edit

func Edit(editPath string)

func ExcludeFromDiff

func ExcludeFromDiff(path string) string

ExcludeFromDiff 生成 Git 排除路径的格式

func GeneratePrompt

func GeneratePrompt(locale string, maxLength int, commitType CommitType) string

func GetAllGitTags

func GetAllGitTags(ctx context.Context) []*semver.Version

func GetAllRemoteTags

func GetAllRemoteTags(ctx context.Context) []*semver.Version

func GetCommitCount

func GetCommitCount(branch string) (r result.Result[int])

func GetCurMaxVer

func GetCurMaxVer(ctx context.Context) *semver.Version

func GetCurrentBranch

func GetCurrentBranch() result.Result[string]

func GetCurrentBranchV1

func GetCurrentBranchV1() (string, error)

func GetDetectedMessage

func GetDetectedMessage(files []string) string

GetDetectedMessage 生成检测到的文件数量的消息

func GetEditor

func GetEditor() (r result.Result[string])

func GetNextGitMaxTag

func GetNextGitMaxTag(tags []*semver.Version) *semver.Version

func GetNextReleaseTag

func GetNextReleaseTag(tags []*semver.Version) *semver.Version

func GetNextTag

func GetNextTag(pre string, tags []*semver.Version) *semver.Version

func GetRepositoryName

func GetRepositoryName() (string, error)

func GetStagedDiff

func GetStagedDiff(ctx context.Context, excludeFiles ...string) (r result.Result[*GetStagedDiffRsp])

GetStagedDiff 获取暂存区的差异

func GitBranchSetUpstream

func GitBranchSetUpstream(ctx context.Context, branch string) (r result.Error)

func GitFetchAll

func GitFetchAll(ctx context.Context)

func GitPull

func GitPull(ctx context.Context, args ...string) (r result.Error)

func GitPush

func GitPush(ctx context.Context, args ...string) string

func GitPushTag

func GitPushTag(ctx context.Context, ver string) string

func HasUncommittedChanges

func HasUncommittedChanges() (bool, error)

HasUncommittedChanges checks if there are uncommitted changes in the current worktree

func HasUnpushedCommits

func HasUnpushedCommits() (bool, error)

HasUnpushedCommits checks if there are unpushed commits in the current branch

func IsAheadOfRemote

func IsAheadOfRemote() (bool, error)

IsAheadOfRemote checks if the current branch is ahead of remote.

func IsDirty

func IsDirty() (r result.Result[bool])

func IsErrExit1

func IsErrExit1(err error) bool

func IsErrSignalInterrupt

func IsErrSignalInterrupt(err error) bool

func IsGitRepository

func IsGitRepository() bool

IsGitRepository checks if the current directory is inside a git repository

func IsHelp

func IsHelp() bool

func IsMergedToOrigin

func IsMergedToOrigin(targetBranch string) (bool, error)

IsMergedToOrigin checks if the current branch is merged to origin

func IsOsExit

func IsOsExit(err error) bool

func IsRemotePushCommitFailed

func IsRemotePushCommitFailed(err string) bool

func IsRemoteTagExist

func IsRemoteTagExist(err string) bool

func IsStatusNeedPush

func IsStatusNeedPush(msg string) bool

func LastCommitAuthor

func LastCommitAuthor() (name, email string, err error)

LastCommitAuthor returns the author name and email of the last commit.

func ListAllBranches

func ListAllBranches() ([]string, error)

func Log

func Log() (string, error)

Log returns recent commit messages (last 10). Returns empty string if no commits exist yet.

func LogConfigAndBranch

func LogConfigAndBranch()

func PreGitPush

func PreGitPush(ctx context.Context) string

func PushTag

func PushTag(tag string) result.Error

func RemoveWorktree

func RemoveWorktree(issueNumberOrBranch string) error

RemoveWorktree removes a git worktree by issue number or branch name

func RemoveWorktreeByPath

func RemoveWorktreeByPath(worktreePath string) error

RemoveWorktreeByPath removes a git worktree by its path

func Run

func Run(executors ...func() error) result.Error

func RunCommand

func RunCommand(command string) error

RunCommand executes a command in the current directory

func SanitizeBranchNameForDirectory

func SanitizeBranchNameForDirectory(branchName string) string

func ShellExec

func ShellExec(ctx context.Context, args ...string) (err error)

func ShellExecOutput

func ShellExecOutput(ctx context.Context, args ...string) (r result.Result[string])

func Spin

func Spin[T any](name string, do func() result.Result[T]) (r result.Result[T])

func Status

func Status() (string, error)

Status returns the output of git status.

func UsageDesc

func UsageDesc(format string, args ...interface{}) string

Types

type CommitType

type CommitType string
const (
	EmptyCommitType        CommitType = ""
	ConventionalCommitType CommitType = "conventional"
)

type FileChange

type FileChange struct {
	Path    string
	Added   int
	Removed int
}

func DiffStat

func DiffStat() ([]FileChange, error)

DiffStat returns statistics for all changed files (staged and unstaged).

type GetStagedDiffRsp

type GetStagedDiffRsp struct {
	Files []string `json:"files"`
	Diff  string   `json:"diff"`
}

type KnownError

type KnownError struct {
	Message string
}

KnownError 是一个自定义错误类型

func (*KnownError) Error

func (e *KnownError) Error() string

type OpenaiClient

type OpenaiClient struct {
	Client *openai.Client
	Cfg    *OpenaiConfig
}

func NewOpenaiClient

func NewOpenaiClient(cfg *OpenaiConfig) *OpenaiClient

type OpenaiConfig

type OpenaiConfig struct {
	ApiKey  string `yaml:"api_key"`
	BaseURL string `yaml:"base_url"`
	Model   string `yaml:"model"`
}

type WorktreeInfo

type WorktreeInfo struct {
	Path       string
	Branch     string
	Commit     string
	IsDetached bool
	IsCurrent  bool
}

WorktreeInfo represents information about a git worktree

func GetWorktreeForIssue

func GetWorktreeForIssue(issueNumberOrBranch string) (*WorktreeInfo, error)

GetWorktreeForIssue finds a worktree for a specific issue number or branch name

func ListWorktrees

func ListWorktrees() ([]WorktreeInfo, error)

ListWorktrees returns a list of all worktrees

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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