aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bug/bug_show.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-12-29 12:49:12 +0100
committerMichael Muré <batolettre@gmail.com>2022-12-29 12:53:06 +0100
commit5844dd0a6a08f496e6018c0bad0b38d82a8846fc (patch)
treee0a22258e29c12bec617b18298bea6bb377aede6 /commands/bug/bug_show.go
parent211a038c6057c5cfdcbf4c7d4cc8b4e93d8dc8db (diff)
downloadgit-bug-5844dd0a6a08f496e6018c0bad0b38d82a8846fc.tar.gz
commands: share JSON creation
Diffstat (limited to 'commands/bug/bug_show.go')
-rw-r--r--commands/bug/bug_show.go65
1 files changed, 3 insertions, 62 deletions
diff --git a/commands/bug/bug_show.go b/commands/bug/bug_show.go
index 6cf50015..9f80120c 100644
--- a/commands/bug/bug_show.go
+++ b/commands/bug/bug_show.go
@@ -1,7 +1,6 @@
package bugcmd
import (
- "encoding/json"
"errors"
"fmt"
"strings"
@@ -186,67 +185,9 @@ func showDefaultFormatter(env *execenv.Env, snapshot *bug.Snapshot) error {
return nil
}
-type JSONBugSnapshot struct {
- Id string `json:"id"`
- HumanId string `json:"human_id"`
- CreateTime cmdjson.Time `json:"create_time"`
- EditTime cmdjson.Time `json:"edit_time"`
- Status string `json:"status"`
- Labels []bug.Label `json:"labels"`
- Title string `json:"title"`
- Author cmdjson.Identity `json:"author"`
- Actors []cmdjson.Identity `json:"actors"`
- Participants []cmdjson.Identity `json:"participants"`
- Comments []JSONBugComment `json:"comments"`
-}
-
-type JSONBugComment struct {
- Id string `json:"id"`
- HumanId string `json:"human_id"`
- Author cmdjson.Identity `json:"author"`
- Message string `json:"message"`
-}
-
-func NewJSONComment(comment bug.Comment) JSONBugComment {
- return JSONBugComment{
- Id: comment.CombinedId().String(),
- HumanId: comment.CombinedId().Human(),
- Author: cmdjson.NewIdentity(comment.Author),
- Message: comment.Message,
- }
-}
-
-func showJsonFormatter(env *execenv.Env, snapshot *bug.Snapshot) error {
- jsonBug := JSONBugSnapshot{
- Id: snapshot.Id().String(),
- HumanId: snapshot.Id().Human(),
- CreateTime: cmdjson.NewTime(snapshot.CreateTime, 0),
- EditTime: cmdjson.NewTime(snapshot.EditTime(), 0),
- Status: snapshot.Status.String(),
- Labels: snapshot.Labels,
- Title: snapshot.Title,
- Author: cmdjson.NewIdentity(snapshot.Author),
- }
-
- jsonBug.Actors = make([]cmdjson.Identity, len(snapshot.Actors))
- for i, element := range snapshot.Actors {
- jsonBug.Actors[i] = cmdjson.NewIdentity(element)
- }
-
- jsonBug.Participants = make([]cmdjson.Identity, len(snapshot.Participants))
- for i, element := range snapshot.Participants {
- jsonBug.Participants[i] = cmdjson.NewIdentity(element)
- }
-
- jsonBug.Comments = make([]JSONBugComment, len(snapshot.Comments))
- for i, comment := range snapshot.Comments {
- jsonBug.Comments[i] = NewJSONComment(comment)
- }
-
- jsonObject, _ := json.MarshalIndent(jsonBug, "", " ")
- env.Out.Printf("%s\n", jsonObject)
-
- return nil
+func showJsonFormatter(env *execenv.Env, snap *bug.Snapshot) error {
+ jsonBug := cmdjson.NewBugSnapshot(snap)
+ return env.Out.PrintJSON(jsonBug)
}
func showOrgModeFormatter(env *execenv.Env, snapshot *bug.Snapshot) error {