Skip to content

Commit 343d912

Browse files
committed
Adds additional NuGet package information, particularly IconURL, to bring the Gitea NuGet api more in-line with GitHub's NuGet API.
This allows fixes #21291, allowing icons to appear for NuGet packages from inside Visual Studio.
1 parent dd1fd89 commit 343d912

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
lines changed

models/packages/package_version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ type PackageVersion struct {
3737
DownloadCount int64 `xorm:"NOT NULL DEFAULT 0"`
3838
}
3939

40+
// IsPrerelease checks if the version is a prerelease version according to semantic versioning
41+
func (pv *PackageVersion) IsPrerelease() bool {
42+
if pv == nil || pv.Version == "" {
43+
return false
44+
}
45+
return strings.Contains(pv.Version, "-")
46+
}
47+
4048
// GetOrInsertVersion inserts a version. If the same version exist already ErrDuplicatePackageVersion is returned
4149
func GetOrInsertVersion(ctx context.Context, pv *PackageVersion) (*PackageVersion, error) {
4250
e := db.GetEngine(ctx)

modules/packages/nuget/metadata.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Metadata struct {
7171
ReleaseNotes string `json:"release_notes,omitempty"`
7272
RepositoryURL string `json:"repository_url,omitempty"`
7373
RequireLicenseAcceptance bool `json:"require_license_acceptance"`
74+
Summary string `json:"summary,omitempty"`
7475
Tags string `json:"tags,omitempty"`
7576
Title string `json:"title,omitempty"`
7677

@@ -105,6 +106,7 @@ type nuspecPackage struct {
105106
Readme string `xml:"readme"`
106107
ReleaseNotes string `xml:"releaseNotes"`
107108
RequireLicenseAcceptance bool `xml:"requireLicenseAcceptance"`
109+
Summary string `xml:"summary"`
108110
Tags string `xml:"tags"`
109111
Title string `xml:"title"`
110112

@@ -204,6 +206,7 @@ func ParseNuspecMetaData(archive *zip.Reader, r io.Reader) (*Package, error) {
204206
ReleaseNotes: p.Metadata.ReleaseNotes,
205207
RepositoryURL: p.Metadata.Repository.URL,
206208
RequireLicenseAcceptance: p.Metadata.RequireLicenseAcceptance,
209+
Summary: p.Metadata.Summary,
207210
Tags: p.Metadata.Tags,
208211
Title: p.Metadata.Title,
209212

routers/api/packages/nuget/api_v3.go

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ type CatalogEntry struct {
6060
ReleaseNotes string `json:"releaseNotes"`
6161
Authors string `json:"authors"`
6262
RequireLicenseAcceptance bool `json:"requireLicenseAcceptance"`
63-
ProjectURL string `json:"projectURL"`
63+
ProjectURL string `json:"projectUrl"`
64+
IconURL string `json:"iconUrl"`
6465
DependencyGroups []*PackageDependencyGroup `json:"dependencyGroups"`
6566
}
6667

@@ -109,15 +110,17 @@ func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageD
109110
RegistrationLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
110111
PackageContentURL: l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version),
111112
CatalogEntry: &CatalogEntry{
112-
CatalogLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
113-
PackageContentURL: l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version),
114-
ID: pd.Package.Name,
115-
Version: pd.Version.Version,
116-
Description: metadata.Description,
117-
ReleaseNotes: metadata.ReleaseNotes,
118-
Authors: metadata.Authors,
119-
ProjectURL: metadata.ProjectURL,
120-
DependencyGroups: createDependencyGroups(pd),
113+
CatalogLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
114+
PackageContentURL: l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version),
115+
ID: pd.Package.Name,
116+
Version: pd.Version.Version,
117+
Description: metadata.Description,
118+
ReleaseNotes: metadata.ReleaseNotes,
119+
Authors: metadata.Authors,
120+
RequireLicenseAcceptance: metadata.RequireLicenseAcceptance,
121+
ProjectURL: metadata.ProjectURL,
122+
IconURL: metadata.IconURL,
123+
DependencyGroups: createDependencyGroups(pd),
121124
},
122125
}
123126
}
@@ -188,13 +191,22 @@ type SearchResultResponse struct {
188191

189192
// https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result
190193
type SearchResult struct {
191-
ID string `json:"id"`
192-
Version string `json:"version"`
193-
Versions []*SearchResultVersion `json:"versions"`
194-
Description string `json:"description"`
195-
Authors string `json:"authors"`
196-
ProjectURL string `json:"projectURL"`
197-
RegistrationIndexURL string `json:"registration"`
194+
Authors string `json:"authors"`
195+
Copyright string `json:"copyright"`
196+
Description string `json:"description"`
197+
IconURL string `json:"iconUrl"`
198+
ID string `json:"id"`
199+
IsPrerelease bool `json:"isPrerelease"`
200+
Language string `json:"language"`
201+
LicenseURL string `json:"licenseUrl"`
202+
ProjectURL string `json:"projectUrl"`
203+
RequireLicenseAcceptance bool `json:"requireLicenseAcceptance"`
204+
Summary string `json:"summary"`
205+
Tags string `json:"tags"`
206+
Title string `json:"title"`
207+
Version string `json:"version"`
208+
Versions []*SearchResultVersion `json:"versions"`
209+
RegistrationIndexURL string `json:"registration"`
198210
}
199211

200212
// https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result
@@ -244,12 +256,21 @@ func createSearchResult(l *linkBuilder, pds []*packages_model.PackageDescriptor)
244256
metadata := latest.Metadata.(*nuget_module.Metadata)
245257

246258
return &SearchResult{
247-
ID: latest.Package.Name,
248-
Version: latest.Version.Version,
249-
Versions: versions,
250-
Description: metadata.Description,
251-
Authors: metadata.Authors,
252-
ProjectURL: metadata.ProjectURL,
253-
RegistrationIndexURL: l.GetRegistrationIndexURL(latest.Package.Name),
259+
Authors: metadata.Authors,
260+
Copyright: metadata.Copyright,
261+
Description: metadata.Description,
262+
IconURL: metadata.IconURL,
263+
ID: latest.Package.Name,
264+
IsPrerelease: latest.Version.IsPrerelease(),
265+
Language: metadata.Language,
266+
LicenseURL: metadata.LicenseURL,
267+
ProjectURL: metadata.ProjectURL,
268+
RequireLicenseAcceptance: metadata.RequireLicenseAcceptance,
269+
Summary: metadata.Summary,
270+
Tags: metadata.Tags,
271+
Title: metadata.Title,
272+
Version: latest.Version.Version,
273+
Versions: versions,
274+
RegistrationIndexURL: l.GetRegistrationIndexURL(latest.Package.Name),
254275
}
255276
}

0 commit comments

Comments
 (0)