1package bug
2
3import (
4 "github.com/MichaelMure/git-bug/identity"
5 "github.com/MichaelMure/git-bug/util/git"
6)
7
8var _ Operation = &NoOpOperation{}
9
10// NoOpOperation is an operation that does not change the bug state. It can
11// however be used to store arbitrary metadata in the bug history, for example
12// to support a bridge feature
13type NoOpOperation struct {
14 OpBase
15}
16
17func (op *NoOpOperation) base() *OpBase {
18 return &op.OpBase
19}
20
21func (op *NoOpOperation) Hash() (git.Hash, error) {
22 return hashOperation(op)
23}
24
25func (op *NoOpOperation) Apply(snapshot *Snapshot) {
26 // Nothing to do
27}
28
29func (op *NoOpOperation) Validate() error {
30 return opBaseValidate(op, NoOpOp)
31}
32
33// Sign post method for gqlgen
34func (op *NoOpOperation) IsAuthored() {}
35
36func NewNoOpOp(author identity.Interface, unixTime int64) *NoOpOperation {
37 return &NoOpOperation{
38 OpBase: newOpBase(NoOpOp, author, unixTime),
39 }
40}
41
42// Convenience function to apply the operation
43func NoOp(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*NoOpOperation, error) {
44 op := NewNoOpOp(author, unixTime)
45
46 for key, value := range metadata {
47 op.SetMetadata(key, value)
48 }
49
50 if err := op.Validate(); err != nil {
51 return nil, err
52 }
53 b.Append(op)
54 return op, nil
55}