aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorSamuel FORESTIER <HorlogeSkynet@users.noreply.github.com>2023-03-19 14:19:37 +0000
committerGitHub <noreply@github.com>2023-03-19 15:19:37 +0100
commitdbdb5ba33eeecf788650e6c1c675abc602d836b5 (patch)
tree17e77f37549e88ec290a91197bb01b8164b29ed7 /routers
parent1a4efa0ee9a49d48549be7479a46be133b9bc260 (diff)
downloadgitea-dbdb5ba33eeecf788650e6c1c675abc602d836b5.tar.gz
gitea-dbdb5ba33eeecf788650e6c1c675abc602d836b5.zip
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 <lauris@nix.lv>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/packages/pypi/pypi.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/routers/api/packages/pypi/pypi.go b/routers/api/packages/pypi/pypi.go
index 609c63dc64..2f71801a8f 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