git-bug/bug/snapshot.go

56 lines
1.0 KiB
Go
Raw Normal View History

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 {
id string
2018-08-01 03:15:40 +03:00
Status Status
Title string
Comments []Comment
Labels []Label
Author Person
CreatedAt time.Time
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 {
return fmt.Sprintf("C:%d L:%d",
2018-07-15 02:43:20 +03:00
len(snap.Comments)-1,
len(snap.Labels),
)
}
// Return the last time a bug was modified
func (snap Snapshot) LastEditTime() time.Time {
if len(snap.Operations) == 0 {
2018-07-17 21:51:09 +03:00
return time.Unix(0, 0)
}
return snap.Operations[len(snap.Operations)-1].Time()
2018-07-15 02:43:20 +03:00
}
// Return the last timestamp a bug was modified
func (snap Snapshot) LastEditUnix() int64 {
if len(snap.Operations) == 0 {
return 0
}
return snap.Operations[len(snap.Operations)-1].GetUnixTime()
}