forked from MichaelMure/git-bug
-
Notifications
You must be signed in to change notification settings - Fork 3
/
identity.go
75 lines (61 loc) · 1.72 KB
/
identity.go
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
72
73
74
75
package bug
import (
"github.com/daedaleanai/git-ticket/entity"
"github.com/daedaleanai/git-ticket/identity"
)
// EnsureIdentities walk the graph of operations and make sure that all Identity
// are properly loaded. That is, it replace all the IdentityStub with the full
// Identity, loaded through a Resolver.
func (bug *Bug) EnsureIdentities(resolver identity.Resolver) error {
it := NewOperationIterator(bug)
// only resolve each identity once
found := make(map[entity.Id]identity.Interface)
for it.Next() {
op := it.Value()
base := op.base()
if stub, ok := base.Author.(*identity.IdentityStub); ok {
entity := stub.Id()
if _, ok := found[entity]; !ok {
id, err := resolver.ResolveIdentity(entity)
if err != nil {
return err
}
found[entity] = id
}
base.Author = found[entity]
}
// if it's an operation which sets the assignee we also need to
// resolve that
if setAss, ok := op.(*SetAssigneeOperation); ok {
entity := setAss.Assignee.Id()
if _, ok := found[entity]; !ok {
id, err := resolver.ResolveIdentity(entity)
if err != nil {
return err
}
found[entity] = id
}
setAss.Assignee = found[entity]
}
// and for review operations, each of the update authors
if setRev, ok := op.(*SetReviewOperation); ok {
err := setRev.Review.EnsureIdentities(resolver, found)
if err != nil {
return err
}
}
// and for ccb operations, the user being added / removed
if setCcb, ok := op.(*SetCcbOperation); ok {
entity := setCcb.Ccb.User.Id()
if _, ok := found[entity]; !ok {
id, err := resolver.ResolveIdentity(entity)
if err != nil {
return err
}
found[entity] = id
}
setCcb.Ccb.User = found[entity]
}
}
return nil
}