op_noop.go

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