Skip to content

Commit d6de786

Browse files
committed
Merge branch 'main' into lunny/refactor_org_setting
2 parents 33075e7 + f88800d commit d6de786

File tree

5 files changed

+185
-58
lines changed

5 files changed

+185
-58
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

options/locale/locale_ga-IE.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,8 @@ settings.hooks_desc=Déanann Crúcaí Gréasán iarratais HTTP POST go huathoibr
23342334
settings.webhook_deletion=Bain Crúca Gréasán
23352335
settings.webhook_deletion_desc=Scriostar a shocruithe agus a stair seachadta a bhaineann le Crúca Gréasán a bhaint. Lean ar aghaidh?
23362336
settings.webhook_deletion_success=Tá an Crúca Gréasán bainte amach.
2337+
settings.webhook.test_delivery=Imeacht Brúigh Tástála
2338+
settings.webhook.test_delivery_desc=Déan tástáil ar an webhook seo le teagmhas brú bréige.
23372339
settings.webhook.test_delivery_desc_disabled=Chun an Crúca Gréasán seo a thástáil le himeacht bhréige, gníomhachtaigh é.
23382340
settings.webhook.request=Iarratas
23392341
settings.webhook.response=Freagra

routers/api/packages/nuget/api_v3.go

Lines changed: 101 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,23 @@ type RegistrationIndexPageItem struct {
5353
// https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#catalog-entry
5454
type CatalogEntry struct {
5555
CatalogLeafURL string `json:"@id"`
56-
PackageContentURL string `json:"packageContent"`
56+
Authors string `json:"authors"`
57+
Copyright string `json:"copyright"`
58+
DependencyGroups []*PackageDependencyGroup `json:"dependencyGroups"`
59+
Description string `json:"description"`
60+
IconURL string `json:"iconUrl"`
5761
ID string `json:"id"`
62+
IsPrerelease bool `json:"isPrerelease"`
63+
Language string `json:"language"`
64+
LicenseURL string `json:"licenseUrl"`
65+
PackageContentURL string `json:"packageContent"`
66+
ProjectURL string `json:"projectUrl"`
67+
RequireLicenseAcceptance bool `json:"requireLicenseAcceptance"`
68+
Summary string `json:"summary"`
69+
Tags string `json:"tags"`
5870
Version string `json:"version"`
59-
Description string `json:"description"`
6071
ReleaseNotes string `json:"releaseNotes"`
61-
Authors string `json:"authors"`
62-
RequireLicenseAcceptance bool `json:"requireLicenseAcceptance"`
63-
ProjectURL string `json:"projectURL"`
64-
DependencyGroups []*PackageDependencyGroup `json:"dependencyGroups"`
72+
Published time.Time `json:"published"`
6573
}
6674

6775
// https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#package-dependency-group
@@ -109,15 +117,24 @@ func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageD
109117
RegistrationLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
110118
PackageContentURL: l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version),
111119
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),
120+
CatalogLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
121+
Authors: metadata.Authors,
122+
Copyright: metadata.Copyright,
123+
DependencyGroups: createDependencyGroups(pd),
124+
Description: metadata.Description,
125+
IconURL: metadata.IconURL,
126+
ID: pd.Package.Name,
127+
IsPrerelease: pd.Version.IsPrerelease(),
128+
Language: metadata.Language,
129+
LicenseURL: metadata.LicenseURL,
130+
PackageContentURL: l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version),
131+
ProjectURL: metadata.ProjectURL,
132+
RequireLicenseAcceptance: metadata.RequireLicenseAcceptance,
133+
Summary: metadata.Summary,
134+
Tags: metadata.Tags,
135+
Version: pd.Version.Version,
136+
ReleaseNotes: metadata.ReleaseNotes,
137+
Published: pd.Version.CreatedUnix.AsLocalTime(),
121138
},
122139
}
123140
}
@@ -145,22 +162,42 @@ func createDependencyGroups(pd *packages_model.PackageDescriptor) []*PackageDepe
145162

146163
// https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#registration-leaf
147164
type RegistrationLeafResponse struct {
148-
RegistrationLeafURL string `json:"@id"`
149-
Type []string `json:"@type"`
150-
Listed bool `json:"listed"`
151-
PackageContentURL string `json:"packageContent"`
152-
Published time.Time `json:"published"`
153-
RegistrationIndexURL string `json:"registration"`
165+
RegistrationLeafURL string `json:"@id"`
166+
Type []string `json:"@type"`
167+
PackageContentURL string `json:"packageContent"`
168+
RegistrationIndexURL string `json:"registration"`
169+
CatalogEntry CatalogEntry `json:"catalogEntry"`
154170
}
155171

156172
func createRegistrationLeafResponse(l *linkBuilder, pd *packages_model.PackageDescriptor) *RegistrationLeafResponse {
173+
registrationLeafURL := l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version)
174+
packageDownloadURL := l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version)
175+
metadata := pd.Metadata.(*nuget_module.Metadata)
157176
return &RegistrationLeafResponse{
158-
Type: []string{"Package", "http://schema.nuget.org/catalog#Permalink"},
159-
Listed: true,
160-
Published: pd.Version.CreatedUnix.AsLocalTime(),
161-
RegistrationLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
162-
PackageContentURL: l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version),
177+
RegistrationLeafURL: registrationLeafURL,
163178
RegistrationIndexURL: l.GetRegistrationIndexURL(pd.Package.Name),
179+
PackageContentURL: packageDownloadURL,
180+
Type: []string{"Package", "http://schema.nuget.org/catalog#Permalink"},
181+
CatalogEntry: CatalogEntry{
182+
CatalogLeafURL: registrationLeafURL,
183+
Authors: metadata.Authors,
184+
Copyright: metadata.Copyright,
185+
DependencyGroups: createDependencyGroups(pd),
186+
Description: metadata.Description,
187+
IconURL: metadata.IconURL,
188+
ID: pd.Package.Name,
189+
IsPrerelease: pd.Version.IsPrerelease(),
190+
Language: metadata.Language,
191+
LicenseURL: metadata.LicenseURL,
192+
PackageContentURL: packageDownloadURL,
193+
ProjectURL: metadata.ProjectURL,
194+
RequireLicenseAcceptance: metadata.RequireLicenseAcceptance,
195+
Summary: metadata.Summary,
196+
Tags: metadata.Tags,
197+
Version: pd.Version.Version,
198+
ReleaseNotes: metadata.ReleaseNotes,
199+
Published: pd.Version.CreatedUnix.AsLocalTime(),
200+
},
164201
}
165202
}
166203

@@ -188,13 +225,24 @@ type SearchResultResponse struct {
188225

189226
// https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result
190227
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"`
228+
Authors string `json:"authors"`
229+
Copyright string `json:"copyright"`
230+
DependencyGroups []*PackageDependencyGroup `json:"dependencyGroups"`
231+
Description string `json:"description"`
232+
IconURL string `json:"iconUrl"`
233+
ID string `json:"id"`
234+
IsPrerelease bool `json:"isPrerelease"`
235+
Language string `json:"language"`
236+
LicenseURL string `json:"licenseUrl"`
237+
ProjectURL string `json:"projectUrl"`
238+
RequireLicenseAcceptance bool `json:"requireLicenseAcceptance"`
239+
Summary string `json:"summary"`
240+
Tags string `json:"tags"`
241+
Title string `json:"title"`
242+
TotalDownloads int64 `json:"totalDownloads"`
243+
Version string `json:"version"`
244+
Versions []*SearchResultVersion `json:"versions"`
245+
RegistrationIndexURL string `json:"registration"`
198246
}
199247

200248
// https://docs.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result
@@ -230,11 +278,12 @@ func createSearchResultResponse(l *linkBuilder, totalHits int64, pds []*packages
230278
func createSearchResult(l *linkBuilder, pds []*packages_model.PackageDescriptor) *SearchResult {
231279
latest := pds[0]
232280
versions := make([]*SearchResultVersion, 0, len(pds))
281+
totalDownloads := int64(0)
233282
for _, pd := range pds {
234283
if latest.SemVer.LessThan(pd.SemVer) {
235284
latest = pd
236285
}
237-
286+
totalDownloads += pd.Version.DownloadCount
238287
versions = append(versions, &SearchResultVersion{
239288
RegistrationLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
240289
Version: pd.Version.Version,
@@ -244,12 +293,23 @@ func createSearchResult(l *linkBuilder, pds []*packages_model.PackageDescriptor)
244293
metadata := latest.Metadata.(*nuget_module.Metadata)
245294

246295
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),
296+
Authors: metadata.Authors,
297+
Copyright: metadata.Copyright,
298+
Description: metadata.Description,
299+
DependencyGroups: createDependencyGroups(latest),
300+
IconURL: metadata.IconURL,
301+
ID: latest.Package.Name,
302+
IsPrerelease: latest.Version.IsPrerelease(),
303+
Language: metadata.Language,
304+
LicenseURL: metadata.LicenseURL,
305+
ProjectURL: metadata.ProjectURL,
306+
RequireLicenseAcceptance: metadata.RequireLicenseAcceptance,
307+
Summary: metadata.Summary,
308+
Tags: metadata.Tags,
309+
Title: metadata.Title,
310+
TotalDownloads: totalDownloads,
311+
Version: latest.Version.Version,
312+
Versions: versions,
313+
RegistrationIndexURL: l.GetRegistrationIndexURL(latest.Package.Name),
254314
}
255315
}

0 commit comments

Comments
 (0)