Skip to content

Commit dbdb5ba

Browse files
Sort Python package descriptors by version to mimic PyPI format (#23550)
--- Hi, very naive and **untested** first time ever Go code, feel free to reject/edit this as needed. (PyPI actually performs "naive" string comparison too) --------- Co-authored-by: Lauris BH <[email protected]>
1 parent 1a4efa0 commit dbdb5ba

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

routers/api/packages/pypi/pypi.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"net/http"
1010
"regexp"
11+
"sort"
1112
"strings"
1213

1314
packages_model "code.gitea.io/gitea/models/packages"
@@ -62,6 +63,11 @@ func PackageMetadata(ctx *context.Context) {
6263
return
6364
}
6465

66+
// sort package descriptors by version to mimic PyPI format
67+
sort.Slice(pds, func(i, j int) bool {
68+
return strings.Compare(pds[i].Version.Version, pds[j].Version.Version) < 0
69+
})
70+
6571
ctx.Data["RegistryURL"] = setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/pypi"
6672
ctx.Data["PackageDescriptor"] = pds[0]
6773
ctx.Data["PackageDescriptors"] = pds

0 commit comments

Comments
 (0)