-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
distributions.go
63 lines (57 loc) · 1.35 KB
/
distributions.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package main
import (
"fmt"
"os"
"path/filepath"
"sort"
"gopkg.in/yaml.v3"
)
type distributionsGenerator struct {
}
type distOutput struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
Maintainers []string `yaml:"maintainers"`
Components map[string][]string `yaml:"components"`
}
func (cg distributionsGenerator) generate(data *githubData) error {
for _, dist := range data.distributions {
components := map[string][]string{}
for _, c := range data.components {
inDistro := false
for _, componentDistro := range c.Status.Distributions {
if dist.Name == componentDistro {
inDistro = true
break
}
}
if inDistro {
array, ok := components[c.Status.Class]
if !ok {
array = []string{}
}
components[c.Status.Class] = append(array, c.Type)
}
}
for _, comps := range components {
sort.Strings(comps)
}
output := distOutput{
Name: dist.Name,
URL: dist.URL,
Maintainers: dist.Maintainers,
Components: components,
}
b, err := yaml.Marshal(output)
if err != nil {
return nil
}
err = os.WriteFile(filepath.Join("reports", "distributions", fmt.Sprintf("%s.yaml", dist.Name)), b, 0600)
if err != nil {
return nil
}
}
return nil
}