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:
sid 2026-03-23 11:42:44 -06:00
parent 7c0dcc8696
commit 113505de95
29 changed files with 3131 additions and 542 deletions

View file

@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
"strconv"
"code.gitea.io/sdk/gitea"
"forgejo.zerova.net/sid/fgj-sid/internal/api"
@ -57,7 +56,7 @@ func init() {
prCommentCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
prCommentCmd.Flags().StringP("body", "b", "", "Comment body")
prCommentCmd.Flags().String("body-file", "", "Read body from file (use \"-\" for stdin)")
prCommentCmd.Flags().Bool("json", false, "Output created comment as JSON")
addJSONFlags(prCommentCmd, "Output created comment as JSON")
prReviewCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
prReviewCmd.Flags().BoolP("approve", "a", false, "Approve the pull request")
@ -65,7 +64,7 @@ func init() {
prReviewCmd.Flags().BoolP("comment", "c", false, "Submit as a review comment")
prReviewCmd.Flags().StringP("body", "b", "", "Review body/message")
prReviewCmd.Flags().String("body-file", "", "Read body from file (use \"-\" for stdin)")
prReviewCmd.Flags().Bool("json", false, "Output created review as JSON")
addJSONFlags(prReviewCmd, "Output created review as JSON")
}
// readBody resolves the body text from --body and --body-file flags.
@ -98,7 +97,7 @@ func readBody(cmd *cobra.Command) (string, error) {
func runPRComment(cmd *cobra.Command, args []string) error {
repo, _ := cmd.Flags().GetString("repo")
prNumber, err := strconv.ParseInt(args[0], 10, 64)
prNumber, err := parseIssueArg(args[0])
if err != nil {
return fmt.Errorf("invalid pull request number: %w", err)
}
@ -127,19 +126,22 @@ func runPRComment(cmd *cobra.Command, args []string) error {
return err
}
ios.StartSpinner("Adding comment...")
comment, _, err := client.CreateIssueComment(owner, name, prNumber, gitea.CreateIssueCommentOption{
Body: body,
})
ios.StopSpinner()
if err != nil {
return fmt.Errorf("failed to create comment: %w", err)
}
if jsonOutput, _ := cmd.Flags().GetBool("json"); jsonOutput {
return writeJSON(comment)
if wantJSON(cmd) {
return outputJSON(cmd, comment)
}
fmt.Printf("Comment added to PR #%d\n", prNumber)
fmt.Printf("View at: %s\n", comment.HTMLURL)
cs := ios.ColorScheme()
fmt.Fprintf(ios.Out, "%s Comment added to PR #%d\n", cs.SuccessIcon(), prNumber)
fmt.Fprintf(ios.Out, "View at: %s\n", comment.HTMLURL)
return nil
}
@ -150,7 +152,7 @@ func runPRReview(cmd *cobra.Command, args []string) error {
requestChanges, _ := cmd.Flags().GetBool("request-changes")
commentReview, _ := cmd.Flags().GetBool("comment")
prNumber, err := strconv.ParseInt(args[0], 10, 64)
prNumber, err := parseIssueArg(args[0])
if err != nil {
return fmt.Errorf("invalid pull request number: %w", err)
}
@ -208,21 +210,24 @@ func runPRReview(cmd *cobra.Command, args []string) error {
action = "reviewed with comment"
}
ios.StartSpinner("Submitting review...")
review, _, err := client.CreatePullReview(owner, name, prNumber, gitea.CreatePullReviewOptions{
State: state,
Body: body,
})
ios.StopSpinner()
if err != nil {
return fmt.Errorf("failed to create review: %w", err)
}
if jsonOutput, _ := cmd.Flags().GetBool("json"); jsonOutput {
return writeJSON(review)
if wantJSON(cmd) {
return outputJSON(cmd, review)
}
fmt.Printf("PR #%d %s\n", prNumber, action)
cs := ios.ColorScheme()
fmt.Fprintf(ios.Out, "%s PR #%d %s\n", cs.SuccessIcon(), prNumber, action)
if review.HTMLURL != "" {
fmt.Printf("View at: %s\n", review.HTMLURL)
fmt.Fprintf(ios.Out, "View at: %s\n", review.HTMLURL)
}
return nil