aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-10-01 21:58:50 +0200
committerMichael Muré <batolettre@gmail.com>2018-10-01 21:58:50 +0200
commitde81ed49e67ce47bd931bd6f84bd1bb8a2167262 (patch)
treef31444ddfba79d3df42b1f8024dca3acd2dac387 /bug
parentbe59fe0d67805117f537ec64dea92b7113cb387a (diff)
downloadgit-bug-de81ed49e67ce47bd931bd6f84bd1bb8a2167262.tar.gz
bug: add a new no-op operation to store arbitrary metadata on a bug
Diffstat (limited to 'bug')
-rw-r--r--bug/op_noop.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/bug/op_noop.go b/bug/op_noop.go
new file mode 100644
index 00000000..06e3496a
--- /dev/null
+++ b/bug/op_noop.go
@@ -0,0 +1,49 @@
+package bug
+
+import "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
+type NoOpOperation struct {
+ OpBase
+}
+
+func (op *NoOpOperation) base() *OpBase {
+ return &op.OpBase
+}
+
+func (op *NoOpOperation) Hash() (git.Hash, error) {
+ return hashOperation(op)
+}
+
+func (op *NoOpOperation) Apply(snapshot *Snapshot) {
+ // Nothing to do
+}
+
+func (op *NoOpOperation) Validate() error {
+ return opBaseValidate(op, NoOpOp)
+}
+
+func NewNoOpOp(author Person, 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) {
+ op := NewNoOpOp(author, unixTime)
+
+ for key, value := range metadata {
+ op.SetMetadata(key, value)
+ }
+
+ if err := op.Validate(); err != nil {
+ return nil, err
+ }
+ b.Append(op)
+ return op, nil
+}