aboutsummaryrefslogtreecommitdiffstats
path: root/bug/snapshot.go
blob: 5058b3f74d8fab15e7c1cdf5b7d00e70506c2b1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package bug

import (
	"fmt"
	"github.com/dustin/go-humanize"
	"time"
)

// Snapshot is a compiled form of the Bug data structure used for storage and merge
type Snapshot struct {
	id string

	Status   Status    `json:"status"`
	Title    string    `json:"title"`
	Comments []Comment `json:"comments"`
	Labels   []Label   `json:"labels"`

	Operations []Operation
}

// 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)
}

func (snap Snapshot) Summary() string {
	return fmt.Sprintf("C:%d L:%d   %s",
		len(snap.Comments)-1,
		len(snap.Labels),
		humanize.Time(snap.LastEdit()),
	)
}

// Return the last time a bug was modified
func (snap Snapshot) LastEdit() time.Time {
	if len(snap.Operations) == 0 {
		return time.Unix(0, 0)
	}

	return snap.Operations[len(snap.Operations)-1].Time()
}