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

[MAINT]: {origin} in asset upload seems dubious #505

Open
1 task done
ggreif opened this issue Feb 1, 2023 · 4 comments
Open
1 task done

[MAINT]: {origin} in asset upload seems dubious #505

ggreif opened this issue Feb 1, 2023 · 4 comments
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects

Comments

@ggreif
Copy link

ggreif commented Feb 1, 2023

Describe the need

See https://github.com/octokit/types.ts/blob/main/src/generated/Endpoints.ts#L5211

If I follow to the documentation link https://docs.github.com/rest/reference/repos#upload-a-release-asset
the {origin} path segment is not mentioned at all.

Also there are no other URL templates with such a segment.

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ggreif ggreif added Status: Triage This is being looked at and prioritized Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR labels Feb 1, 2023
@ghost ghost added this to Maintenance in JS Feb 1, 2023
@gr2m
Copy link
Contributor

gr2m commented Feb 1, 2023

It's a special case. You can see in the docs that the domain for uploading assets is uploads.github.com, not api.github.com. For GHES it's <GHES origin>/api/uploads I think. But as per the documention, you should

Use the upload_url returned in the response of the Create a release endpoint to upload a release asset.

@gr2m gr2m added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR Status: Triage This is being looked at and prioritized labels Feb 1, 2023
@ghost ghost moved this from Maintenance to Support in JS Feb 1, 2023
@ggreif
Copy link
Author

ggreif commented Feb 2, 2023

Thanks! That clarifies it. The upload_url is passed here:
https://github.com/svenstaro/upload-release-action/blob/master/src/main.ts#L100

@gr2m
Copy link
Contributor

gr2m commented Feb 3, 2023

If you set url, you don't need to set a route, it gets overwritten. I think you want to do this

  const uploaded_asset: UploadAssetResp = await octokit.request({
    ...repo(),
    method: 'POST',
    url: release.data.upload_url,
    release_id: release.data.id,
    name: asset_name,
    data: file_bytes,
    headers: {
      'content-type': 'binary/octet-stream',
      'content-length': file_size
    }
  })

The content-length header should be set for you automatically by fetch which is used for requests under the hood

@ggreif
Copy link
Author

ggreif commented Feb 3, 2023

@gr2m thanks! Is the data: '@' + file,-style specification of the source expected to work? (I didn't succeed to make it work).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Status: 🔥 Backlog
JS
  
Support
Development

No branches or pull requests

2 participants