diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/json_common.go | 55 | ||||
-rw-r--r-- | commands/ls.go | 33 | ||||
-rw-r--r-- | commands/show.go | 66 | ||||
-rw-r--r-- | commands/user_ls.go | 33 |
4 files changed, 102 insertions, 85 deletions
diff --git a/commands/json_common.go b/commands/json_common.go new file mode 100644 index 00000000..9a144a1e --- /dev/null +++ b/commands/json_common.go @@ -0,0 +1,55 @@ +package commands + +import ( + "time" + + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/util/lamport" +) + +type JSONIdentity struct { + Id string `json:"id"` + HumanId string `json:"human_id"` + Name string `json:"name"` + Login string `json:"login"` +} + +func NewJSONIdentity(i identity.Interface) JSONIdentity { + return JSONIdentity{ + Id: i.Id().String(), + HumanId: i.Id().Human(), + Name: i.Name(), + Login: i.Login(), + } +} + +func NewJSONIdentityFromExcerpt(excerpt *cache.IdentityExcerpt) JSONIdentity { + return JSONIdentity{ + Id: excerpt.Id.String(), + HumanId: excerpt.Id.Human(), + Name: excerpt.Name, + Login: excerpt.Login, + } +} + +func NewJSONIdentityFromLegacyExcerpt(excerpt *cache.LegacyAuthorExcerpt) JSONIdentity { + return JSONIdentity{ + Name: excerpt.Name, + Login: excerpt.Login, + } +} + +type JSONTime struct { + Timestamp int64 `json:"timestamp"` + Time time.Time `json:"time"` + Lamport lamport.Time `json:"lamport,omitempty"` +} + +func NewJSONTime(t time.Time, l lamport.Time) JSONTime { + return JSONTime{ + Timestamp: t.Unix(), + Time: t, + Lamport: l, + } +} diff --git a/commands/ls.go b/commands/ls.go index e1a7166a..34f1f982 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "strings" - "time" text "github.com/MichaelMure/go-term-text" "github.com/spf13/cobra" @@ -75,10 +74,10 @@ func runLsBug(_ *cobra.Command, args []string) error { } type JSONBugExcerpt struct { - Id string `json:"id"` - HumanId string `json:"human_id"` - CreationTime time.Time `json:"creation_time"` - LastEdited time.Time `json:"last_edited"` + Id string `json:"id"` + HumanId string `json:"human_id"` + CreateTime JSONTime `json:"create_time"` + EditTime JSONTime `json:"edit_time"` Status string `json:"status"` Labels []bug.Label `json:"labels"` @@ -95,15 +94,15 @@ func lsJsonFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerpt) jsonBugs := make([]JSONBugExcerpt, len(bugExcerpts)) for i, b := range bugExcerpts { jsonBug := JSONBugExcerpt{ - Id: b.Id.String(), - HumanId: b.Id.Human(), - CreationTime: time.Unix(b.CreateUnixTime, 0), - LastEdited: time.Unix(b.EditUnixTime, 0), - Status: b.Status.String(), - Labels: b.Labels, - Title: b.Title, - Comments: b.LenComments, - Metadata: b.CreateMetadata, + Id: b.Id.String(), + HumanId: b.Id.Human(), + CreateTime: NewJSONTime(b.CreateTime(), b.CreateLamportTime), + EditTime: NewJSONTime(b.EditTime(), b.EditLamportTime), + Status: b.Status.String(), + Labels: b.Labels, + Title: b.Title, + Comments: b.LenComments, + Metadata: b.CreateMetadata, } if b.AuthorId != "" { @@ -225,15 +224,13 @@ func lsOrgmodeFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerp fmt.Printf("* %s %s [%s] %s: %s %s\n", b.Id.Human(), status, - time.Unix(b.CreateUnixTime, 0), + b.CreateTime(), name, title, labelsString, ) - fmt.Printf("** Last Edited: %s\n", - time.Unix(b.EditUnixTime, 0).String(), - ) + fmt.Printf("** Last Edited: %s\n", b.EditTime().String()) fmt.Printf("** Actors:\n") for _, element := range b.Actors { diff --git a/commands/show.go b/commands/show.go index 4915f181..2f4e46ed 100644 --- a/commands/show.go +++ b/commands/show.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "strings" - "time" "github.com/spf13/cobra" @@ -47,9 +46,9 @@ func runShowBug(_ *cobra.Command, args []string) error { case "authorEmail": fmt.Printf("%s\n", snapshot.Author.Email()) case "createTime": - fmt.Printf("%s\n", snapshot.CreatedAt.String()) + fmt.Printf("%s\n", snapshot.CreateTime.String()) case "lastEdit": - fmt.Printf("%s\n", snapshot.LastEditTime().String()) + fmt.Printf("%s\n", snapshot.EditTime().String()) case "humanId": fmt.Printf("%s\n", snapshot.Id().Human()) case "id": @@ -101,11 +100,11 @@ func showDefaultFormatter(snapshot *bug.Snapshot) error { fmt.Printf("%s opened this issue %s\n", colors.Magenta(snapshot.Author.DisplayName()), - snapshot.CreatedAt.String(), + snapshot.CreateTime.String(), ) fmt.Printf("This was last edited at %s\n\n", - snapshot.LastEditTime().String(), + snapshot.EditTime().String(), ) // Labels @@ -166,37 +165,45 @@ func showDefaultFormatter(snapshot *bug.Snapshot) error { } type JSONBugSnapshot struct { - Id string `json:"id"` - HumanId string `json:"human_id"` - CreationTime time.Time `json:"creation_time"` - LastEdited time.Time `json:"last_edited"` - + Id string `json:"id"` + HumanId string `json:"human_id"` + CreateTime JSONTime `json:"create_time"` + EditTime JSONTime `json:"edit_time"` Status string `json:"status"` Labels []bug.Label `json:"labels"` Title string `json:"title"` Author JSONIdentity `json:"author"` Actors []JSONIdentity `json:"actors"` Participants []JSONIdentity `json:"participants"` - - Comments []JSONComment `json:"comments"` + Comments []JSONComment `json:"comments"` } type JSONComment struct { - Id int `json:"id"` + Id string `json:"id"` + HumanId string `json:"human_id"` Author JSONIdentity `json:"author"` Message string `json:"message"` } +func NewJSONComment(comment bug.Comment) JSONComment { + return JSONComment{ + Id: comment.Id().String(), + HumanId: comment.Id().Human(), + Author: NewJSONIdentity(comment.Author), + Message: comment.Message, + } +} + func showJsonFormatter(snapshot *bug.Snapshot) error { jsonBug := JSONBugSnapshot{ - Id: snapshot.Id().String(), - HumanId: snapshot.Id().Human(), - CreationTime: snapshot.CreatedAt, - LastEdited: snapshot.LastEditTime(), - Status: snapshot.Status.String(), - Labels: snapshot.Labels, - Title: snapshot.Title, - Author: NewJSONIdentity(snapshot.Author), + Id: snapshot.Id().String(), + HumanId: snapshot.Id().Human(), + CreateTime: NewJSONTime(snapshot.CreateTime, 0), + EditTime: NewJSONTime(snapshot.EditTime(), 0), + Status: snapshot.Status.String(), + Labels: snapshot.Labels, + Title: snapshot.Title, + Author: NewJSONIdentity(snapshot.Author), } jsonBug.Actors = make([]JSONIdentity, len(snapshot.Actors)) @@ -209,18 +216,9 @@ func showJsonFormatter(snapshot *bug.Snapshot) error { jsonBug.Participants[i] = NewJSONIdentity(element) } + jsonBug.Comments = make([]JSONComment, len(snapshot.Comments)) for i, comment := range snapshot.Comments { - var message string - if comment.Message == "" { - message = "No description provided." - } else { - message = comment.Message - } - jsonBug.Comments = append(jsonBug.Comments, JSONComment{ - Id: i, - Author: NewJSONIdentity(comment.Author), - Message: message, - }) + jsonBug.Comments[i] = NewJSONComment(comment) } jsonObject, _ := json.MarshalIndent(jsonBug, "", " ") @@ -242,11 +240,11 @@ func showOrgmodeFormatter(snapshot *bug.Snapshot) error { ) fmt.Printf("* Creation Time: %s\n", - snapshot.CreatedAt.String(), + snapshot.CreateTime.String(), ) fmt.Printf("* Last Edit: %s\n", - snapshot.LastEditTime().String(), + snapshot.EditTime().String(), ) // Labels diff --git a/commands/user_ls.go b/commands/user_ls.go index 78ef8258..b3fb32e6 100644 --- a/commands/user_ls.go +++ b/commands/user_ls.go @@ -7,7 +7,6 @@ import ( "github.com/spf13/cobra" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/colors" "github.com/MichaelMure/git-bug/util/interrupt" ) @@ -44,38 +43,6 @@ func runUserLs(_ *cobra.Command, _ []string) error { } } -type JSONIdentity struct { - Id string `json:"id"` - HumanId string `json:"human_id"` - Name string `json:"name"` - Login string `json:"login"` -} - -func NewJSONIdentity(i identity.Interface) JSONIdentity { - return JSONIdentity{ - Id: i.Id().String(), - HumanId: i.Id().Human(), - Name: i.Name(), - Login: i.Login(), - } -} - -func NewJSONIdentityFromExcerpt(excerpt *cache.IdentityExcerpt) JSONIdentity { - return JSONIdentity{ - Id: excerpt.Id.String(), - HumanId: excerpt.Id.Human(), - Name: excerpt.Name, - Login: excerpt.Login, - } -} - -func NewJSONIdentityFromLegacyExcerpt(excerpt *cache.LegacyAuthorExcerpt) JSONIdentity { - return JSONIdentity{ - Name: excerpt.Name, - Login: excerpt.Login, - } -} - func userLsDefaultFormatter(users []*cache.IdentityExcerpt) error { for _, user := range users { fmt.Printf("%s %s\n", |