1package bug
2
3import (
4 "github.com/MichaelMure/git-bug/util"
5 "time"
6)
7
8type OperationType int
9
10const (
11 _ OperationType = iota
12 CreateOp
13 SetTitleOp
14 AddCommentOp
15 SetStatusOp
16 LabelChangeOp
17)
18
19type Operation interface {
20 OpType() OperationType
21 Time() time.Time
22 Apply(snapshot Snapshot) Snapshot
23 Files() []util.Hash
24
25 // TODO: data validation (ex: a title is a single line)
26 // Validate() bool
27}
28
29type OpBase struct {
30 OperationType OperationType
31 Author Person
32 UnixTime int64
33}
34
35func NewOpBase(opType OperationType, author Person) OpBase {
36 return OpBase{
37 OperationType: opType,
38 Author: author,
39 UnixTime: time.Now().Unix(),
40 }
41}
42
43func (op OpBase) OpType() OperationType {
44 return op.OperationType
45}
46
47func (op OpBase) Time() time.Time {
48 return time.Unix(op.UnixTime, 0)
49}