aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation_pack.go
diff options
context:
space:
mode:
Diffstat (limited to 'bug/operation_pack.go')
-rw-r--r--bug/operation_pack.go47
1 files changed, 35 insertions, 12 deletions
diff --git a/bug/operation_pack.go b/bug/operation_pack.go
index f33d94bf..5f3e9da8 100644
--- a/bug/operation_pack.go
+++ b/bug/operation_pack.go
@@ -20,7 +20,7 @@ const formatVersion = 1
type OperationPack struct {
Operations []Operation
- // Private field so not serialized by gob
+ // Private field so not serialized
commitHash git.Hash
}
@@ -57,6 +57,7 @@ func (opp *OperationPack) UnmarshalJSON(data []byte) error {
return err
}
+ // delegate to specialized unmarshal function
op, err := opp.unmarshalOp(raw, t.OperationType)
if err != nil {
return err
@@ -73,28 +74,36 @@ func (opp *OperationPack) UnmarshalJSON(data []byte) error {
func (opp *OperationPack) unmarshalOp(raw []byte, _type OperationType) (Operation, error) {
switch _type {
+ case AddCommentOp:
+ op := &AddCommentOperation{}
+ err := json.Unmarshal(raw, &op)
+ return op, err
case CreateOp:
op := &CreateOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case SetTitleOp:
- op := &SetTitleOperation{}
+ case EditCommentOp:
+ op := &EditCommentOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case AddCommentOp:
- op := &AddCommentOperation{}
+ case LabelChangeOp:
+ op := &LabelChangeOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case SetStatusOp:
- op := &SetStatusOperation{}
+ case NoOpOp:
+ op := &NoOpOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case LabelChangeOp:
- op := &LabelChangeOperation{}
+ case SetMetadataOp:
+ op := &SetMetadataOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case EditCommentOp:
- op := &EditCommentOperation{}
+ case SetStatusOp:
+ op := &SetStatusOperation{}
+ err := json.Unmarshal(raw, &op)
+ return op, err
+ case SetTitleOp:
+ op := &SetTitleOperation{}
err := json.Unmarshal(raw, &op)
return op, err
default:
@@ -129,7 +138,21 @@ func (opp *OperationPack) Validate() error {
// Write will serialize and store the OperationPack as a git blob and return
// its hash
-func (opp *OperationPack) Write(repo repository.Repo) (git.Hash, error) {
+func (opp *OperationPack) Write(repo repository.ClockedRepo) (git.Hash, error) {
+ // make sure we don't write invalid data
+ err := opp.Validate()
+ if err != nil {
+ return "", errors.Wrap(err, "validation error")
+ }
+
+ // First, make sure that all the identities are properly Commit as well
+ for _, op := range opp.Operations {
+ err := op.base().Author.CommitAsNeeded(repo)
+ if err != nil {
+ return "", err
+ }
+ }
+
data, err := json.Marshal(opp)
if err != nil {