0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-16 23:33:59 +01:00

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>
This commit is contained in:
Samuel FORESTIER 2023-03-19 14:19:37 +00:00 committed by GitHub
parent 1a4efa0ee9
commit dbdb5ba33e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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