This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathrecord.go
102 lines (78 loc) · 1.75 KB
/
record.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2019 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"fmt"
"strings"
)
const (
labelNamesSeparator = ","
)
func labelToRecord(l Label, quote bool) (record []string) {
name := l.Name
category := l.CategoryName
colour := l.Colour
from := l.From
if quote {
name = fmt.Sprintf("`%s`", l.Name)
category = fmt.Sprintf("`%s`", l.CategoryName)
colour = fmt.Sprintf("`%s`", l.Colour)
if from != "" {
from = fmt.Sprintf("`%s`", l.From)
}
}
record = append(record, name)
record = append(record, l.Description)
record = append(record, category)
record = append(record, colour)
record = append(record, from)
return record
}
func labelHeaderRecord() []string {
return []string{
"Name",
"Description",
"Category",
"Colour",
"From",
}
}
func categoryHeaderRecord(showLabels bool) []string {
var fields []string
fields = append(fields, "Name")
fields = append(fields, "Description")
fields = append(fields, "URL")
if showLabels {
fields = append(fields, "Labels")
}
return fields
}
func categoryToRecord(lf *LabelsFile, c Category, showLabels, quote bool) ([]string, error) {
var record []string
name := c.Name
if quote {
name = fmt.Sprintf("`%s`", c.Name)
}
record = append(record, name)
record = append(record, c.Description)
record = append(record, c.URL)
if showLabels {
var labelNames []string
labels, err := getLabelsByCategory(c.Name, lf)
if err != nil {
return nil, err
}
for _, l := range labels {
labelName := l.Name
if quote {
labelName = fmt.Sprintf("`%s`", l.Name)
}
labelNames = append(labelNames, labelName)
}
result := strings.Join(labelNames, labelNamesSeparator)
record = append(record, result)
}
return record, nil
}