From feab9412dffe5772048aad29893c4cb01d566387 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 21 Nov 2018 18:56:12 +0100 Subject: WIP identity in git --- bug/op_set_title.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bug/op_set_title.go') diff --git a/bug/op_set_title.go b/bug/op_set_title.go index b631ca18..3b253c06 100644 --- a/bug/op_set_title.go +++ b/bug/op_set_title.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/text" ) @@ -77,7 +79,7 @@ func (op *SetTitleOperation) Validate() error { // Sign post method for gqlgen func (op *SetTitleOperation) IsAuthored() {} -func NewSetTitleOp(author Person, unixTime int64, title string, was string) *SetTitleOperation { +func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was string) *SetTitleOperation { return &SetTitleOperation{ OpBase: newOpBase(SetTitleOp, author, unixTime), Title: title, @@ -87,7 +89,7 @@ func NewSetTitleOp(author Person, unixTime int64, title string, was string) *Set type SetTitleTimelineItem struct { hash git.Hash - Author Person + Author identity.Interface UnixTime Timestamp Title string Was string @@ -98,7 +100,7 @@ func (s SetTitleTimelineItem) Hash() git.Hash { } // Convenience function to apply the operation -func SetTitle(b Interface, author Person, unixTime int64, title string) (*SetTitleOperation, error) { +func SetTitle(b Interface, author identity.Interface, unixTime int64, title string) (*SetTitleOperation, error) { it := NewOperationIterator(b) var lastTitleOp Operation -- cgit From d10c76469d40f13e27739fd363145e89bf74c3e0 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 19 Jan 2019 19:23:31 +0100 Subject: identity: somewhat getting closer ! --- bug/op_set_title.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'bug/op_set_title.go') diff --git a/bug/op_set_title.go b/bug/op_set_title.go index 3b253c06..ae6484c6 100644 --- a/bug/op_set_title.go +++ b/bug/op_set_title.go @@ -1,6 +1,7 @@ package bug import ( + "encoding/json" "fmt" "strings" @@ -15,8 +16,8 @@ var _ Operation = &SetTitleOperation{} // SetTitleOperation will change the title of a bug type SetTitleOperation struct { OpBase - Title string `json:"title"` - Was string `json:"was"` + Title string + Was string } func (op *SetTitleOperation) base() *OpBase { @@ -76,6 +77,54 @@ func (op *SetTitleOperation) Validate() error { return nil } +// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op +// MarshalJSON +func (op *SetTitleOperation) MarshalJSON() ([]byte, error) { + base, err := json.Marshal(op.OpBase) + if err != nil { + return nil, err + } + + // revert back to a flat map to be able to add our own fields + var data map[string]interface{} + if err := json.Unmarshal(base, &data); err != nil { + return nil, err + } + + data["title"] = op.Title + data["was"] = op.Was + + return json.Marshal(data) +} + +// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op +// MarshalJSON +func (op *SetTitleOperation) UnmarshalJSON(data []byte) error { + // Unmarshal OpBase and the op separately + + base := OpBase{} + err := json.Unmarshal(data, &base) + if err != nil { + return err + } + + aux := struct { + Title string `json:"title"` + Was string `json:"was"` + }{} + + err = json.Unmarshal(data, &aux) + if err != nil { + return err + } + + op.OpBase = base + op.Title = aux.Title + op.Was = aux.Was + + return nil +} + // Sign post method for gqlgen func (op *SetTitleOperation) IsAuthored() {} -- cgit From c235d89d36500e58e3bcadda94e9cab06023dd55 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 24 Feb 2019 23:05:03 +0100 Subject: commands: show the last modification time in "user" --- bug/op_set_title.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'bug/op_set_title.go') diff --git a/bug/op_set_title.go b/bug/op_set_title.go index ae6484c6..084838cb 100644 --- a/bug/op_set_title.go +++ b/bug/op_set_title.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/util/timestamp" "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/text" @@ -41,7 +42,7 @@ func (op *SetTitleOperation) Apply(snapshot *Snapshot) { item := &SetTitleTimelineItem{ hash: hash, Author: op.Author, - UnixTime: Timestamp(op.UnixTime), + UnixTime: timestamp.Timestamp(op.UnixTime), Title: op.Title, Was: op.Was, } @@ -139,7 +140,7 @@ func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was type SetTitleTimelineItem struct { hash git.Hash Author identity.Interface - UnixTime Timestamp + UnixTime timestamp.Timestamp Title string Was string } -- cgit