...
1
16
17 package releaseutil
18
19 import (
20 "sort"
21
22 rspb "helm.sh/helm/v3/pkg/release"
23 )
24
25 type list []*rspb.Release
26
27 func (s list) Len() int { return len(s) }
28 func (s list) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
29
30
31 type ByName struct{ list }
32
33
34 func (s ByName) Less(i, j int) bool { return s.list[i].Name < s.list[j].Name }
35
36
37 type ByDate struct{ list }
38
39
40 func (s ByDate) Less(i, j int) bool {
41 ti := s.list[i].Info.LastDeployed.Unix()
42 tj := s.list[j].Info.LastDeployed.Unix()
43 return ti < tj
44 }
45
46
47 type ByRevision struct{ list }
48
49
50 func (s ByRevision) Less(i, j int) bool {
51 return s.list[i].Version < s.list[j].Version
52 }
53
54
55 func Reverse(list []*rspb.Release, sortFn func([]*rspb.Release)) {
56 sortFn(list)
57 for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
58 list[i], list[j] = list[j], list[i]
59 }
60 }
61
62
63
64 func SortByName(list []*rspb.Release) {
65 sort.Sort(ByName{list})
66 }
67
68
69
70 func SortByDate(list []*rspb.Release) {
71 sort.Sort(ByDate{list})
72 }
73
74
75
76 func SortByRevision(list []*rspb.Release) {
77 sort.Sort(ByRevision{list})
78 }
79
View as plain text