feat: v0.3.0d — add PR checks, iostreams, aliases, and broad enhancements
Add PR checks command, iostreams/text packages for colored table output, top-level run/workflow aliases matching gh CLI structure. Enhance actions, issues, PRs, releases, repos, labels, milestones, and wiki commands with improved flags, JSON output, and error handling.
This commit is contained in:
parent
7c0dcc8696
commit
113505de95
29 changed files with 3131 additions and 542 deletions
|
|
@ -114,6 +114,48 @@ func parseGitConfig(configPath string) (string, error) {
|
|||
return "", fmt.Errorf("no origin remote found in git config")
|
||||
}
|
||||
|
||||
// GetCurrentBranch returns the name of the currently checked-out branch.
|
||||
func GetCurrentBranch() (string, error) {
|
||||
gitDir, err := findGitDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
headPath := filepath.Join(gitDir, "HEAD")
|
||||
data, err := os.ReadFile(headPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read .git/HEAD: %w", err)
|
||||
}
|
||||
|
||||
headStr := strings.TrimSpace(string(data))
|
||||
if strings.HasPrefix(headStr, "ref: refs/heads/") {
|
||||
return strings.TrimPrefix(headStr, "ref: refs/heads/"), nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("HEAD is not on a branch (detached HEAD)")
|
||||
}
|
||||
|
||||
// findGitDir searches for the .git directory starting from the current directory
|
||||
func findGitDir() (string, error) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get current directory: %w", err)
|
||||
}
|
||||
|
||||
dir := cwd
|
||||
for {
|
||||
gitDir := filepath.Join(dir, ".git")
|
||||
if info, err := os.Stat(gitDir); err == nil && info.IsDir() {
|
||||
return gitDir, nil
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
return "", fmt.Errorf("not in a git repository")
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
}
|
||||
|
||||
// parseRemoteURL extracts owner/name/hostname from various git URL formats:
|
||||
// - https://codeberg.org/owner/name.git
|
||||
// - git@codeberg.org:owner/name.git
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue