mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00: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:
		@@ -8,6 +8,7 @@ import (
 | 
				
			|||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
 | 
						"sort"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	packages_model "code.gitea.io/gitea/models/packages"
 | 
						packages_model "code.gitea.io/gitea/models/packages"
 | 
				
			||||||
@@ -62,6 +63,11 @@ func PackageMetadata(ctx *context.Context) {
 | 
				
			|||||||
		return
 | 
							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["RegistryURL"] = setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/pypi"
 | 
				
			||||||
	ctx.Data["PackageDescriptor"] = pds[0]
 | 
						ctx.Data["PackageDescriptor"] = pds[0]
 | 
				
			||||||
	ctx.Data["PackageDescriptors"] = pds
 | 
						ctx.Data["PackageDescriptors"] = pds
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user