2018-07-13 17:13:40 +03:00
|
|
|
package bug
|
2018-07-12 22:31:41 +03:00
|
|
|
|
2018-08-03 00:37:49 +03:00
|
|
|
import (
|
|
|
|
"github.com/MichaelMure/git-bug/util"
|
|
|
|
"time"
|
|
|
|
)
|
2018-07-18 01:16:06 +03:00
|
|
|
|
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
|
2018-07-18 01:16:06 +03:00
|
|
|
Time() time.Time
|
2018-07-13 17:13:40 +03:00
|
|
|
Apply(snapshot Snapshot) Snapshot
|
2018-08-03 00:37:49 +03:00
|
|
|
Files() []util.Hash
|
2018-07-31 16:18:09 +03:00
|
|
|
|
|
|
|
// TODO: data validation (ex: a title is a single line)
|
|
|
|
// Validate() bool
|
2018-07-12 22:31:41 +03:00
|
|
|
}
|
2018-07-13 22:21:24 +03:00
|
|
|
|
|
|
|
type OpBase struct {
|
2018-07-14 23:17:37 +03:00
|
|
|
OperationType OperationType
|
2018-07-18 01:16:06 +03:00
|
|
|
Author Person
|
|
|
|
UnixTime int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOpBase(opType OperationType, author Person) OpBase {
|
|
|
|
return OpBase{
|
|
|
|
OperationType: opType,
|
|
|
|
Author: author,
|
|
|
|
UnixTime: time.Now().Unix(),
|
|
|
|
}
|
2018-07-13 22:21:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (op OpBase) OpType() OperationType {
|
|
|
|
return op.OperationType
|
|
|
|
}
|
2018-07-18 01:16:06 +03:00
|
|
|
|
|
|
|
func (op OpBase) Time() time.Time {
|
|
|
|
return time.Unix(op.UnixTime, 0)
|
|
|
|
}
|
2018-08-06 21:31:20 +03:00
|
|
|
|
|
|
|
func (op OpBase) Files() []util.Hash {
|
|
|
|
return nil
|
|
|
|
}
|