Skip to content
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

Swift Package Manager Publishing using commandline throws error (#33990) #34068

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wgr1984
Copy link

@wgr1984 wgr1984 commented Mar 30, 2025

Fix #33990

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 30, 2025
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 30, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Mar 30, 2025
@wxiaoguang wxiaoguang marked this pull request as draft March 30, 2025 05:04
@KN4CK3R
Copy link
Member

KN4CK3R commented Apr 2, 2025

Alternative fix with minimal changes:

@@ -304,10 +304,18 @@ func UploadPackageFile(ctx *context.Context) {
 
        packageVersion := v.Core().String()
 
-       file, _, err := ctx.Req.FormFile("source-archive")
+       var file io.ReadCloser
+       multipartFile, _, err := ctx.Req.FormFile("source-archive")
        if err != nil {
-               apiError(ctx, http.StatusBadRequest, err)
-               return
+               content := ctx.Req.FormValue("source-archive")
+               if content != "" {
+                       file = io.NopCloser(strings.NewReader(content))
+               } else {
+                       apiError(ctx, http.StatusBadRequest, err)
+                       return
+               }
+       } else {
+               file = multipartFile
        }
        defer file.Close()

+ tests

@hiifong
Copy link
Member

hiifong commented Apr 3, 2025

hi @wgr1984, would you be interested in continuing to complete the pr?

@wgr1984
Copy link
Author

wgr1984 commented Apr 3, 2025 via email

@wgr1984 wgr1984 force-pushed the swift-package-manager-publishing-using-commandline-throws-error branch from a2a92fb to 6ded601 Compare April 6, 2025 19:29
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 6, 2025
@wgr1984
Copy link
Author

wgr1984 commented Apr 6, 2025

updated + test. Metadata looks good, too 👍

curl -k --location 'https://127.0.0.1:3000/api/packages/tet/swift/test/TestLib/1.3.19' \
--header 'Accept: application/vnd.swift.registry.v1+json' \
--header 'Authorization: Basic dGV0OmRlZmF1bHQ=' \
--header 'Cookie: _csrf=BuZq7gKCTbJRLox5fIJSVlw_BNI6MTc0Mzk2NDIwODc2MTI2OTAwMA; i_like_gitea=497d7722fdfa170e'

{
   "id":"test.TestLib",
   "version":"1.3.19",
   "resources":[
      {
         "name":"source-archive",
         "type":"application/zip",
         "checksum":"3d4247adb875f627f5afd3ac860ff027ede1bb45f883059d4ceb5a8a025676df"
      }
   ],
   "metadata":{
      "@context":[
         "http://schema.org/"
      ],
      "@type":"SoftwareSourceCode",
      "name":"TestLib",
      "version":"1.3.19",
      "description":"A test Swift package",
      "keywords":[
         "test",
         "swift"
      ],
      "license":"MIT",
      "author":{
         "@type":"Person"
      },
      "programmingLanguage":{
         "@type":"ComputerLanguage",
         "name":"Swift",
         "url":"https://swift.org"
      }
   }
}

image

@lunny lunny added type/bug backport/v1.23 This PR should be backported to Gitea 1.23 labels Apr 6, 2025
@wxiaoguang wxiaoguang added this to the 1.24.0 milestone Apr 7, 2025
@@ -304,10 +304,18 @@ func UploadPackageFile(ctx *context.Context) {

packageVersion := v.Core().String()

file, _, err := ctx.Req.FormFile("source-archive")
var file io.ReadCloser
multipartFile, _, err := ctx.Req.FormFile("source-archive")
if err != nil {
Copy link
Member

@hiifong hiifong Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error here I think may need to be handled separately, if it's a http.ErrMissingFile error then we need to get the file content from FromValue, otherwise it just returns an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v1.23 This PR should be backported to Gitea 1.23 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. topic/packages type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Swift Package Manager Publishing using commandline throws error
7 participants