forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.go
62 lines (48 loc) · 1.17 KB
/
clean.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
// Copyright (c) 2019 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import "strings"
func cleanString(s string) string {
result := strings.Replace(s, "\n", " ", -1)
result = strings.Replace(result, "\t", "\\t", -1)
result = strings.TrimSpace(result)
return result
}
func cleanLabel(l Label) Label {
return Label{
Name: cleanString(l.Name),
Description: cleanString(l.Description),
CategoryName: cleanString(l.CategoryName),
Colour: cleanString(l.Colour),
From: cleanString(l.From),
}
}
func cleanCategory(c *Category) {
c.Name = cleanString(c.Name)
c.Description = cleanString(c.Description)
c.URL = cleanString(c.URL)
}
func cleanCategories(lf *LabelsFile) {
var cleaned Categories
for _, c := range lf.Categories {
cleanCategory(&c)
cleaned = append(cleaned, c)
}
lf.Categories = cleaned
}
func cleanLabels(lf *LabelsFile) {
var cleaned Labels
for _, l := range lf.Labels {
new := cleanLabel(l)
cleaned = append(cleaned, new)
}
lf.Labels = cleaned
}
func clean(lf *LabelsFile) {
lf.Description = cleanString(lf.Description)
lf.Repo = cleanString(lf.Repo)
cleanCategories(lf)
cleanLabels(lf)
}