cli/cmd/qa/cmd_review.go

323 lines
8.1 KiB
Go
Raw Normal View History

feat(qa): add review command for PR status (#64) * feat(qa): add qa watch command for CI monitoring (#47) Implements `core qa watch` to monitor GitHub Actions after a push: - Polls workflow runs for a commit until completion - Shows live progress with pass/fail counts - On failure, shows job name, failed step, and link to logs - Exits with appropriate code (0 = passed, 1 = failed) Usage: core qa watch # Watch current repo's HEAD core qa watch --repo X # Watch specific repo core qa watch --timeout 5m # Custom timeout Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on watch command - Add length check before slicing commitSha to prevent panic on short SHAs - Count all non-success conclusions as failures (cancelled, timed_out, etc.) - Use errors.E/Wrap pattern for consistent error handling with operation context Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add context-aware commands and log parsing - Use exec.CommandContext with timeout context for all gh invocations so commands are cancelled when deadline expires - Implement fetchErrorFromLogs using 'gh run view --log-failed' to extract first meaningful error line from failed workflows - Pass context through call chain for proper timeout propagation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on review command - Fix truncate to use runes for UTF-8 safe string slicing - Remove unused user parameter from showMyPRs and showRequestedReviews - Remove unused getCurrentUser function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): remove duplicate i18n block and improve error handling - Remove duplicate cmd.qa block in en_GB.json - Use errors.E consistently for error wrapping - Require --repo flag when not in a git repository Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:56:48 +00:00
// cmd_review.go implements the 'qa review' command for PR review status.
//
// Usage:
// core qa review # Show all PRs needing attention
// core qa review --mine # Show status of your open PRs
// core qa review --requested # Show PRs you need to review
package qa
import (
"context"
"encoding/json"
"fmt"
"os/exec"
"strings"
"time"
"forge.lthn.ai/core/go/pkg/cli"
"forge.lthn.ai/core/go/pkg/i18n"
"forge.lthn.ai/core/go/pkg/log"
feat(qa): add review command for PR status (#64) * feat(qa): add qa watch command for CI monitoring (#47) Implements `core qa watch` to monitor GitHub Actions after a push: - Polls workflow runs for a commit until completion - Shows live progress with pass/fail counts - On failure, shows job name, failed step, and link to logs - Exits with appropriate code (0 = passed, 1 = failed) Usage: core qa watch # Watch current repo's HEAD core qa watch --repo X # Watch specific repo core qa watch --timeout 5m # Custom timeout Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on watch command - Add length check before slicing commitSha to prevent panic on short SHAs - Count all non-success conclusions as failures (cancelled, timed_out, etc.) - Use errors.E/Wrap pattern for consistent error handling with operation context Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add context-aware commands and log parsing - Use exec.CommandContext with timeout context for all gh invocations so commands are cancelled when deadline expires - Implement fetchErrorFromLogs using 'gh run view --log-failed' to extract first meaningful error line from failed workflows - Pass context through call chain for proper timeout propagation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on review command - Fix truncate to use runes for UTF-8 safe string slicing - Remove unused user parameter from showMyPRs and showRequestedReviews - Remove unused getCurrentUser function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): remove duplicate i18n block and improve error handling - Remove duplicate cmd.qa block in en_GB.json - Use errors.E consistently for error wrapping - Require --repo flag when not in a git repository Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:56:48 +00:00
)
// Review command flags
var (
reviewMine bool
reviewRequested bool
reviewRepo string
)
// PullRequest represents a GitHub pull request
type PullRequest struct {
Number int `json:"number"`
Title string `json:"title"`
Author Author `json:"author"`
State string `json:"state"`
IsDraft bool `json:"isDraft"`
Mergeable string `json:"mergeable"`
ReviewDecision string `json:"reviewDecision"`
URL string `json:"url"`
HeadRefName string `json:"headRefName"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
ChangedFiles int `json:"changedFiles"`
StatusChecks *StatusCheckRollup `json:"statusCheckRollup"`
ReviewRequests ReviewRequests `json:"reviewRequests"`
Reviews []Review `json:"reviews"`
}
// Author represents a GitHub user
type Author struct {
Login string `json:"login"`
}
// StatusCheckRollup contains CI check status
type StatusCheckRollup struct {
Contexts []StatusContext `json:"contexts"`
}
// StatusContext represents a single check
type StatusContext struct {
State string `json:"state"`
Conclusion string `json:"conclusion"`
Name string `json:"name"`
}
// ReviewRequests contains pending review requests
type ReviewRequests struct {
Nodes []ReviewRequest `json:"nodes"`
}
// ReviewRequest represents a review request
type ReviewRequest struct {
RequestedReviewer Author `json:"requestedReviewer"`
}
// Review represents a PR review
type Review struct {
Author Author `json:"author"`
State string `json:"state"`
}
// addReviewCommand adds the 'review' subcommand to the qa command.
func addReviewCommand(parent *cli.Command) {
reviewCmd := &cli.Command{
Use: "review",
Short: i18n.T("cmd.qa.review.short"),
Long: i18n.T("cmd.qa.review.long"),
RunE: func(cmd *cli.Command, args []string) error {
return runReview()
},
}
reviewCmd.Flags().BoolVarP(&reviewMine, "mine", "m", false, i18n.T("cmd.qa.review.flag.mine"))
reviewCmd.Flags().BoolVarP(&reviewRequested, "requested", "r", false, i18n.T("cmd.qa.review.flag.requested"))
reviewCmd.Flags().StringVar(&reviewRepo, "repo", "", i18n.T("cmd.qa.review.flag.repo"))
parent.AddCommand(reviewCmd)
}
func runReview() error {
// Check gh is available
if _, err := exec.LookPath("gh"); err != nil {
feat(errors): Unify errors and logging (#180) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * feat(io): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(errors): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * feat(io): extend Medium interface with Delete, Rename, List, Stat operations Adds the following methods to the Medium interface: - Delete(path) - remove a file or empty directory - DeleteAll(path) - recursively remove a file or directory - Rename(old, new) - move/rename a file or directory - List(path) - list directory entries (returns []fs.DirEntry) - Stat(path) - get file information (returns fs.FileInfo) - Exists(path) - check if path exists - IsDir(path) - check if path is a directory Implements these methods in both local.Medium (using os package) and MockMedium (in-memory for testing). Includes FileInfo and DirEntry types for mock implementations. This enables migration of direct os.* calls to the Medium abstraction for consistent path validation and testability. Refs #101 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * chore(io): migrate internal/cmd/docs and internal/cmd/dev to Medium - internal/cmd/docs: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.RemoveAll with io.Local equivalents - internal/cmd/dev: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.ReadDir with io.Local equivalents - Fix local.Medium to allow absolute paths when root is "/" for full filesystem access (io.Local use case) Refs #113, #114 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): migrate internal/cmd/setup to Medium abstraction Migrated all direct os.* filesystem calls to use io.Local: - cmd_repo.go: os.MkdirAll -> io.Local.EnsureDir, os.WriteFile -> io.Local.Write, os.Stat -> io.Local.IsFile - cmd_bootstrap.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.IsDir/Exists, os.ReadDir -> io.Local.List - cmd_registry.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.Exists - cmd_ci.go: os.ReadFile -> io.Local.Read - github_config.go: os.ReadFile -> io.Local.Read, os.Stat -> io.Local.Exists Refs #116 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): add error creation and log-and-return helpers Implements issues #129 and #132: - Add Err struct with Op, Msg, Err, Code fields for structured errors - Add E(), Wrap(), WrapCode(), NewCode() for error creation - Add Is(), As(), NewError(), Join() as stdlib wrappers - Add Op(), ErrCode(), Message(), Root() for introspection - Add LogError(), LogWarn(), Must() for combined log-and-return Closes #129 Closes #132 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(errors): create deprecation alias pointing to pkg/log Makes pkg/errors a thin compatibility layer that re-exports from pkg/log. All error handling functions now have canonical implementations in pkg/log. Migration guide in package documentation: - errors.Error -> log.Err - errors.E -> log.E - errors.Code -> log.NewCode - errors.New -> log.NewError Fixes behavior consistency: - E(op, msg, nil) now creates an error (for errors without cause) - Wrap(nil, op, msg) returns nil (for conditional wrapping) - WrapCode returns nil only when both err is nil AND code is empty Closes #128 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(log): migrate pkg/errors imports to pkg/log Migrates all internal packages from pkg/errors to pkg/log: - internal/cmd/monitor - internal/cmd/qa - internal/cmd/dev - pkg/agentic Closes #130 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): address Copilot review feedback - Fix MockMedium.Rename: collect keys before mutating maps during iteration - Fix .git checks to use Exists instead of List (handles worktrees/submodules) - Fix cmd_sync.go: use DeleteAll for recursive directory removal Files updated: - pkg/io/io.go: safe map iteration in Rename - internal/cmd/setup/cmd_bootstrap.go: Exists for .git checks - internal/cmd/setup/cmd_registry.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_install.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_manage.go: Exists for .git checks - internal/cmd/docs/cmd_sync.go: DeleteAll for recursive delete Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting across migrated files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): remove duplicate method declarations Clean up the client.go file that had duplicate method declarations from a bad cherry-pick merge. Now has 127 lines of simple, clean code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(io): fix traversal test to match sanitization behavior The simplified path() sanitizes .. to . without returning errors. Update test to verify sanitization works correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 06:48:40 +00:00
return log.E("qa.review", i18n.T("error.gh_not_found"), nil)
feat(qa): add review command for PR status (#64) * feat(qa): add qa watch command for CI monitoring (#47) Implements `core qa watch` to monitor GitHub Actions after a push: - Polls workflow runs for a commit until completion - Shows live progress with pass/fail counts - On failure, shows job name, failed step, and link to logs - Exits with appropriate code (0 = passed, 1 = failed) Usage: core qa watch # Watch current repo's HEAD core qa watch --repo X # Watch specific repo core qa watch --timeout 5m # Custom timeout Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on watch command - Add length check before slicing commitSha to prevent panic on short SHAs - Count all non-success conclusions as failures (cancelled, timed_out, etc.) - Use errors.E/Wrap pattern for consistent error handling with operation context Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add context-aware commands and log parsing - Use exec.CommandContext with timeout context for all gh invocations so commands are cancelled when deadline expires - Implement fetchErrorFromLogs using 'gh run view --log-failed' to extract first meaningful error line from failed workflows - Pass context through call chain for proper timeout propagation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on review command - Fix truncate to use runes for UTF-8 safe string slicing - Remove unused user parameter from showMyPRs and showRequestedReviews - Remove unused getCurrentUser function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): remove duplicate i18n block and improve error handling - Remove duplicate cmd.qa block in en_GB.json - Use errors.E consistently for error wrapping - Require --repo flag when not in a git repository Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:56:48 +00:00
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Determine repo
repoFullName := reviewRepo
if repoFullName == "" {
var err error
repoFullName, err = detectRepoFromGit()
if err != nil {
feat(errors): Unify errors and logging (#180) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * feat(io): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(errors): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * feat(io): extend Medium interface with Delete, Rename, List, Stat operations Adds the following methods to the Medium interface: - Delete(path) - remove a file or empty directory - DeleteAll(path) - recursively remove a file or directory - Rename(old, new) - move/rename a file or directory - List(path) - list directory entries (returns []fs.DirEntry) - Stat(path) - get file information (returns fs.FileInfo) - Exists(path) - check if path exists - IsDir(path) - check if path is a directory Implements these methods in both local.Medium (using os package) and MockMedium (in-memory for testing). Includes FileInfo and DirEntry types for mock implementations. This enables migration of direct os.* calls to the Medium abstraction for consistent path validation and testability. Refs #101 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * chore(io): migrate internal/cmd/docs and internal/cmd/dev to Medium - internal/cmd/docs: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.RemoveAll with io.Local equivalents - internal/cmd/dev: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.ReadDir with io.Local equivalents - Fix local.Medium to allow absolute paths when root is "/" for full filesystem access (io.Local use case) Refs #113, #114 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): migrate internal/cmd/setup to Medium abstraction Migrated all direct os.* filesystem calls to use io.Local: - cmd_repo.go: os.MkdirAll -> io.Local.EnsureDir, os.WriteFile -> io.Local.Write, os.Stat -> io.Local.IsFile - cmd_bootstrap.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.IsDir/Exists, os.ReadDir -> io.Local.List - cmd_registry.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.Exists - cmd_ci.go: os.ReadFile -> io.Local.Read - github_config.go: os.ReadFile -> io.Local.Read, os.Stat -> io.Local.Exists Refs #116 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): add error creation and log-and-return helpers Implements issues #129 and #132: - Add Err struct with Op, Msg, Err, Code fields for structured errors - Add E(), Wrap(), WrapCode(), NewCode() for error creation - Add Is(), As(), NewError(), Join() as stdlib wrappers - Add Op(), ErrCode(), Message(), Root() for introspection - Add LogError(), LogWarn(), Must() for combined log-and-return Closes #129 Closes #132 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(errors): create deprecation alias pointing to pkg/log Makes pkg/errors a thin compatibility layer that re-exports from pkg/log. All error handling functions now have canonical implementations in pkg/log. Migration guide in package documentation: - errors.Error -> log.Err - errors.E -> log.E - errors.Code -> log.NewCode - errors.New -> log.NewError Fixes behavior consistency: - E(op, msg, nil) now creates an error (for errors without cause) - Wrap(nil, op, msg) returns nil (for conditional wrapping) - WrapCode returns nil only when both err is nil AND code is empty Closes #128 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(log): migrate pkg/errors imports to pkg/log Migrates all internal packages from pkg/errors to pkg/log: - internal/cmd/monitor - internal/cmd/qa - internal/cmd/dev - pkg/agentic Closes #130 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): address Copilot review feedback - Fix MockMedium.Rename: collect keys before mutating maps during iteration - Fix .git checks to use Exists instead of List (handles worktrees/submodules) - Fix cmd_sync.go: use DeleteAll for recursive directory removal Files updated: - pkg/io/io.go: safe map iteration in Rename - internal/cmd/setup/cmd_bootstrap.go: Exists for .git checks - internal/cmd/setup/cmd_registry.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_install.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_manage.go: Exists for .git checks - internal/cmd/docs/cmd_sync.go: DeleteAll for recursive delete Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting across migrated files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): remove duplicate method declarations Clean up the client.go file that had duplicate method declarations from a bad cherry-pick merge. Now has 127 lines of simple, clean code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(io): fix traversal test to match sanitization behavior The simplified path() sanitizes .. to . without returning errors. Update test to verify sanitization works correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 06:48:40 +00:00
return log.E("qa.review", i18n.T("cmd.qa.review.error.no_repo"), nil)
feat(qa): add review command for PR status (#64) * feat(qa): add qa watch command for CI monitoring (#47) Implements `core qa watch` to monitor GitHub Actions after a push: - Polls workflow runs for a commit until completion - Shows live progress with pass/fail counts - On failure, shows job name, failed step, and link to logs - Exits with appropriate code (0 = passed, 1 = failed) Usage: core qa watch # Watch current repo's HEAD core qa watch --repo X # Watch specific repo core qa watch --timeout 5m # Custom timeout Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on watch command - Add length check before slicing commitSha to prevent panic on short SHAs - Count all non-success conclusions as failures (cancelled, timed_out, etc.) - Use errors.E/Wrap pattern for consistent error handling with operation context Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add context-aware commands and log parsing - Use exec.CommandContext with timeout context for all gh invocations so commands are cancelled when deadline expires - Implement fetchErrorFromLogs using 'gh run view --log-failed' to extract first meaningful error line from failed workflows - Pass context through call chain for proper timeout propagation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on review command - Fix truncate to use runes for UTF-8 safe string slicing - Remove unused user parameter from showMyPRs and showRequestedReviews - Remove unused getCurrentUser function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): remove duplicate i18n block and improve error handling - Remove duplicate cmd.qa block in en_GB.json - Use errors.E consistently for error wrapping - Require --repo flag when not in a git repository Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:56:48 +00:00
}
}
// Default: show both mine and requested if neither flag is set
showMine := reviewMine || (!reviewMine && !reviewRequested)
showRequested := reviewRequested || (!reviewMine && !reviewRequested)
if showMine {
if err := showMyPRs(ctx, repoFullName); err != nil {
return err
}
}
if showRequested {
if showMine {
cli.Blank()
}
if err := showRequestedReviews(ctx, repoFullName); err != nil {
return err
}
}
return nil
}
// showMyPRs shows the user's open PRs with status
func showMyPRs(ctx context.Context, repo string) error {
prs, err := fetchPRs(ctx, repo, "author:@me")
if err != nil {
feat(errors): Unify errors and logging (#180) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * feat(io): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(errors): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * feat(io): extend Medium interface with Delete, Rename, List, Stat operations Adds the following methods to the Medium interface: - Delete(path) - remove a file or empty directory - DeleteAll(path) - recursively remove a file or directory - Rename(old, new) - move/rename a file or directory - List(path) - list directory entries (returns []fs.DirEntry) - Stat(path) - get file information (returns fs.FileInfo) - Exists(path) - check if path exists - IsDir(path) - check if path is a directory Implements these methods in both local.Medium (using os package) and MockMedium (in-memory for testing). Includes FileInfo and DirEntry types for mock implementations. This enables migration of direct os.* calls to the Medium abstraction for consistent path validation and testability. Refs #101 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * chore(io): migrate internal/cmd/docs and internal/cmd/dev to Medium - internal/cmd/docs: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.RemoveAll with io.Local equivalents - internal/cmd/dev: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.ReadDir with io.Local equivalents - Fix local.Medium to allow absolute paths when root is "/" for full filesystem access (io.Local use case) Refs #113, #114 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): migrate internal/cmd/setup to Medium abstraction Migrated all direct os.* filesystem calls to use io.Local: - cmd_repo.go: os.MkdirAll -> io.Local.EnsureDir, os.WriteFile -> io.Local.Write, os.Stat -> io.Local.IsFile - cmd_bootstrap.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.IsDir/Exists, os.ReadDir -> io.Local.List - cmd_registry.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.Exists - cmd_ci.go: os.ReadFile -> io.Local.Read - github_config.go: os.ReadFile -> io.Local.Read, os.Stat -> io.Local.Exists Refs #116 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): add error creation and log-and-return helpers Implements issues #129 and #132: - Add Err struct with Op, Msg, Err, Code fields for structured errors - Add E(), Wrap(), WrapCode(), NewCode() for error creation - Add Is(), As(), NewError(), Join() as stdlib wrappers - Add Op(), ErrCode(), Message(), Root() for introspection - Add LogError(), LogWarn(), Must() for combined log-and-return Closes #129 Closes #132 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(errors): create deprecation alias pointing to pkg/log Makes pkg/errors a thin compatibility layer that re-exports from pkg/log. All error handling functions now have canonical implementations in pkg/log. Migration guide in package documentation: - errors.Error -> log.Err - errors.E -> log.E - errors.Code -> log.NewCode - errors.New -> log.NewError Fixes behavior consistency: - E(op, msg, nil) now creates an error (for errors without cause) - Wrap(nil, op, msg) returns nil (for conditional wrapping) - WrapCode returns nil only when both err is nil AND code is empty Closes #128 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(log): migrate pkg/errors imports to pkg/log Migrates all internal packages from pkg/errors to pkg/log: - internal/cmd/monitor - internal/cmd/qa - internal/cmd/dev - pkg/agentic Closes #130 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): address Copilot review feedback - Fix MockMedium.Rename: collect keys before mutating maps during iteration - Fix .git checks to use Exists instead of List (handles worktrees/submodules) - Fix cmd_sync.go: use DeleteAll for recursive directory removal Files updated: - pkg/io/io.go: safe map iteration in Rename - internal/cmd/setup/cmd_bootstrap.go: Exists for .git checks - internal/cmd/setup/cmd_registry.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_install.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_manage.go: Exists for .git checks - internal/cmd/docs/cmd_sync.go: DeleteAll for recursive delete Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting across migrated files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): remove duplicate method declarations Clean up the client.go file that had duplicate method declarations from a bad cherry-pick merge. Now has 127 lines of simple, clean code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(io): fix traversal test to match sanitization behavior The simplified path() sanitizes .. to . without returning errors. Update test to verify sanitization works correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 06:48:40 +00:00
return log.E("qa.review", "failed to fetch your PRs", err)
feat(qa): add review command for PR status (#64) * feat(qa): add qa watch command for CI monitoring (#47) Implements `core qa watch` to monitor GitHub Actions after a push: - Polls workflow runs for a commit until completion - Shows live progress with pass/fail counts - On failure, shows job name, failed step, and link to logs - Exits with appropriate code (0 = passed, 1 = failed) Usage: core qa watch # Watch current repo's HEAD core qa watch --repo X # Watch specific repo core qa watch --timeout 5m # Custom timeout Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on watch command - Add length check before slicing commitSha to prevent panic on short SHAs - Count all non-success conclusions as failures (cancelled, timed_out, etc.) - Use errors.E/Wrap pattern for consistent error handling with operation context Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add context-aware commands and log parsing - Use exec.CommandContext with timeout context for all gh invocations so commands are cancelled when deadline expires - Implement fetchErrorFromLogs using 'gh run view --log-failed' to extract first meaningful error line from failed workflows - Pass context through call chain for proper timeout propagation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on review command - Fix truncate to use runes for UTF-8 safe string slicing - Remove unused user parameter from showMyPRs and showRequestedReviews - Remove unused getCurrentUser function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): remove duplicate i18n block and improve error handling - Remove duplicate cmd.qa block in en_GB.json - Use errors.E consistently for error wrapping - Require --repo flag when not in a git repository Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:56:48 +00:00
}
if len(prs) == 0 {
cli.Print("%s\n", dimStyle.Render(i18n.T("cmd.qa.review.no_prs")))
return nil
}
cli.Print("%s (%d):\n", i18n.T("cmd.qa.review.your_prs"), len(prs))
for _, pr := range prs {
printPRStatus(pr)
}
return nil
}
// showRequestedReviews shows PRs where user's review is requested
func showRequestedReviews(ctx context.Context, repo string) error {
prs, err := fetchPRs(ctx, repo, "review-requested:@me")
if err != nil {
feat(errors): Unify errors and logging (#180) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * feat(io): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(errors): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): batch implementation placeholder Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * feat(io): extend Medium interface with Delete, Rename, List, Stat operations Adds the following methods to the Medium interface: - Delete(path) - remove a file or empty directory - DeleteAll(path) - recursively remove a file or directory - Rename(old, new) - move/rename a file or directory - List(path) - list directory entries (returns []fs.DirEntry) - Stat(path) - get file information (returns fs.FileInfo) - Exists(path) - check if path exists - IsDir(path) - check if path is a directory Implements these methods in both local.Medium (using os package) and MockMedium (in-memory for testing). Includes FileInfo and DirEntry types for mock implementations. This enables migration of direct os.* calls to the Medium abstraction for consistent path validation and testability. Refs #101 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * chore(io): migrate internal/cmd/docs and internal/cmd/dev to Medium - internal/cmd/docs: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.RemoveAll with io.Local equivalents - internal/cmd/dev: Replace os.Stat, os.ReadFile, os.WriteFile, os.MkdirAll, os.ReadDir with io.Local equivalents - Fix local.Medium to allow absolute paths when root is "/" for full filesystem access (io.Local use case) Refs #113, #114 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(io): migrate internal/cmd/setup to Medium abstraction Migrated all direct os.* filesystem calls to use io.Local: - cmd_repo.go: os.MkdirAll -> io.Local.EnsureDir, os.WriteFile -> io.Local.Write, os.Stat -> io.Local.IsFile - cmd_bootstrap.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.IsDir/Exists, os.ReadDir -> io.Local.List - cmd_registry.go: os.MkdirAll -> io.Local.EnsureDir, os.Stat -> io.Local.Exists - cmd_ci.go: os.ReadFile -> io.Local.Read - github_config.go: os.ReadFile -> io.Local.Read, os.Stat -> io.Local.Exists Refs #116 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(log): add error creation and log-and-return helpers Implements issues #129 and #132: - Add Err struct with Op, Msg, Err, Code fields for structured errors - Add E(), Wrap(), WrapCode(), NewCode() for error creation - Add Is(), As(), NewError(), Join() as stdlib wrappers - Add Op(), ErrCode(), Message(), Root() for introspection - Add LogError(), LogWarn(), Must() for combined log-and-return Closes #129 Closes #132 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(errors): create deprecation alias pointing to pkg/log Makes pkg/errors a thin compatibility layer that re-exports from pkg/log. All error handling functions now have canonical implementations in pkg/log. Migration guide in package documentation: - errors.Error -> log.Err - errors.E -> log.E - errors.Code -> log.NewCode - errors.New -> log.NewError Fixes behavior consistency: - E(op, msg, nil) now creates an error (for errors without cause) - Wrap(nil, op, msg) returns nil (for conditional wrapping) - WrapCode returns nil only when both err is nil AND code is empty Closes #128 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore(log): migrate pkg/errors imports to pkg/log Migrates all internal packages from pkg/errors to pkg/log: - internal/cmd/monitor - internal/cmd/qa - internal/cmd/dev - pkg/agentic Closes #130 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): address Copilot review feedback - Fix MockMedium.Rename: collect keys before mutating maps during iteration - Fix .git checks to use Exists instead of List (handles worktrees/submodules) - Fix cmd_sync.go: use DeleteAll for recursive directory removal Files updated: - pkg/io/io.go: safe map iteration in Rename - internal/cmd/setup/cmd_bootstrap.go: Exists for .git checks - internal/cmd/setup/cmd_registry.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_install.go: Exists for .git checks - internal/cmd/pkgcmd/cmd_manage.go: Exists for .git checks - internal/cmd/docs/cmd_sync.go: DeleteAll for recursive delete Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix formatting across migrated files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(io): remove duplicate method declarations Clean up the client.go file that had duplicate method declarations from a bad cherry-pick merge. Now has 127 lines of simple, clean code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(io): fix traversal test to match sanitization behavior The simplified path() sanitizes .. to . without returning errors. Update test to verify sanitization works correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 06:48:40 +00:00
return log.E("qa.review", "failed to fetch review requests", err)
feat(qa): add review command for PR status (#64) * feat(qa): add qa watch command for CI monitoring (#47) Implements `core qa watch` to monitor GitHub Actions after a push: - Polls workflow runs for a commit until completion - Shows live progress with pass/fail counts - On failure, shows job name, failed step, and link to logs - Exits with appropriate code (0 = passed, 1 = failed) Usage: core qa watch # Watch current repo's HEAD core qa watch --repo X # Watch specific repo core qa watch --timeout 5m # Custom timeout Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on watch command - Add length check before slicing commitSha to prevent panic on short SHAs - Count all non-success conclusions as failures (cancelled, timed_out, etc.) - Use errors.E/Wrap pattern for consistent error handling with operation context Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add context-aware commands and log parsing - Use exec.CommandContext with timeout context for all gh invocations so commands are cancelled when deadline expires - Implement fetchErrorFromLogs using 'gh run view --log-failed' to extract first meaningful error line from failed workflows - Pass context through call chain for proper timeout propagation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(qa): add review command for PR status (#62) Add `core qa review` command to show PR review status with actionable next steps. Answers: "What do I need to do to get my PRs merged?" and "What reviews am I blocking?" Features: - Shows your open PRs with merge status (CI, reviews, conflicts) - Shows PRs where your review is requested - Provides actionable suggestions (rebase, address feedback, etc.) - Flags: --mine, --requested, --repo Closes #62 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): address CodeRabbit feedback on review command - Fix truncate to use runes for UTF-8 safe string slicing - Remove unused user parameter from showMyPRs and showRequestedReviews - Remove unused getCurrentUser function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(qa): remove duplicate i18n block and improve error handling - Remove duplicate cmd.qa block in en_GB.json - Use errors.E consistently for error wrapping - Require --repo flag when not in a git repository Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:56:48 +00:00
}
if len(prs) == 0 {
cli.Print("%s\n", dimStyle.Render(i18n.T("cmd.qa.review.no_reviews")))
return nil
}
cli.Print("%s (%d):\n", i18n.T("cmd.qa.review.review_requested"), len(prs))
for _, pr := range prs {
printPRForReview(pr)
}
return nil
}
// fetchPRs fetches PRs matching the search query
func fetchPRs(ctx context.Context, repo, search string) ([]PullRequest, error) {
args := []string{
"pr", "list",
"--state", "open",
"--search", search,
"--json", "number,title,author,state,isDraft,mergeable,reviewDecision,url,headRefName,createdAt,updatedAt,additions,deletions,changedFiles,statusCheckRollup,reviewRequests,reviews",
}
if repo != "" {
args = append(args, "--repo", repo)
}
cmd := exec.CommandContext(ctx, "gh", args...)
output, err := cmd.Output()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
return nil, fmt.Errorf("%s", strings.TrimSpace(string(exitErr.Stderr)))
}
return nil, err
}
var prs []PullRequest
if err := json.Unmarshal(output, &prs); err != nil {
return nil, err
}
return prs, nil
}
// printPRStatus prints a PR with its merge status
func printPRStatus(pr PullRequest) {
// Determine status icon and color
status, style, action := analyzePRStatus(pr)
cli.Print(" %s #%d %s\n",
style.Render(status),
pr.Number,
truncate(pr.Title, 50))
if action != "" {
cli.Print(" %s %s\n", dimStyle.Render("->"), action)
}
}
// printPRForReview prints a PR that needs review
func printPRForReview(pr PullRequest) {
// Show PR info with stats
stats := fmt.Sprintf("+%d/-%d, %d files",
pr.Additions, pr.Deletions, pr.ChangedFiles)
cli.Print(" %s #%d %s\n",
warningStyle.Render("◯"),
pr.Number,
truncate(pr.Title, 50))
cli.Print(" %s @%s, %s\n",
dimStyle.Render("->"),
pr.Author.Login,
stats)
cli.Print(" %s gh pr checkout %d\n",
dimStyle.Render("->"),
pr.Number)
}
// analyzePRStatus determines the status, style, and action for a PR
func analyzePRStatus(pr PullRequest) (status string, style *cli.AnsiStyle, action string) {
// Check if draft
if pr.IsDraft {
return "◯", dimStyle, "Draft - convert to ready when done"
}
// Check CI status
ciPassed := true
ciFailed := false
ciPending := false
var failedCheck string
if pr.StatusChecks != nil {
for _, check := range pr.StatusChecks.Contexts {
switch check.Conclusion {
case "FAILURE", "failure":
ciFailed = true
ciPassed = false
if failedCheck == "" {
failedCheck = check.Name
}
case "PENDING", "pending", "":
if check.State == "PENDING" || check.State == "" {
ciPending = true
ciPassed = false
}
}
}
}
// Check review status
approved := pr.ReviewDecision == "APPROVED"
changesRequested := pr.ReviewDecision == "CHANGES_REQUESTED"
// Check mergeable status
hasConflicts := pr.Mergeable == "CONFLICTING"
// Determine overall status
if hasConflicts {
return "✗", errorStyle, "Needs rebase - has merge conflicts"
}
if ciFailed {
return "✗", errorStyle, fmt.Sprintf("CI failed: %s", failedCheck)
}
if changesRequested {
return "✗", warningStyle, "Changes requested - address review feedback"
}
if ciPending {
return "◯", warningStyle, "CI running..."
}
if !approved && pr.ReviewDecision != "" {
return "◯", warningStyle, "Awaiting review"
}
if approved && ciPassed {
return "✓", successStyle, "Ready to merge"
}
return "◯", dimStyle, ""
}
// truncate shortens a string to max length (rune-safe for UTF-8)
func truncate(s string, max int) string {
runes := []rune(s)
if len(runes) <= max {
return s
}
return string(runes[:max-3]) + "..."
}