diff options
author | Michael Muré <batolettre@gmail.com> | 2022-12-29 13:17:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-29 13:17:23 +0100 |
commit | c8ad1576b1472cb5723def810dfbcc30b40c70b7 (patch) | |
tree | e0a22258e29c12bec617b18298bea6bb377aede6 /commands/bug/bug_show.go | |
parent | 211a038c6057c5cfdcbf4c7d4cc8b4e93d8dc8db (diff) | |
parent | 5844dd0a6a08f496e6018c0bad0b38d82a8846fc (diff) | |
download | git-bug-c8ad1576b1472cb5723def810dfbcc30b40c70b7.tar.gz |
Merge pull request #966 from MichaelMure/cmdjson
commands: share JSON creation
Diffstat (limited to 'commands/bug/bug_show.go')
-rw-r--r-- | commands/bug/bug_show.go | 65 |
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 { |