-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.go
More file actions
91 lines (73 loc) · 2.08 KB
/
models.go
File metadata and controls
91 lines (73 loc) · 2.08 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
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
package depot
import (
"fmt"
"github.com/modfin/henry/mapz"
"github.com/modfin/henry/slicez"
"strings"
)
type SPDX string
type FileName string
type LicenseStructure map[SPDX]map[FileName][]string
func (license LicenseStructure) String() string {
var header string
var body string
spdxs := slicez.Sort(mapz.Keys(license))
for _, spdx := range spdxs {
var link string
if !slicez.Contains([]string{"~unknown", "~non-standard"}, string(spdx)) {
ss := strings.ReplaceAll(string(spdx), "(", "( ")
ss = strings.ReplaceAll(ss, ")", " )")
links := slicez.Map(strings.Split(ss, " "), func(a string) string {
switch a {
case "AND", "OR":
return "\n " + a
case "WITH":
return "\n " + a
case "(", ")":
return a
}
return fmt.Sprintf("https://spdx.org/licenses/%s.html", a)
})
link = fmt.Sprintf("\n %s", strings.Join(links, " "))
}
body += fmt.Sprintf("========================================================================\n")
body += fmt.Sprintf("%s%s\n", spdx, link)
body += fmt.Sprintf("========================================================================\n\n")
var countDirect int
var countIndirect int
files := slicez.Sort(mapz.Keys(license[spdx]))
for _, file := range files {
body += fmt.Sprintf(" [%s]\n", file)
deps := slicez.Sort(license[spdx][file])
for _, dep := range deps {
if strings.HasSuffix(dep, " //indirect") {
continue
}
countDirect++
body += fmt.Sprintf(" %s\n", dep)
}
for _, dep := range deps {
if !strings.HasSuffix(dep, " //indirect") {
continue
}
countIndirect++
body += fmt.Sprintf(" %s\n", dep)
}
body += "\n"
}
header += fmt.Sprintf("%s: %d\n", spdx, countDirect+countIndirect)
}
return "---\n" + header + "---\n" + body
}
type Config struct {
Dependency struct {
Ignore []Dependency `yaml:"ignore"`
Licenses []Dependency `yaml:"licenses"`
} `yaml:"dependency"`
}
type Dependency struct {
Type string `yaml:"type"`
Name string `yaml:"name"`
Version string `yaml:"version"`
License []string `yaml:"license"`
}