git-bug/bug/operation.go

54 lines
862 B
Go
Raw Normal View History

2018-07-13 17:13:40 +03:00
package bug
2018-07-12 22:31:41 +03:00
import (
"github.com/MichaelMure/git-bug/util"
"time"
)
2018-07-12 22:31:41 +03:00
type OperationType int
const (
2018-07-17 20:28:37 +03:00
_ OperationType = iota
CreateOp
SetTitleOp
AddCommentOp
SetStatusOp
2018-07-18 17:41:09 +03:00
LabelChangeOp
2018-07-12 22:31:41 +03:00
)
type Operation interface {
OpType() OperationType
Time() time.Time
2018-07-13 17:13:40 +03:00
Apply(snapshot Snapshot) Snapshot
Files() []util.Hash
// TODO: data validation (ex: a title is a single line)
// Validate() bool
2018-07-12 22:31:41 +03:00
}
type OpBase struct {
OperationType OperationType
Author Person
UnixTime int64
}
func NewOpBase(opType OperationType, author Person) OpBase {
return OpBase{
OperationType: opType,
Author: author,
UnixTime: time.Now().Unix(),
}
}
func (op OpBase) OpType() OperationType {
return op.OperationType
}
func (op OpBase) Time() time.Time {
return time.Unix(op.UnixTime, 0)
}
func (op OpBase) Files() []util.Hash {
return nil
}