aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_noop.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-03-01 23:17:57 +0100
committerGitHub <noreply@github.com>2019-03-01 23:17:57 +0100
commit7260ca05bc3588c0572887a7d8f1b897c7fc13da (patch)
tree66854358df3cb9de651f7688556ec5a4b8ab1868 /bug/op_noop.go
parent0aefae6fcca5786f2c898029c3d6282f760f2c63 (diff)
parentb6bed784e5664819250aac20b2b9690879ee6ab1 (diff)
downloadgit-bug-7260ca05bc3588c0572887a7d8f1b897c7fc13da.tar.gz
Merge pull request #89 from MichaelMure/identity
WIP identity in git
Diffstat (limited to 'bug/op_noop.go')
-rw-r--r--bug/op_noop.go53
1 files changed, 49 insertions, 4 deletions
diff --git a/bug/op_noop.go b/bug/op_noop.go
index ac898dde..3cd9f39a 100644
--- a/bug/op_noop.go
+++ b/bug/op_noop.go
@@ -1,12 +1,17 @@
package bug
-import "github.com/MichaelMure/git-bug/util/git"
+import (
+ "encoding/json"
+
+ "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/git"
+)
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
}
@@ -27,17 +32,57 @@ 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() {}
-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 {