mirror of
https://github.com/go-gitea/gitea
synced 2025-07-12 05:27:20 +00:00
Improve nuget/rubygems package registries (#34741)
1. Add some missing (optional) fields for nuget v2, and sort the fields to make it easier to maintain 2. Add missing "platform" for rubygems: `VERSION-PLATFORM` and `VERSION_PLATFORM` Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
@ -57,14 +57,24 @@ type Package struct {
|
||||
|
||||
// Metadata represents the metadata of a Nuget package
|
||||
type Metadata struct {
|
||||
Description string `json:"description,omitempty"`
|
||||
ReleaseNotes string `json:"release_notes,omitempty"`
|
||||
Readme string `json:"readme,omitempty"`
|
||||
Authors string `json:"authors,omitempty"`
|
||||
ProjectURL string `json:"project_url,omitempty"`
|
||||
RepositoryURL string `json:"repository_url,omitempty"`
|
||||
RequireLicenseAcceptance bool `json:"require_license_acceptance"`
|
||||
Dependencies map[string][]Dependency `json:"dependencies,omitempty"`
|
||||
Authors string `json:"authors,omitempty"`
|
||||
Copyright string `json:"copyright,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
DevelopmentDependency bool `json:"development_dependency,omitempty"`
|
||||
IconURL string `json:"icon_url,omitempty"`
|
||||
Language string `json:"language,omitempty"`
|
||||
LicenseURL string `json:"license_url,omitempty"`
|
||||
MinClientVersion string `json:"min_client_version,omitempty"`
|
||||
Owners string `json:"owners,omitempty"`
|
||||
ProjectURL string `json:"project_url,omitempty"`
|
||||
Readme string `json:"readme,omitempty"`
|
||||
ReleaseNotes string `json:"release_notes,omitempty"`
|
||||
RepositoryURL string `json:"repository_url,omitempty"`
|
||||
RequireLicenseAcceptance bool `json:"require_license_acceptance"`
|
||||
Tags string `json:"tags,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
|
||||
Dependencies map[string][]Dependency `json:"dependencies,omitempty"`
|
||||
}
|
||||
|
||||
// Dependency represents a dependency of a Nuget package
|
||||
@ -74,24 +84,30 @@ type Dependency struct {
|
||||
}
|
||||
|
||||
// https://learn.microsoft.com/en-us/nuget/reference/nuspec
|
||||
// https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Packaging/compiler/resources/nuspec.xsd
|
||||
type nuspecPackage struct {
|
||||
Metadata struct {
|
||||
ID string `xml:"id"`
|
||||
Version string `xml:"version"`
|
||||
Authors string `xml:"authors"`
|
||||
RequireLicenseAcceptance bool `xml:"requireLicenseAcceptance"`
|
||||
// required fields
|
||||
Authors string `xml:"authors"`
|
||||
Description string `xml:"description"`
|
||||
ID string `xml:"id"`
|
||||
Version string `xml:"version"`
|
||||
|
||||
// optional fields
|
||||
Copyright string `xml:"copyright"`
|
||||
DevelopmentDependency bool `xml:"developmentDependency"`
|
||||
IconURL string `xml:"iconUrl"`
|
||||
Language string `xml:"language"`
|
||||
LicenseURL string `xml:"licenseUrl"`
|
||||
MinClientVersion string `xml:"minClientVersion,attr"`
|
||||
Owners string `xml:"owners"`
|
||||
ProjectURL string `xml:"projectUrl"`
|
||||
Description string `xml:"description"`
|
||||
ReleaseNotes string `xml:"releaseNotes"`
|
||||
Readme string `xml:"readme"`
|
||||
PackageTypes struct {
|
||||
PackageType []struct {
|
||||
Name string `xml:"name,attr"`
|
||||
} `xml:"packageType"`
|
||||
} `xml:"packageTypes"`
|
||||
Repository struct {
|
||||
URL string `xml:"url,attr"`
|
||||
} `xml:"repository"`
|
||||
ReleaseNotes string `xml:"releaseNotes"`
|
||||
RequireLicenseAcceptance bool `xml:"requireLicenseAcceptance"`
|
||||
Tags string `xml:"tags"`
|
||||
Title string `xml:"title"`
|
||||
|
||||
Dependencies struct {
|
||||
Dependency []struct {
|
||||
ID string `xml:"id,attr"`
|
||||
@ -107,6 +123,14 @@ type nuspecPackage struct {
|
||||
} `xml:"dependency"`
|
||||
} `xml:"group"`
|
||||
} `xml:"dependencies"`
|
||||
PackageTypes struct {
|
||||
PackageType []struct {
|
||||
Name string `xml:"name,attr"`
|
||||
} `xml:"packageType"`
|
||||
} `xml:"packageTypes"`
|
||||
Repository struct {
|
||||
URL string `xml:"url,attr"`
|
||||
} `xml:"repository"`
|
||||
} `xml:"metadata"`
|
||||
}
|
||||
|
||||
@ -167,13 +191,23 @@ func ParseNuspecMetaData(archive *zip.Reader, r io.Reader) (*Package, error) {
|
||||
}
|
||||
|
||||
m := &Metadata{
|
||||
Description: p.Metadata.Description,
|
||||
ReleaseNotes: p.Metadata.ReleaseNotes,
|
||||
Authors: p.Metadata.Authors,
|
||||
Copyright: p.Metadata.Copyright,
|
||||
Description: p.Metadata.Description,
|
||||
DevelopmentDependency: p.Metadata.DevelopmentDependency,
|
||||
IconURL: p.Metadata.IconURL,
|
||||
Language: p.Metadata.Language,
|
||||
LicenseURL: p.Metadata.LicenseURL,
|
||||
MinClientVersion: p.Metadata.MinClientVersion,
|
||||
Owners: p.Metadata.Owners,
|
||||
ProjectURL: p.Metadata.ProjectURL,
|
||||
ReleaseNotes: p.Metadata.ReleaseNotes,
|
||||
RepositoryURL: p.Metadata.Repository.URL,
|
||||
RequireLicenseAcceptance: p.Metadata.RequireLicenseAcceptance,
|
||||
Dependencies: make(map[string][]Dependency),
|
||||
Tags: p.Metadata.Tags,
|
||||
Title: p.Metadata.Title,
|
||||
|
||||
Dependencies: make(map[string][]Dependency),
|
||||
}
|
||||
|
||||
if p.Metadata.Readme != "" {
|
||||
@ -227,13 +261,13 @@ func ParseNuspecMetaData(archive *zip.Reader, r io.Reader) (*Package, error) {
|
||||
func toNormalizedVersion(v *version.Version) string {
|
||||
var buf bytes.Buffer
|
||||
segments := v.Segments64()
|
||||
fmt.Fprintf(&buf, "%d.%d.%d", segments[0], segments[1], segments[2])
|
||||
_, _ = fmt.Fprintf(&buf, "%d.%d.%d", segments[0], segments[1], segments[2])
|
||||
if len(segments) > 3 && segments[3] > 0 {
|
||||
fmt.Fprintf(&buf, ".%d", segments[3])
|
||||
_, _ = fmt.Fprintf(&buf, ".%d", segments[3])
|
||||
}
|
||||
pre := v.Prerelease()
|
||||
if pre != "" {
|
||||
fmt.Fprint(&buf, "-", pre)
|
||||
_, _ = fmt.Fprint(&buf, "-", pre)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
Reference in New Issue
Block a user