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_noop.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'bug/op_noop.go') diff --git a/bug/op_noop.go b/bug/op_noop.go index ac898dde..410799b3 100644 --- a/bug/op_noop.go +++ b/bug/op_noop.go @@ -1,6 +1,9 @@ package bug -import "github.com/MichaelMure/git-bug/util/git" +import ( + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/util/git" +) var _ Operation = &NoOpOperation{} @@ -30,14 +33,14 @@ func (op *NoOpOperation) Validate() error { // Sign post method for gqlgen func (op *NoOpOperation) IsAuthored() {} -func NewNoOpOp(author Person, unixTime int64) *NoOpOperation { +func NewNoOpOp(author identity.Interface, unixTime int64) *NoOpOperation { return &NoOpOperation{ OpBase: newOpBase(NoOpOp, author, unixTime), } } // Convenience function to apply the operation -func NoOp(b Interface, author Person, unixTime int64, metadata map[string]string) (*NoOpOperation, error) { +func NoOp(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*NoOpOperation, error) { op := NewNoOpOp(author, unixTime) for key, value := range metadata { -- 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_noop.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'bug/op_noop.go') diff --git a/bug/op_noop.go b/bug/op_noop.go index 410799b3..fbc112a8 100644 --- a/bug/op_noop.go +++ b/bug/op_noop.go @@ -1,6 +1,8 @@ package bug import ( + "encoding/json" + "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/git" ) @@ -30,6 +32,46 @@ func (op *NoOpOperation) Validate() error { return opBaseValidate(op, NoOpOp) } +// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op +// MarshalJSON +func (op *NoOpOperation) 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 + } + + return json.Marshal(data) +} + +// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op +// MarshalJSON +func (op *NoOpOperation) UnmarshalJSON(data []byte) error { + // Unmarshal OpBase and the op separately + + base := OpBase{} + err := json.Unmarshal(data, &base) + if err != nil { + return err + } + + aux := struct{}{} + + err = json.Unmarshal(data, &aux) + if err != nil { + return err + } + + op.OpBase = base + + return nil +} + // Sign post method for gqlgen func (op *NoOpOperation) 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_noop.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bug/op_noop.go') diff --git a/bug/op_noop.go b/bug/op_noop.go index fbc112a8..3cd9f39a 100644 --- a/bug/op_noop.go +++ b/bug/op_noop.go @@ -11,7 +11,7 @@ var _ Operation = &NoOpOperation{} // NoOpOperation is an operation that does not change the bug state. It can // however be used to store arbitrary metadata in the bug history, for example -// to support a bridge feature +// to support a bridge feature. type NoOpOperation struct { OpBase } -- cgit