2018-07-13 17:13:40 +03:00
|
|
|
package bug
|
|
|
|
|
2018-07-15 02:43:20 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-07-13 17:13:40 +03:00
|
|
|
// Snapshot is a compiled form of the Bug data structure used for storage and merge
|
|
|
|
type Snapshot struct {
|
2018-07-18 01:16:06 +03:00
|
|
|
id string
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
Status Status
|
|
|
|
Title string
|
|
|
|
Comments []Comment
|
|
|
|
Labels []Label
|
|
|
|
Author Person
|
|
|
|
CreatedAt time.Time
|
2018-07-18 01:16:06 +03:00
|
|
|
|
|
|
|
Operations []Operation
|
2018-07-13 17:13:40 +03:00
|
|
|
}
|
2018-07-15 02:43:20 +03:00
|
|
|
|
2018-07-17 20:28:37 +03:00
|
|
|
// Return the Bug identifier
|
|
|
|
func (snap Snapshot) Id() string {
|
|
|
|
return snap.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the Bug identifier truncated for human consumption
|
|
|
|
func (snap Snapshot) HumanId() string {
|
|
|
|
return fmt.Sprintf("%.8s", snap.id)
|
|
|
|
}
|
|
|
|
|
2018-07-15 02:43:20 +03:00
|
|
|
func (snap Snapshot) Summary() string {
|
2018-08-02 17:48:07 +03:00
|
|
|
return fmt.Sprintf("C:%d L:%d",
|
2018-07-15 02:43:20 +03:00
|
|
|
len(snap.Comments)-1,
|
|
|
|
len(snap.Labels),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-07-18 01:16:06 +03:00
|
|
|
// Return the last time a bug was modified
|
2018-08-23 20:19:16 +03:00
|
|
|
func (snap Snapshot) LastEditTime() time.Time {
|
2018-07-18 01:16:06 +03:00
|
|
|
if len(snap.Operations) == 0 {
|
2018-07-17 21:51:09 +03:00
|
|
|
return time.Unix(0, 0)
|
|
|
|
}
|
2018-07-18 01:16:06 +03:00
|
|
|
|
|
|
|
return snap.Operations[len(snap.Operations)-1].Time()
|
2018-07-15 02:43:20 +03:00
|
|
|
}
|
2018-08-23 20:19:16 +03:00
|
|
|
|
|
|
|
// Return the last timestamp a bug was modified
|
|
|
|
func (snap Snapshot) LastEditUnix() int64 {
|
|
|
|
if len(snap.Operations) == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-09-10 20:03:17 +03:00
|
|
|
return snap.Operations[len(snap.Operations)-1].GetUnixTime()
|
2018-08-23 20:19:16 +03:00
|
|
|
}
|