aboutsummaryrefslogtreecommitdiffstats
path: root/bug/clocks.go
blob: ba93e0dcbf67203c49097ca2abf663713b5f11c2 (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
package bug

import (
	"github.com/MichaelMure/git-bug/repository"
)

// ClockLoader is the repository.ClockLoader for the Bug entity
var ClockLoader = repository.ClockLoader{
	Clocks: []string{creationClockName, editClockName},
	Witnesser: func(repo repository.ClockedRepo) error {
		for b := range ReadAllLocalBugs(repo) {
			if b.Err != nil {
				return b.Err
			}

			createClock, err := repo.GetOrCreateClock(creationClockName)
			if err != nil {
				return err
			}
			err = createClock.Witness(b.Bug.createTime)
			if err != nil {
				return err
			}

			editClock, err := repo.GetOrCreateClock(editClockName)
			if err != nil {
				return err
			}
			err = editClock.Witness(b.Bug.editTime)
			if err != nil {
				return err
			}
		}

		return nil
	},
}