Skip to content

Commit

Permalink
Order package revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmaly committed Apr 22, 2022
1 parent c1e49b9 commit 5abfb37
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
6 changes: 3 additions & 3 deletions e2e/testdata/porch/rpkg-get/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ commands:
- --output=custom-columns=NAME:.metadata.name,PKG:.spec.packageName,REPO:.spec.repository,REV:.spec.revision
stdout: |
NAME PKG REPO REV
test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens test-blueprints v1
test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 empty test-blueprints v1
test-blueprints-9626794e984ff13c9a4c64df5af0f15ec3a146bf basens test-blueprints main
test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens test-blueprints v1
test-blueprints-58fffeb908ead18e2c05c873e61bff11a5292963 empty test-blueprints main
test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 empty test-blueprints v1
- args:
- alpha
- rpkg
Expand All @@ -38,5 +38,5 @@ commands:
- --output=custom-columns=NAME:.metadata.name,PKG:.spec.packageName,REPO:.spec.repository,REV:.spec.revision
stdout: |
NAME PKG REPO REV
test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens test-blueprints v1
test-blueprints-9626794e984ff13c9a4c64df5af0f15ec3a146bf basens test-blueprints main
test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens test-blueprints v1
31 changes: 31 additions & 0 deletions porch/repository/pkg/cache/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package cache

import (
"context"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -320,5 +322,34 @@ func toPackageRevisionSlice(cached []*cachedPackageRevision, filter repository.L
result = append(result, p)
}
}
sort.Slice(result, func(i, j int) bool {
ki, kl := result[i].Key(), result[j].Key()
switch res := strings.Compare(ki.Package, kl.Package); {
case res < 0:
return true
case res > 0:
return false
default:
// Equal. Compare next element
}
switch res := strings.Compare(ki.Revision, kl.Revision); {
case res < 0:
return true
case res > 0:
return false
default:
// Equal. Compare next element
}
switch res := strings.Compare(string(result[i].Lifecycle()), string(result[j].Lifecycle())); {
case res < 0:
return true
case res > 0:
return false
default:
// Equal. Compare next element
}

return strings.Compare(result[i].KubeObjectName(), result[j].KubeObjectName()) < 0
})
return result
}

0 comments on commit 5abfb37

Please sign in to comment.