/
assignees.go
55 lines (46 loc) · 1 KB
/
assignees.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
package prchecker
import (
"sync"
)
// Assignees has GitHub users.
type Assignees struct {
once sync.Once
// listMap contains GitHub users in Key.
listMap map[string]struct{}
}
// HasAssignees checks if at least one user is exists or not.
func (a *Assignees) HasAssignees() bool {
return len(a.listMap) != 0
}
// RemoveFromList removes users from the list.
func (a *Assignees) RemoveFromList(names ...string) {
for _, name := range names {
if _, ok := a.listMap[name]; ok {
delete(a.listMap, name)
}
}
}
// Add adds users into the list.
func (a *Assignees) Add(assignees ...string) {
if len(assignees) == 0 {
return
}
a.once.Do(func() {
a.listMap = make(map[string]struct{})
})
for _, assignee := range assignees {
a.listMap[assignee] = struct{}{}
}
}
// List returns the list of users.
func (a *Assignees) List() []string {
size := len(a.listMap)
if size == 0 {
return nil
}
list := make([]string, 0, size)
for key := range a.listMap {
list = append(list, key)
}
return list
}