refactor(cli): restructure cmd packages into subdirectories
- Move CLI commands into subdirectories matching command hierarchy:
dev/, go/, php/, build/, ci/, sdk/, pkg/, vm/, docs/, setup/, doctor/, test/, ai/
- Create shared/ package for common styles and utilities
- Add new `core ai` root command with claude subcommand
- Update package declarations and imports across all files
- Create commands.go entry points for each package
- Remove GUI-related files (moved to core-gui repo)
This makes the filesystem structure match the CLI command structure,
improving context capture and code organization.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:02:43 +00:00
|
|
|
package dev
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"sort"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-01-30 10:32:05 +00:00
|
|
|
"github.com/host-uk/core/pkg/cli"
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
"github.com/host-uk/core/pkg/i18n"
|
refactor(cli): restructure cmd packages into subdirectories
- Move CLI commands into subdirectories matching command hierarchy:
dev/, go/, php/, build/, ci/, sdk/, pkg/, vm/, docs/, setup/, doctor/, test/, ai/
- Create shared/ package for common styles and utilities
- Add new `core ai` root command with claude subcommand
- Update package declarations and imports across all files
- Create commands.go entry points for each package
- Remove GUI-related files (moved to core-gui repo)
This makes the filesystem structure match the CLI command structure,
improving context capture and code organization.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:02:43 +00:00
|
|
|
"github.com/host-uk/core/pkg/repos"
|
2026-01-30 00:47:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
2026-01-27 21:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
2026-01-30 01:28:39 +00:00
|
|
|
// PR-specific styles (aliases to shared)
|
2026-01-27 21:08:51 +00:00
|
|
|
var (
|
2026-01-30 10:32:05 +00:00
|
|
|
prNumberStyle = cli.PrNumberStyle
|
|
|
|
|
prTitleStyle = cli.ValueStyle
|
|
|
|
|
prAuthorStyle = cli.InfoStyle
|
|
|
|
|
prApprovedStyle = cli.SuccessStyle
|
|
|
|
|
prChangesStyle = cli.WarningStyle
|
|
|
|
|
prPendingStyle = cli.DimStyle
|
|
|
|
|
prDraftStyle = cli.DimStyle
|
2026-01-27 21:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GitHubPR represents a GitHub pull request.
|
|
|
|
|
type GitHubPR struct {
|
|
|
|
|
Number int `json:"number"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
State string `json:"state"`
|
|
|
|
|
IsDraft bool `json:"isDraft"`
|
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
|
Author struct {
|
|
|
|
|
Login string `json:"login"`
|
|
|
|
|
} `json:"author"`
|
|
|
|
|
ReviewDecision string `json:"reviewDecision"`
|
|
|
|
|
Reviews struct {
|
|
|
|
|
Nodes []struct {
|
|
|
|
|
State string `json:"state"`
|
|
|
|
|
Author struct {
|
|
|
|
|
Login string `json:"login"`
|
|
|
|
|
} `json:"author"`
|
|
|
|
|
} `json:"nodes"`
|
|
|
|
|
} `json:"reviews"`
|
|
|
|
|
URL string `json:"url"`
|
|
|
|
|
|
|
|
|
|
// Added by us
|
|
|
|
|
RepoName string `json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Reviews command flags
|
|
|
|
|
var (
|
|
|
|
|
reviewsRegistryPath string
|
|
|
|
|
reviewsAuthor string
|
|
|
|
|
reviewsShowAll bool
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-30 00:22:47 +00:00
|
|
|
// addReviewsCommand adds the 'reviews' command to the given parent command.
|
2026-01-30 00:47:54 +00:00
|
|
|
func addReviewsCommand(parent *cobra.Command) {
|
|
|
|
|
reviewsCmd := &cobra.Command{
|
|
|
|
|
Use: "reviews",
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
Short: i18n.T("cmd.dev.reviews.short"),
|
|
|
|
|
Long: i18n.T("cmd.dev.reviews.long"),
|
2026-01-30 00:47:54 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return runReviews(reviewsRegistryPath, reviewsAuthor, reviewsShowAll)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
reviewsCmd.Flags().StringVar(&reviewsRegistryPath, "registry", "", i18n.T("common.flag.registry"))
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
reviewsCmd.Flags().StringVar(&reviewsAuthor, "author", "", i18n.T("cmd.dev.reviews.flag.author"))
|
|
|
|
|
reviewsCmd.Flags().BoolVar(&reviewsShowAll, "all", false, i18n.T("cmd.dev.reviews.flag.all"))
|
2026-01-30 00:47:54 +00:00
|
|
|
|
|
|
|
|
parent.AddCommand(reviewsCmd)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runReviews(registryPath string, author string, showAll bool) error {
|
|
|
|
|
// Check gh is available
|
|
|
|
|
if _, err := exec.LookPath("gh"); err != nil {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
return fmt.Errorf(i18n.T("error.gh_not_found"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find or use provided registry, fall back to directory scan
|
|
|
|
|
var reg *repos.Registry
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
if registryPath != "" {
|
|
|
|
|
reg, err = repos.LoadRegistry(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to load registry: %w", err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
registryPath, err = repos.FindRegistry()
|
|
|
|
|
if err == nil {
|
|
|
|
|
reg, err = repos.LoadRegistry(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to load registry: %w", err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback: scan current directory
|
|
|
|
|
cwd, _ := os.Getwd()
|
|
|
|
|
reg, err = repos.ScanDirectory(cwd)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to scan directory: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch PRs sequentially (avoid GitHub rate limits)
|
|
|
|
|
var allPRs []GitHubPR
|
|
|
|
|
var fetchErrors []error
|
|
|
|
|
|
|
|
|
|
repoList := reg.List()
|
|
|
|
|
for i, repo := range repoList {
|
|
|
|
|
repoFullName := fmt.Sprintf("%s/%s", reg.Org, repo.Name)
|
2026-01-30 15:05:24 +00:00
|
|
|
fmt.Printf("\033[2K\r%s %d/%d %s", dimStyle.Render(i18n.T("i18n.progress.fetch")), i+1, len(repoList), repo.Name)
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
prs, err := fetchPRs(repoFullName, repo.Name, author)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fetchErrors = append(fetchErrors, fmt.Errorf("%s: %w", repo.Name, err))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, pr := range prs {
|
|
|
|
|
// Filter drafts unless --all
|
|
|
|
|
if !showAll && pr.IsDraft {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
allPRs = append(allPRs, pr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fmt.Print("\033[2K\r") // Clear progress line
|
|
|
|
|
|
|
|
|
|
// Sort: pending review first, then by date
|
|
|
|
|
sort.Slice(allPRs, func(i, j int) bool {
|
|
|
|
|
// Pending reviews come first
|
|
|
|
|
iPending := allPRs[i].ReviewDecision == "" || allPRs[i].ReviewDecision == "REVIEW_REQUIRED"
|
|
|
|
|
jPending := allPRs[j].ReviewDecision == "" || allPRs[j].ReviewDecision == "REVIEW_REQUIRED"
|
|
|
|
|
if iPending != jPending {
|
|
|
|
|
return iPending
|
|
|
|
|
}
|
|
|
|
|
return allPRs[i].CreatedAt.After(allPRs[j].CreatedAt)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Print PRs
|
|
|
|
|
if len(allPRs) == 0 {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Println(i18n.T("cmd.dev.reviews.no_prs"))
|
2026-01-27 21:08:51 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Count by status
|
|
|
|
|
var pending, approved, changesRequested int
|
|
|
|
|
for _, pr := range allPRs {
|
|
|
|
|
switch pr.ReviewDecision {
|
|
|
|
|
case "APPROVED":
|
|
|
|
|
approved++
|
|
|
|
|
case "CHANGES_REQUESTED":
|
|
|
|
|
changesRequested++
|
|
|
|
|
default:
|
|
|
|
|
pending++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println()
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf("%s", i18n.T("cmd.dev.reviews.open_prs", map[string]interface{}{"Count": len(allPRs)}))
|
2026-01-27 21:08:51 +00:00
|
|
|
if pending > 0 {
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf(" * %s", prPendingStyle.Render(i18n.T("common.count.pending", map[string]interface{}{"Count": pending})))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
if approved > 0 {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf(" * %s", prApprovedStyle.Render(i18n.T("cmd.dev.reviews.approved", map[string]interface{}{"Count": approved})))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
if changesRequested > 0 {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf(" * %s", prChangesStyle.Render(i18n.T("cmd.dev.reviews.changes_requested", map[string]interface{}{"Count": changesRequested})))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
|
|
for _, pr := range allPRs {
|
|
|
|
|
printPR(pr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print any errors
|
|
|
|
|
if len(fetchErrors) > 0 {
|
|
|
|
|
fmt.Println()
|
|
|
|
|
for _, err := range fetchErrors {
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf("%s %s\n", errorStyle.Render(i18n.T("common.label.error")), err)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fetchPRs(repoFullName, repoName string, author string) ([]GitHubPR, error) {
|
|
|
|
|
args := []string{
|
|
|
|
|
"pr", "list",
|
|
|
|
|
"--repo", repoFullName,
|
|
|
|
|
"--state", "open",
|
|
|
|
|
"--json", "number,title,state,isDraft,createdAt,author,reviewDecision,reviews,url",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if author != "" {
|
|
|
|
|
args = append(args, "--author", author)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command("gh", args...)
|
|
|
|
|
output, err := cmd.Output()
|
|
|
|
|
if err != nil {
|
|
|
|
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
|
|
|
|
stderr := string(exitErr.Stderr)
|
|
|
|
|
if strings.Contains(stderr, "no pull requests") || strings.Contains(stderr, "Could not resolve") {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
return nil, fmt.Errorf("%s", stderr)
|
|
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var prs []GitHubPR
|
|
|
|
|
if err := json.Unmarshal(output, &prs); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tag with repo name
|
|
|
|
|
for i := range prs {
|
|
|
|
|
prs[i].RepoName = repoName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return prs, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func printPR(pr GitHubPR) {
|
|
|
|
|
// #12 [core-php] Webhook validation
|
|
|
|
|
num := prNumberStyle.Render(fmt.Sprintf("#%d", pr.Number))
|
|
|
|
|
repo := issueRepoStyle.Render(fmt.Sprintf("[%s]", pr.RepoName))
|
2026-01-30 10:32:05 +00:00
|
|
|
title := prTitleStyle.Render(cli.Truncate(pr.Title, 50))
|
2026-01-27 21:08:51 +00:00
|
|
|
author := prAuthorStyle.Render("@" + pr.Author.Login)
|
|
|
|
|
|
|
|
|
|
// Review status
|
|
|
|
|
var status string
|
|
|
|
|
switch pr.ReviewDecision {
|
|
|
|
|
case "APPROVED":
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
status = prApprovedStyle.Render(i18n.T("cmd.dev.reviews.status_approved"))
|
2026-01-27 21:08:51 +00:00
|
|
|
case "CHANGES_REQUESTED":
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
status = prChangesStyle.Render(i18n.T("cmd.dev.reviews.status_changes"))
|
2026-01-27 21:08:51 +00:00
|
|
|
default:
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
status = prPendingStyle.Render(i18n.T("cmd.dev.reviews.status_pending"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draft indicator
|
|
|
|
|
draft := ""
|
|
|
|
|
if pr.IsDraft {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
draft = prDraftStyle.Render(" " + i18n.T("cmd.dev.reviews.draft"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:32:05 +00:00
|
|
|
age := cli.FormatAge(pr.CreatedAt)
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
fmt.Printf(" %s %s %s%s %s %s %s\n", num, repo, title, draft, author, status, issueAgeStyle.Render(age))
|
|
|
|
|
}
|