refactor(output): share the JSON, created-resource and batch tails

Mutations end with a.jsonResult or a.created instead of hand-rolled
--json branches, the two identical jsonResult/writeMutationJSON helpers
become one, and writeBatchJSON checks --json itself so batch commands
share one tail.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 10:43:46 +02:00
1 parent 27e39ec4be
commit 6b204a34c0
32 files changed
+87 -217

No files matched your search

+4 -10
View File
@@ -268,13 +268,10 @@ func ownReview(pull services.Pull, t target, state string) error {
// reportReview reports a submitted review, then prints its URL, or the review as JSON.
func (a *application) reportReview(cmd *cobra.Command, t target, pull services.Pull, item services.Review) error {
a.done(cmd, "%s pull request %s", reviewVerbs[item.State], refLabel(t.Repo, pull.Number, pull.Title))
switch {
case a.options.json != "":
return a.writeJSON(cmd, item)
case item.URL != "":
return a.printURL(cmd, item.URL)
if a.options.json == "" && item.URL == "" {
return nil
}
return nil
return a.created(cmd, item, item.URL)
}
// readInlineComments reads the inline comments of --comments-file, a JSON array.
@@ -625,10 +622,7 @@ func (a *application) pullReviewReplyCommand() *cobra.Command {
return err
}
a.done(cmd, "Replied to review comment %d on %s#%d", id, t.Repo, n)
if a.options.json != "" {
return a.writeJSON(cmd, item)
}
return a.printURL(cmd, item.URL)
return a.created(cmd, item, item.URL)
}}
cmd.Flags().StringVarP(&body, "body", "b", "", "Reply body")
cmd.Flags().StringVarP(&file, "body-file", "F", "", "Read the body from `file`, or - for stdin")