feat(nuget): add missing nuget V2 properties (#7102)
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped

- Add several missing nuget V2 properties to the API.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7102
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: jwolvers <jwolvers@noreply.codeberg.org>
Co-committed-by: jwolvers <jwolvers@noreply.codeberg.org>
This commit is contained in:
jwolvers 2025-03-04 11:26:08 +00:00 committed by Gusted
parent a9303901cf
commit 3fdc3b6f82
4 changed files with 138 additions and 13 deletions

View file

@ -49,6 +49,9 @@ func TestPackageNuGet(t *testing.T) {
Version string `xml:"Version"`
NormalizedVersion string `xml:"NormalizedVersion"`
Authors string `xml:"Authors"`
Owners string `xml:"Owners,omitempty"`
Copyright string `xml:"Copyright,omitempty"`
Language string `xml:"Language,omitempty"`
Dependencies string `xml:"Dependencies"`
Description string `xml:"Description"`
VersionDownloadCount nuget.TypedValue[int64] `xml:"VersionDownloadCount"`
@ -58,9 +61,15 @@ func TestPackageNuGet(t *testing.T) {
LastUpdated nuget.TypedValue[time.Time] `xml:"LastUpdated"`
Published nuget.TypedValue[time.Time] `xml:"Published"`
ProjectURL string `xml:"ProjectUrl,omitempty"`
LicenseURL string `xml:"LicenseUrl,omitempty"`
IconURL string `xml:"IconUrl,omitempty"`
ReleaseNotes string `xml:"ReleaseNotes,omitempty"`
RequireLicenseAcceptance nuget.TypedValue[bool] `xml:"RequireLicenseAcceptance"`
DevelopmentDependency nuget.TypedValue[bool] `xml:"DevelopmentDependency"`
Title string `xml:"Title"`
MinClientVersion string `xml:"MinClientVersion,omitempty"`
Tags string `xml:"Tags,omitempty"`
ID string `xml:"Id,omitempty"`
}
type FeedEntry struct {
@ -87,21 +96,43 @@ func TestPackageNuGet(t *testing.T) {
packageName := "test.package"
packageVersion := "1.0.3"
packageAuthors := "KN4CK3R"
packageDescription := "Gitea Test Package"
packageDescription := "Forgejo Test Package"
symbolFilename := "test.pdb"
symbolID := "d910bb6948bd4c6cb40155bcf52c3c94"
packageTitle := "Package Title"
packageLanguage := "Package Language"
packageOwners := "Package Owners"
packageCopyright := "Package Copyright"
packageProjectURL := "https://forgejo.org"
packageLicenseURL := "https://forgejo.org/docs/latest/license/"
packageIconURL := "https://codeberg.org/forgejo/governance/raw/branch/main/branding/logo/forgejo.png"
packageReleaseNotes := "Package Release Notes"
packageTags := "tag_1 tag_2 tag_3"
packageMinClientVersion := "1.0.0.0"
createPackage := func(id, version string) io.Reader {
var buf bytes.Buffer
archive := zip.NewWriter(&buf)
w, _ := archive.Create("package.nuspec")
w.Write([]byte(`<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<metadata minClientVersion="` + packageMinClientVersion + `">
<id>` + id + `</id>
<title>` + packageTitle + `</title>
<language>` + packageLanguage + `</language>
<version>` + version + `</version>
<authors>` + packageAuthors + `</authors>
<owners>` + packageOwners + `</owners>
<copyright>` + packageCopyright + `</copyright>
<developmentDependency>true</developmentDependency>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<projectUrl>` + packageProjectURL + `</projectUrl>
<licenseUrl>` + packageLicenseURL + `</licenseUrl>
<iconUrl>` + packageIconURL + `</iconUrl>
<description>` + packageDescription + `</description>
<releaseNotes>` + packageReleaseNotes + `</releaseNotes>
<tags>` + packageTags + `</tags>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Microsoft.CSharp" version="4.5.0" />
@ -115,11 +146,22 @@ func TestPackageNuGet(t *testing.T) {
nuspec := `<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<metadata minClientVersion="` + packageMinClientVersion + `">
<id>` + packageName + `</id>
<title>` + packageTitle + `</title>
<language>` + packageLanguage + `</language>
<version>` + packageVersion + `</version>
<authors>` + packageAuthors + `</authors>
<owners>` + packageOwners + `</owners>
<copyright>` + packageCopyright + `</copyright>
<developmentDependency>true</developmentDependency>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<projectUrl>` + packageProjectURL + `</projectUrl>
<licenseUrl>` + packageLicenseURL + `</licenseUrl>
<iconUrl>` + packageIconURL + `</iconUrl>
<description>` + packageDescription + `</description>
<releaseNotes>` + packageReleaseNotes + `</releaseNotes>
<tags>` + packageTags + `</tags>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Microsoft.CSharp" version="4.5.0" />
@ -325,7 +367,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
require.NoError(t, err)
assert.Equal(t, int64(414), pb.Size)
assert.Equal(t, int64(len(content)), pb.Size)
case fmt.Sprintf("%s.%s.snupkg", packageName, packageVersion):
assert.False(t, pf.IsLead)
@ -337,7 +379,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
pb, err := packages.GetBlobByID(db.DefaultContext, pf.BlobID)
require.NoError(t, err)
assert.Equal(t, int64(453), pb.Size)
assert.Equal(t, int64(len([]byte(nuspec))), pb.Size)
case symbolFilename:
assert.False(t, pf.IsLead)
@ -668,10 +710,22 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
var result FeedEntry
decodeXML(t, resp, &result)
assert.Equal(t, packageName, result.Properties.Title)
assert.Equal(t, packageName, result.Properties.ID)
assert.Equal(t, packageVersion, result.Properties.Version)
assert.Equal(t, packageAuthors, result.Properties.Authors)
assert.Equal(t, packageDescription, result.Properties.Description)
assert.Equal(t, packageTitle, result.Properties.Title)
assert.Equal(t, packageLanguage, result.Properties.Language)
assert.Equal(t, packageOwners, result.Properties.Owners)
assert.Equal(t, packageCopyright, result.Properties.Copyright)
assert.Equal(t, packageProjectURL, result.Properties.ProjectURL)
assert.Equal(t, packageLicenseURL, result.Properties.LicenseURL)
assert.Equal(t, packageIconURL, result.Properties.IconURL)
assert.Equal(t, packageReleaseNotes, result.Properties.ReleaseNotes)
assert.Equal(t, packageTags, result.Properties.Tags)
assert.Equal(t, packageMinClientVersion, result.Properties.MinClientVersion)
assert.True(t, result.Properties.DevelopmentDependency.Value)
assert.True(t, result.Properties.RequireLicenseAcceptance.Value)
assert.Equal(t, "Microsoft.CSharp:4.5.0:.NETStandard2.0", result.Properties.Dependencies)
})