Skip to content

Commit

Permalink
Sort Python package descriptors by version to mimic PyPI format
Browse files Browse the repository at this point in the history
  • Loading branch information
HorlogeSkynet committed Mar 18, 2023
1 parent d42015e commit 0e885b8
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 0e885b8

Please sign in to comment.