kemakino
kemakino

Reputation: 1122

GitHub API to retrieve files uploaded via issue comment

Is it possible to retrieve a file that is uploaded via an issue comment? Assume that I have

owner: foo
repo: bar

and there is a file on the path

https://github.com/foo/bar/files/1000001/text.txt

Then would this API call retrieve the data, especially if the repo is private?
I don't think so but not sure how to achieve it in another way.

await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
  owner: 'foo',
  repo: 'bar',
  path: 'files/1000001/text.txt'
})

Upvotes: 2

Views: 555

Answers (1)

Gregor
Gregor

Reputation: 2385

There is no REST API endpoint to retrieve files that have been uploaded to a comment. The API call you mentioned (GET /repos/{owner}/{repo}/contents/{path}) is used to retrieve contents of the repository's source files only.

const { data: { body } } = await octokit.request('GET /repos/{owner}/{repo}/issues/comments/{comment_id}', {
  owner: 'foo',
  repo: 'bar',
  comment_id: '692203785'
})
// `body` is "[file.xlsx](https://github.com/keita-makino/so-63841841/files/5220043/file.xlsx)\r\n"

Extract the URL (https://github.com/keita-makino/so-63841841/files/5220043/file.xlsx) and download it with octokit.request("https://github.com/keita-makino/so-63841841/files/5220043/file.xlsx").

I am not sure if that will work for private repositories though because the redirect URL to Amazon's S3 might require authentication that only works with browsers.

I'd also recommend to contact GitHub support: https://support.github.com/contact. Maybe the are planning on adding REST API endpoints for files uploaded with comments, and maybe there already is a way using the GraphQL endpoint

Upvotes: 1

Related Questions