Skip to content

Commit

Permalink
Sort Python package descriptors by version to mimic PyPI format (#23550)
Browse files Browse the repository at this point in the history
---

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>
  • Loading branch information
HorlogeSkynet and lafriks committed Mar 19, 2023
1 parent 1a4efa0 commit dbdb5ba
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions routers/api/packages/pypi/pypi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"regexp"
"sort"
"strings"

packages_model "code.gitea.io/gitea/models/packages"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dbdb5ba

Please sign in to comment.