diff options
Diffstat (limited to 'bug/op_set_title.go')
-rw-r--r-- | bug/op_set_title.go | 50 |
1 files changed, 12 insertions, 38 deletions
diff --git a/bug/op_set_title.go b/bug/op_set_title.go index 31113943..fadd29a9 100644 --- a/bug/op_set_title.go +++ b/bug/op_set_title.go @@ -5,10 +5,10 @@ import ( "fmt" "strings" + "github.com/MichaelMure/git-bug/entity" "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" ) @@ -17,31 +17,24 @@ var _ Operation = &SetTitleOperation{} // SetTitleOperation will change the title of a bug type SetTitleOperation struct { OpBase - Title string - Was string + Title string `json:"title"` + Was string `json:"was"` } func (op *SetTitleOperation) base() *OpBase { return &op.OpBase } -func (op *SetTitleOperation) Hash() (git.Hash, error) { - return hashOperation(op) +func (op *SetTitleOperation) Id() entity.Id { + return idOperation(op) } func (op *SetTitleOperation) Apply(snapshot *Snapshot) { snapshot.Title = op.Title snapshot.addActor(op.Author) - hash, err := op.Hash() - if err != nil { - // Should never error unless a programming error happened - // (covered in OpBase.Validate()) - panic(err) - } - item := &SetTitleTimelineItem{ - hash: hash, + id: op.Id(), Author: op.Author, UnixTime: timestamp.Timestamp(op.UnixTime), Title: op.Title, @@ -79,28 +72,9 @@ 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 +// UnmarshalJSON is a two step JSON unmarshaling +// This workaround is necessary to avoid the inner OpBase.MarshalJSON +// overriding the outer op's MarshalJSON func (op *SetTitleOperation) UnmarshalJSON(data []byte) error { // Unmarshal OpBase and the op separately @@ -139,15 +113,15 @@ func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was } type SetTitleTimelineItem struct { - hash git.Hash + id entity.Id Author identity.Interface UnixTime timestamp.Timestamp Title string Was string } -func (s SetTitleTimelineItem) Hash() git.Hash { - return s.hash +func (s SetTitleTimelineItem) Id() entity.Id { + return s.id } // Sign post method for gqlgen |