1package bug
2
3import (
4 "github.com/MichaelMure/git-bug/util"
5 "time"
6)
7
8// OperationType is an identifier
9type OperationType int
10
11const (
12 _ OperationType = iota
13 CreateOp
14 SetTitleOp
15 AddCommentOp
16 SetStatusOp
17 LabelChangeOp
18)
19
20// Operation define the interface to fulfill for an edit operation of a Bug
21type Operation interface {
22 // OpType return the type of operation
23 OpType() OperationType
24 // Time return the time when the operation was added
25 Time() time.Time
26 // Apply the operation to a Snapshot to create the final state
27 Apply(snapshot Snapshot) Snapshot
28 // Files return the files needed by this operation
29 Files() []util.Hash
30
31 // TODO: data validation (ex: a title is a single line)
32 // Validate() bool
33}
34
35// OpBase implement the common code for all operations
36type OpBase struct {
37 OperationType OperationType
38 Author Person
39 UnixTime int64
40}
41
42// NewOpBase is the constructor for an OpBase
43func NewOpBase(opType OperationType, author Person) OpBase {
44 return OpBase{
45 OperationType: opType,
46 Author: author,
47 UnixTime: time.Now().Unix(),
48 }
49}
50
51// OpType return the type of operation
52func (op OpBase) OpType() OperationType {
53 return op.OperationType
54}
55
56// Time return the time when the operation was added
57func (op OpBase) Time() time.Time {
58 return time.Unix(op.UnixTime, 0)
59}
60
61// Files return the files needed by this operation
62func (op OpBase) Files() []util.Hash {
63 return nil
64}