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
30func NewNoOpOp(author Person, unixTime int64) *NoOpOperation {
31	return &NoOpOperation{
32		OpBase: newOpBase(NoOpOp, author, unixTime),
33	}
34}
35
36// Convenience function to apply the operation
37func NoOp(b Interface, author Person, unixTime int64, metadata map[string]string) (*NoOpOperation, error) {
38	op := NewNoOpOp(author, unixTime)
39
40	for key, value := range metadata {
41		op.SetMetadata(key, value)
42	}
43
44	if err := op.Validate(); err != nil {
45		return nil, err
46	}
47	b.Append(op)
48	return op, nil
49}