-
Notifications
You must be signed in to change notification settings - Fork 0
/
repositoryContents.go
54 lines (44 loc) · 1.05 KB
/
repositoryContents.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
package main
import (
"github.com/Masterminds/semver"
"log"
"sort"
)
type ChartName string
type RepositoryContents struct {
Entries map[ChartName][]Entry `yaml:"entries"`
Versions map[ChartName]semver.Collection
Generated string `yaml:"generated"`
URL string
}
type Entry struct {
Version string `yaml:"version"`
}
func (rc *RepositoryContents) FilterCharts(chartsToKeep []Chart) {
filtered := make(map[ChartName][]Entry)
for _, chart := range chartsToKeep {
if entries, ok := rc.Entries[chart.Name]; ok {
filtered[chart.Name] = entries
continue
}
}
rc.Entries = filtered
}
func (rc *RepositoryContents) EntriesToVersions() {
if rc.Versions == nil {
rc.Versions = make(map[ChartName]semver.Collection)
}
for k, e := range rc.Entries {
versions := make(semver.Collection, 0)
for _, v := range e {
version, err := semver.NewVersion(v.Version)
if err != nil {
log.Printf("Error parsing version: %s", err)
continue
}
versions = append(versions, version)
}
sort.Sort(versions)
rc.Versions[k] = versions
}
}