mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-11 15:58:30 +00:00
chore: enable forcetypeassert linter, fix issues (#38804)
Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert) linter to prevent unchecked type assertions. ~650 issues fixed, most fixes were clean, some use `setting.PanicInDevOrTesting`. The only behaviour changes are where code would previously send a 500 error or panic, a 4xx error is now emitted. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -127,7 +127,7 @@ func SearchPackages(ctx *context.Context) {
|
||||
crates = append(crates, &SearchResultCrate{
|
||||
Name: pd.Package.Name,
|
||||
LatestVersion: pd.Version.Version,
|
||||
Description: pd.Metadata.(*cargo_module.Metadata).Description,
|
||||
Description: packages_model.DescriptorMetadata[*cargo_module.Metadata](pd).Description,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,12 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := verifySignedHeaders(req, version, pub.(*rsa.PublicKey)); err != nil {
|
||||
rsaPub, ok := pub.(*rsa.PublicKey)
|
||||
if !ok {
|
||||
return nil, errors.New("public key is not a RSA key")
|
||||
}
|
||||
|
||||
if err := verifySignedHeaders(req, version, rsaPub); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func PackagesUniverse(ctx *context.Context) {
|
||||
LocationType: "opscode",
|
||||
LocationPath: baseURL,
|
||||
DownloadURL: fmt.Sprintf("%s/cookbooks/%s/versions/%s/download", baseURL, url.PathEscape(pd.Package.Name), pd.Version.Version),
|
||||
Dependencies: pd.Metadata.(*chef_module.Metadata).Dependencies,
|
||||
Dependencies: packages_model.DescriptorMetadata[*chef_module.Metadata](pd).Dependencies,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func EnumeratePackages(ctx *context.Context) {
|
||||
|
||||
items := make([]*Item, 0, len(pds))
|
||||
for _, pd := range pds {
|
||||
metadata := pd.Metadata.(*chef_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*chef_module.Metadata](pd)
|
||||
|
||||
items = append(items, &Item{
|
||||
CookbookName: pd.Package.Name,
|
||||
@@ -193,7 +193,7 @@ func PackageMetadata(ctx *context.Context) {
|
||||
|
||||
latest := pds[len(pds)-1]
|
||||
|
||||
metadata := latest.Metadata.(*chef_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*chef_module.Metadata](latest)
|
||||
|
||||
ctx.JSON(http.StatusOK, &Result{
|
||||
Name: latest.Package.Name,
|
||||
@@ -241,7 +241,7 @@ func PackageVersionMetadata(ctx *context.Context) {
|
||||
|
||||
baseURL := fmt.Sprintf("%sapi/packages/%s/chef/api/v1/cookbooks/%s", setting.AppURL, ctx.Package.Owner.Name, url.PathEscape(pd.Package.Name))
|
||||
|
||||
metadata := pd.Metadata.(*chef_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*chef_module.Metadata](pd)
|
||||
|
||||
ctx.JSON(http.StatusOK, &Result{
|
||||
Version: pd.Version.Version,
|
||||
|
||||
@@ -50,7 +50,7 @@ func createSearchResultResponse(total int64, pds []*packages_model.PackageDescri
|
||||
for _, pd := range pds {
|
||||
results = append(results, &SearchResult{
|
||||
Name: pd.Package.Name,
|
||||
Description: pd.Metadata.(*composer_module.Metadata).Description,
|
||||
Description: packages_model.DescriptorMetadata[*composer_module.Metadata](pd).Description,
|
||||
Downloads: pd.Version.DownloadCount,
|
||||
})
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func createPackageMetadataResponse(ctx *context.Context, registryURL string, pds
|
||||
Version: pd.Version.Version,
|
||||
Type: packageType,
|
||||
Created: pd.Version.CreatedUnix.AsLocalTime(),
|
||||
Metadata: pd.Metadata.(*composer_module.Metadata),
|
||||
Metadata: packages_model.DescriptorMetadata[*composer_module.Metadata](pd),
|
||||
Dist: Dist{
|
||||
Type: "zip",
|
||||
URL: fmt.Sprintf("%s/files/%s/%s/%s", registryURL, url.PathEscape(pd.Package.LowerName), url.PathEscape(pd.Version.LowerVersion), url.PathEscape(pd.Files[0].File.LowerName)),
|
||||
|
||||
@@ -103,6 +103,14 @@ func ExtractPathParameters(ctx *context.Context) {
|
||||
ctx.Data[packageReferenceKey] = pref
|
||||
}
|
||||
|
||||
func getRecipeReference(ctx *context.Context) *conan_module.RecipeReference {
|
||||
return ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference) //nolint:forcetypeassert // must be valid
|
||||
}
|
||||
|
||||
func getPackageReference(ctx *context.Context) *conan_module.PackageReference {
|
||||
return ctx.Data[packageReferenceKey].(*conan_module.PackageReference) //nolint:forcetypeassert // must be valid
|
||||
}
|
||||
|
||||
// Ping reports the server capabilities
|
||||
func Ping(ctx *context.Context) {
|
||||
ctx.RespHeader().Add("X-Conan-Server-Capabilities", "revisions") // complex_search,checksum_deploy,matrix_params
|
||||
@@ -164,20 +172,20 @@ func CheckCredentials(ctx *context.Context) {
|
||||
|
||||
// RecipeSnapshot displays the recipe files with their md5 hash
|
||||
func RecipeSnapshot(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
serveSnapshot(ctx, rref.AsKey())
|
||||
}
|
||||
|
||||
// RecipeSnapshot displays the package files with their md5 hash
|
||||
func PackageSnapshot(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
serveSnapshot(ctx, pref.AsKey())
|
||||
}
|
||||
|
||||
func serveSnapshot(ctx *context.Context, fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx, ctx.Package.Owner.ID, packages_model.TypeConan, rref.Name, rref.Version)
|
||||
if err != nil {
|
||||
@@ -217,7 +225,7 @@ func serveSnapshot(ctx *context.Context, fileKey string) {
|
||||
|
||||
// RecipeDownloadURLs displays the recipe files with their download url
|
||||
func RecipeDownloadURLs(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
serveDownloadURLs(
|
||||
ctx,
|
||||
@@ -228,7 +236,7 @@ func RecipeDownloadURLs(ctx *context.Context) {
|
||||
|
||||
// PackageDownloadURLs displays the package files with their download url
|
||||
func PackageDownloadURLs(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
serveDownloadURLs(
|
||||
ctx,
|
||||
@@ -238,7 +246,7 @@ func PackageDownloadURLs(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func serveDownloadURLs(ctx *context.Context, fileKey, downloadURL string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx, ctx.Package.Owner.ID, packages_model.TypeConan, rref.Name, rref.Version)
|
||||
if err != nil {
|
||||
@@ -274,7 +282,7 @@ func serveDownloadURLs(ctx *context.Context, fileKey, downloadURL string) {
|
||||
|
||||
// RecipeUploadURLs displays the upload urls for the provided recipe files
|
||||
func RecipeUploadURLs(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
serveUploadURLs(
|
||||
ctx,
|
||||
@@ -285,7 +293,7 @@ func RecipeUploadURLs(ctx *context.Context) {
|
||||
|
||||
// PackageUploadURLs displays the upload urls for the provided package files
|
||||
func PackageUploadURLs(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
serveUploadURLs(
|
||||
ctx,
|
||||
@@ -315,21 +323,21 @@ func serveUploadURLs(ctx *context.Context, fileFilter container.Set[string], upl
|
||||
|
||||
// UploadRecipeFile handles the upload of a recipe file
|
||||
func UploadRecipeFile(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
uploadFile(ctx, recipeFileList, rref.AsKey())
|
||||
}
|
||||
|
||||
// UploadPackageFile handles the upload of a package file
|
||||
func UploadPackageFile(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
uploadFile(ctx, packageFileList, pref.AsKey())
|
||||
}
|
||||
|
||||
func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
filename := ctx.PathParam("filename")
|
||||
if !fileFilter.Contains(filename) {
|
||||
@@ -454,20 +462,20 @@ func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey
|
||||
|
||||
// DownloadRecipeFile serves the content of the requested recipe file
|
||||
func DownloadRecipeFile(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
downloadFile(ctx, recipeFileList, rref.AsKey())
|
||||
}
|
||||
|
||||
// DownloadPackageFile serves the content of the requested package file
|
||||
func DownloadPackageFile(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
downloadFile(ctx, packageFileList, pref.AsKey())
|
||||
}
|
||||
|
||||
func downloadFile(ctx *context.Context, fileFilter container.Set[string], fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
filename := ctx.PathParam("filename")
|
||||
if !fileFilter.Contains(filename) {
|
||||
@@ -503,7 +511,7 @@ func downloadFile(ctx *context.Context, fileFilter container.Set[string], fileKe
|
||||
|
||||
// DeleteRecipeV1 deletes the requested recipe(s)
|
||||
func DeleteRecipeV1(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
if err := deleteRecipeOrPackage(ctx, rref, true, nil, false); err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, conan_model.ErrPackageReferenceNotExist) {
|
||||
@@ -518,7 +526,7 @@ func DeleteRecipeV1(ctx *context.Context) {
|
||||
|
||||
// DeleteRecipeV2 deletes the requested recipe(s) respecting its revisions
|
||||
func DeleteRecipeV2(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
if err := deleteRecipeOrPackage(ctx, rref, rref.Revision == "", nil, false); err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, conan_model.ErrPackageReferenceNotExist) {
|
||||
@@ -533,7 +541,7 @@ func DeleteRecipeV2(ctx *context.Context) {
|
||||
|
||||
// DeletePackageV1 deletes the requested package(s)
|
||||
func DeletePackageV1(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
type PackageReferences struct {
|
||||
References []string `json:"package_ids"`
|
||||
@@ -582,8 +590,8 @@ func DeletePackageV1(ctx *context.Context) {
|
||||
|
||||
// DeletePackageV2 deletes the requested package(s) respecting its revisions
|
||||
func DeletePackageV2(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
if pref != nil { // has package reference
|
||||
if err := deleteRecipeOrPackage(ctx, rref, false, pref, pref.Revision == ""); err != nil {
|
||||
@@ -693,7 +701,7 @@ func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeRef
|
||||
|
||||
// ListRecipeRevisions gets a list of all recipe revisions
|
||||
func ListRecipeRevisions(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
revisions, err := conan_model.GetRecipeRevisions(ctx, ctx.Package.Owner.ID, rref)
|
||||
if err != nil {
|
||||
@@ -706,7 +714,7 @@ func ListRecipeRevisions(ctx *context.Context) {
|
||||
|
||||
// ListPackageRevisions gets a list of all package revisions
|
||||
func ListPackageRevisions(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
revisions, err := conan_model.GetPackageRevisions(ctx, ctx.Package.Owner.ID, pref)
|
||||
if err != nil {
|
||||
@@ -742,7 +750,7 @@ func listRevisions(ctx *context.Context, revisions []*conan_model.PropertyValue)
|
||||
|
||||
// LatestRecipeRevision gets the latest recipe revision
|
||||
func LatestRecipeRevision(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
revision, err := conan_model.GetLastRecipeRevision(ctx, ctx.Package.Owner.ID, rref)
|
||||
if err != nil {
|
||||
@@ -759,7 +767,7 @@ func LatestRecipeRevision(ctx *context.Context) {
|
||||
|
||||
// LatestPackageRevision gets the latest package revision
|
||||
func LatestPackageRevision(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
revision, err := conan_model.GetLastPackageRevision(ctx, ctx.Package.Owner.ID, pref)
|
||||
if err != nil {
|
||||
@@ -776,20 +784,20 @@ func LatestPackageRevision(ctx *context.Context) {
|
||||
|
||||
// ListRecipeRevisionFiles gets a list of all recipe revision files
|
||||
func ListRecipeRevisionFiles(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
listRevisionFiles(ctx, rref.AsKey())
|
||||
}
|
||||
|
||||
// ListPackageRevisionFiles gets a list of all package revision files
|
||||
func ListPackageRevisionFiles(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
listRevisionFiles(ctx, pref.AsKey())
|
||||
}
|
||||
|
||||
func listRevisionFiles(ctx *context.Context, fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx, ctx.Package.Owner.ID, packages_model.TypeConan, rref.Name, rref.Version)
|
||||
if err != nil {
|
||||
|
||||
@@ -72,7 +72,7 @@ func SearchPackagesV2(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func searchPackages(ctx *context.Context, searchAllRevisions bool) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
if !searchAllRevisions && rref.Revision == "" {
|
||||
lastRevision, err := conan_model.GetLastRecipeRevision(ctx, ctx.Package.Owner.ID, rref)
|
||||
|
||||
@@ -138,7 +138,7 @@ func EnumeratePackages(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
versionMetadata := pd.Metadata.(*conda_module.VersionMetadata)
|
||||
versionMetadata := packages_model.DescriptorMetadata[*conda_module.VersionMetadata](pd)
|
||||
|
||||
pi := &PackageInfo{
|
||||
Name: pd.PackageProperties.GetByName(conda_module.PropertyName),
|
||||
|
||||
@@ -93,7 +93,7 @@ func enumeratePackages(ctx *context.Context, format string, opts *cran_model.Sea
|
||||
}
|
||||
}
|
||||
|
||||
metadata := pd.Metadata.(*cran_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*cran_module.Metadata](pd)
|
||||
|
||||
fmt.Fprintln(w, "Package:", pd.Package.Name)
|
||||
fmt.Fprintln(w, "Version:", pd.Version.Version)
|
||||
|
||||
@@ -45,7 +45,7 @@ func createPackageMetadataResponse(registryURL string, pds []*packages_model.Pac
|
||||
|
||||
latest := pds[len(pds)-1]
|
||||
|
||||
metadata := latest.Metadata.(*npm_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*npm_module.Metadata](latest)
|
||||
|
||||
return &npm_module.PackageMetadata{
|
||||
ID: latest.Package.Name,
|
||||
@@ -67,7 +67,7 @@ func createPackageMetadataResponse(registryURL string, pds []*packages_model.Pac
|
||||
func createPackageMetadataVersion(registryURL string, pd *packages_model.PackageDescriptor) *npm_module.PackageMetadataVersion {
|
||||
hashBytes, _ := hex.DecodeString(pd.Files[0].Blob.HashSHA512)
|
||||
|
||||
metadata := pd.Metadata.(*npm_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*npm_module.Metadata](pd)
|
||||
|
||||
return &npm_module.PackageMetadataVersion{
|
||||
ID: fmt.Sprintf("%s@%s", pd.Package.Name, pd.Version.Version),
|
||||
@@ -107,7 +107,7 @@ func createPackageMetadataVersion(registryURL string, pd *packages_model.Package
|
||||
func createPackageSearchResponse(pds []*packages_model.PackageDescriptor, total int64) *npm_module.PackageSearch {
|
||||
objects := make([]*npm_module.PackageSearchObject, 0, len(pds))
|
||||
for _, pd := range pds {
|
||||
metadata := pd.Metadata.(*npm_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*npm_module.Metadata](pd)
|
||||
|
||||
scope := metadata.Scope
|
||||
if scope == "" {
|
||||
|
||||
@@ -332,12 +332,8 @@ func createFeedResponse(l *linkBuilder, totalEntries int64, pds []*packages_mode
|
||||
}
|
||||
}
|
||||
|
||||
func createEntryResponse(l *linkBuilder, pd *packages_model.PackageDescriptor) *FeedEntry {
|
||||
return createEntry(l, pd, true)
|
||||
}
|
||||
|
||||
func createEntry(l *linkBuilder, pd *packages_model.PackageDescriptor, withNamespace bool) *FeedEntry {
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](pd)
|
||||
|
||||
id := l.GetPackageMetadataURL(pd.Package.Name, pd.Version.Version)
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ func createRegistrationIndexResponse(l *linkBuilder, pds []*packages_model.Packa
|
||||
}
|
||||
|
||||
func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageDescriptor) *RegistrationIndexPageItem {
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](pd)
|
||||
|
||||
return &RegistrationIndexPageItem{
|
||||
RegistrationLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
|
||||
@@ -120,7 +120,7 @@ func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageD
|
||||
CatalogLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
|
||||
Authors: metadata.Authors,
|
||||
Copyright: metadata.Copyright,
|
||||
DependencyGroups: createDependencyGroups(pd),
|
||||
DependencyGroups: createDependencyGroups(metadata),
|
||||
Description: metadata.Description,
|
||||
IconURL: metadata.IconURL,
|
||||
ID: pd.Package.Name,
|
||||
@@ -139,9 +139,7 @@ func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageD
|
||||
}
|
||||
}
|
||||
|
||||
func createDependencyGroups(pd *packages_model.PackageDescriptor) []*PackageDependencyGroup {
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
|
||||
func createDependencyGroups(metadata *nuget_module.Metadata) []*PackageDependencyGroup {
|
||||
dependencyGroups := make([]*PackageDependencyGroup, 0, len(metadata.Dependencies))
|
||||
for k, v := range metadata.Dependencies {
|
||||
dependencies := make([]*PackageDependency, 0, len(v))
|
||||
@@ -172,7 +170,7 @@ type RegistrationLeafResponse struct {
|
||||
func createRegistrationLeafResponse(l *linkBuilder, pd *packages_model.PackageDescriptor) *RegistrationLeafResponse {
|
||||
registrationLeafURL := l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version)
|
||||
packageDownloadURL := l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version)
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](pd)
|
||||
return &RegistrationLeafResponse{
|
||||
RegistrationLeafURL: registrationLeafURL,
|
||||
RegistrationIndexURL: l.GetRegistrationIndexURL(pd.Package.Name),
|
||||
@@ -182,7 +180,7 @@ func createRegistrationLeafResponse(l *linkBuilder, pd *packages_model.PackageDe
|
||||
CatalogLeafURL: registrationLeafURL,
|
||||
Authors: metadata.Authors,
|
||||
Copyright: metadata.Copyright,
|
||||
DependencyGroups: createDependencyGroups(pd),
|
||||
DependencyGroups: createDependencyGroups(metadata),
|
||||
Description: metadata.Description,
|
||||
IconURL: metadata.IconURL,
|
||||
ID: pd.Package.Name,
|
||||
@@ -290,13 +288,13 @@ func createSearchResult(l *linkBuilder, pds []*packages_model.PackageDescriptor)
|
||||
})
|
||||
}
|
||||
|
||||
metadata := latest.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](latest)
|
||||
|
||||
return &SearchResult{
|
||||
Authors: metadata.Authors,
|
||||
Copyright: metadata.Copyright,
|
||||
Description: metadata.Description,
|
||||
DependencyGroups: createDependencyGroups(latest),
|
||||
DependencyGroups: createDependencyGroups(metadata),
|
||||
IconURL: metadata.IconURL,
|
||||
ID: latest.Package.Name,
|
||||
IsPrerelease: latest.Version.IsPrerelease(),
|
||||
|
||||
@@ -267,9 +267,10 @@ func RegistrationLeafV2(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
resp := createEntryResponse(
|
||||
resp := createEntry(
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
pd,
|
||||
true,
|
||||
)
|
||||
|
||||
xmlResponse(ctx, http.StatusOK, resp)
|
||||
|
||||
@@ -67,7 +67,7 @@ func packageDescriptorToMetadata(baseURL string, pd *packages_model.PackageDescr
|
||||
Version: pd.Version.Version,
|
||||
ArchiveURL: fmt.Sprintf("%s/files/%s.tar.gz", baseURL, url.PathEscape(pd.Version.Version)),
|
||||
Published: pd.Version.CreatedUnix.AsLocalTime(),
|
||||
Pubspec: pd.Metadata.(*pub_module.Metadata).Pubspec,
|
||||
Pubspec: packages_model.DescriptorMetadata[*pub_module.Metadata](pd).Pubspec,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ func enumeratePackages(ctx *context.Context, filename string, pvs []*packages_mo
|
||||
Name: "Gem::Version",
|
||||
Value: []string{p.Version.Version},
|
||||
},
|
||||
p.Metadata.(*rubygems_module.Metadata).Platform,
|
||||
packages_model.DescriptorMetadata[*rubygems_module.Metadata](p).Platform,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func ServePackageSpecification(ctx *context.Context) {
|
||||
zw := zlib.NewWriter(ctx.Resp)
|
||||
defer zw.Close()
|
||||
|
||||
metadata := pd.Metadata.(*rubygems_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*rubygems_module.Metadata](pd)
|
||||
|
||||
// create a Ruby Gem::Specification object
|
||||
spec := &rubygems_module.RubyUserDef{
|
||||
@@ -405,7 +405,7 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model.
|
||||
return "", err
|
||||
}
|
||||
|
||||
metadata := pd.Metadata.(*rubygems_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*rubygems_module.Metadata](pd)
|
||||
fullFilename := makeGemFullFileName(pd.Package.Name, version.Version, metadata.Platform)
|
||||
file, err := packages_model.GetFileForVersionByName(ctx, version.ID, fullFilename, "")
|
||||
if err != nil {
|
||||
|
||||
@@ -197,7 +197,7 @@ func PackageVersionMetadata(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
metadata := pd.Metadata.(*swift_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*swift_module.Metadata](pd)
|
||||
repositoryURLs := make([]string, 0, len(pd.VersionProperties))
|
||||
for _, property := range pd.VersionProperties {
|
||||
if property.Name == swift_module.PropertyRepositoryURL {
|
||||
@@ -278,7 +278,7 @@ func DownloadManifest(ctx *context.Context) {
|
||||
swiftVersion = swift_module.TrimmedVersionString(v)
|
||||
}
|
||||
}
|
||||
m, ok := pd.Metadata.(*swift_module.Metadata).Manifests[swiftVersion]
|
||||
m, ok := packages_model.DescriptorMetadata[*swift_module.Metadata](pd).Manifests[swiftVersion]
|
||||
if !ok {
|
||||
setResponseHeaders(ctx.Resp, &headers{
|
||||
Status: http.StatusSeeOther,
|
||||
|
||||
@@ -130,7 +130,7 @@ func EnumeratePackageVersions(ctx *context.Context) {
|
||||
|
||||
ctx.JSON(http.StatusOK, &packageMetadata{
|
||||
Name: pds[0].Package.Name,
|
||||
Description: pds[len(pds)-1].Metadata.(*vagrant_module.Metadata).Description,
|
||||
Description: packages_model.DescriptorMetadata[*vagrant_module.Metadata](pds[len(pds)-1]).Description,
|
||||
Versions: versions,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user