-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add list generic package version/file API endpoint
#35770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
4130feb
b4efc0e
119a984
4f878a1
451a64e
b7de62b
885cd08
a9b81b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |
|
|
||
| packages_model "code.gitea.io/gitea/models/packages" | ||
| packages_module "code.gitea.io/gitea/modules/packages" | ||
| "code.gitea.io/gitea/modules/timeutil" | ||
| "code.gitea.io/gitea/routers/api/packages/helper" | ||
| "code.gitea.io/gitea/services/context" | ||
| packages_service "code.gitea.io/gitea/services/packages" | ||
|
|
@@ -22,11 +23,70 @@ var ( | |
| filenameRegex = regexp.MustCompile(`\A[-_+=:;.()\[\]{}~!@#$%^& \w]+\z`) | ||
| ) | ||
|
|
||
| // PackageFileInfo represents information about an existing package file | ||
| // swagger:model | ||
|
Comment on lines
+26
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct, I realized this during implementation but left those comments in there because I wasn't sure what the intention was for documentation. |
||
| type PackageFileInfo struct { | ||
| // Name of package file | ||
| Name string `json:"name"` | ||
| // swagger:strfmt date-time | ||
| // Date when package file was created/uploaded | ||
| CreatedUnix timeutil.TimeStamp `json:"created"` | ||
| } | ||
|
|
||
| // PackageInfo represents information about an existing package file | ||
| // swagger:model | ||
| type PackageInfo struct { | ||
| /// Version linked to package information | ||
| Version string `json:"version"` | ||
| /// Download count for files within version | ||
| DownloadCount int64 `json:"downloads"` | ||
| /// Files uploaded for package version | ||
| Files []PackageFileInfo `json:"files"` | ||
| } | ||
|
|
||
| func apiError(ctx *context.Context, status int, obj any) { | ||
| message := helper.ProcessErrorForUser(ctx, status, obj) | ||
| ctx.PlainText(status, message) | ||
| } | ||
|
|
||
| // EnumeratePackageVersions lists upload versions and their associated files | ||
| func EnumeratePackageVersions(ctx *context.Context) { | ||
| pvs, err := packages_model.GetVersionsByPackageName(ctx, ctx.Package.Owner.ID, packages_model.TypeGeneric, ctx.PathParam("packagename")) | ||
| if err != nil { | ||
| apiError(ctx, http.StatusInternalServerError, err) | ||
| return | ||
| } | ||
| if len(pvs) == 0 { | ||
| apiError(ctx, http.StatusNotFound, err) | ||
| return | ||
| } | ||
|
|
||
| var info []PackageInfo | ||
| for _, pv := range pvs { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems strange to list all versions with all files together. IIRC most APIs are designed to "list the versions, and then list the files of a version". What if there are hundreds of versions, and each version has hundreds of files? And it's unclear about how to "for example automatically downloading and deploying the latest compiled build of repos within your organization." It needs a definition for "what is 'latest'". By
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could see an organization wanting to map "latest" by any of the three which is why all of the data is returned at once whilst remaining as minimal as possible. |
||
| packageFiles, err := packages_model.GetFilesByVersionID(ctx, pv.ID) | ||
| if err != nil { | ||
| apiError(ctx, http.StatusInternalServerError, err) | ||
| return | ||
| } | ||
|
|
||
| var files []PackageFileInfo | ||
| for _, file := range packageFiles { | ||
| files = append(files, PackageFileInfo{ | ||
| Name: file.Name, | ||
| CreatedUnix: file.CreatedUnix, | ||
| }) | ||
| } | ||
|
|
||
| info = append(info, PackageInfo{ | ||
| Version: pv.Version, | ||
| DownloadCount: pv.DownloadCount, | ||
| Files: files, | ||
| }) | ||
| } | ||
|
|
||
| ctx.JSON(http.StatusOK, info) | ||
| } | ||
|
|
||
| // DownloadPackageFile serves the specific generic package. | ||
| func DownloadPackageFile(ctx *context.Context) { | ||
| s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.