-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfields.go
More file actions
43 lines (37 loc) · 1.15 KB
/
fields.go
File metadata and controls
43 lines (37 loc) · 1.15 KB
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
package labeler
// FieldFlag represents a bitmask for fields that can be evaluated for labeling.
// Use bitwise operations or helper methods to combine and check flags.
type FieldFlag uint
// Has returns true if the FieldFlag contains the provided flag.
func (f FieldFlag) Has(flag FieldFlag) bool {
return f&flag != 0
}
// OrDefault returns AllFieldFlags if no flags are set (f == 0), otherwise returns f.
func (f FieldFlag) OrDefault() FieldFlag {
if f == 0 {
return AllFieldFlags
}
return f
}
const (
// FieldTitle indicates the title field should be evaluated for labeling.
FieldTitle FieldFlag = 1 << iota
// FieldBody indicates the body field should be evaluated for labeling.
FieldBody
// AllFieldFlags is a convenience constant representing all available fields.
AllFieldFlags = FieldTitle | FieldBody
)
// ParseFieldFlags converts a slice of string field names to a FieldFlag bitmask.
// Unrecognized field names are ignored.
func ParseFieldFlags(fields []string) FieldFlag {
var flags FieldFlag
for _, f := range fields {
switch f {
case "title":
flags |= FieldTitle
case "body", "description":
flags |= FieldBody
}
}
return flags
}