简体   繁体   English

用于检索通过问题评论上传的文件的 GitHub API

[英]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 ?那么这个 API 调用会检索数据吗,特别是如果 repo 是私有的
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'
})

There is no REST API endpoint to retrieve files that have been uploaded to a comment.没有 REST API 端点来检索已上传到评论的文件。 The API call you mentioned ( GET /repos/{owner}/{repo}/contents/{path} ) is used to retrieve contents of the repository's source files only.您提到的 API 调用( GET /repos/{owner}/{repo}/contents/{path} )仅用于检索存储库源文件的内容。

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") .提取 URL ( https://github.com/keita-makino/so-63841841/files/5220043/file.xlsx ) 并使用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.我不确定这是否适用于私有存储库,因为亚马逊 S3 的重定向 URL 可能需要仅适用于浏览器的身份验证。

I'd also recommend to contact GitHub support: https://support.github.com/contact .我还建议联系 GitHub 支持: 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也许他们正计划为通过评论上传的文件添加 REST API 端点,也许已经有一种使用 GraphQL 端点的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM