From 0e885b86702253fe4da413fa5de746c4fe942659 Mon Sep 17 00:00:00 2001 From: Samuel FORESTIER Date: Fri, 17 Mar 2023 20:36:38 +0000 Subject: [PATCH] Sort Python package descriptors by version to mimic PyPI format --- routers/api/packages/pypi/pypi.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/routers/api/packages/pypi/pypi.go b/routers/api/packages/pypi/pypi.go index 609c63dc64f5a..d8c9accb65c37 100644 --- a/routers/api/packages/pypi/pypi.go +++ b/routers/api/packages/pypi/pypi.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "regexp" + "sort" "strings" packages_model "code.gitea.io/gitea/models/packages" @@ -62,6 +63,11 @@ func PackageMetadata(ctx *context.Context) { return } + // sort package descriptors by version to mimic PyPI format + sort.Slice(pds, func(i, j int) bool { + return strings.Compare(pds[i].Version.Version, pds[j].Version.Version) < 0 + }) + ctx.Data["RegistryURL"] = setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/pypi" ctx.Data["PackageDescriptor"] = pds[0] ctx.Data["PackageDescriptors"] = pds