aboutsummaryrefslogtreecommitdiffstats
path: root/bug/snapshot.go
blob: 1004b625a0cb4d65b1a550d73042f1f0ed1f3072 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package bug

import (
	"fmt"
	"time"

	"github.com/MichaelMure/git-bug/util/git"
)

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

	Status    Status
	Title     string
	Comments  []Comment
	Labels    []Label
	Author    Person
	CreatedAt time.Time

	Timeline []TimelineItem

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

// Deprecated:should be moved in UI code
func (snap *Snapshot) Summary() string {
	return fmt.Sprintf("C:%d L:%d",
		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 {
		return time.Unix(0, 0)
	}

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

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

// SearchTimelineItem will search in the timeline for an item matching the given hash
func (snap *Snapshot) SearchTimelineItem(hash git.Hash) (TimelineItem, error) {
	for i := range snap.Timeline {
		if snap.Timeline[i].Hash() == hash {
			return snap.Timeline[i], nil
		}
	}

	return nil, fmt.Errorf("timeline item not found")
}