【问题标题】:GitHub API to retrieve files uploaded via issue commentGitHub API 检索通过问题评论上传的文件
【发布时间】:2020-12-29 16:03:17
【问题描述】:

是否可以检索通过问题评论上传的文件? 假设我有

owner: foo
repo: bar

并且路径上有一个文件

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

那么这个 API 调用是否会检索数据,尤其是如果 repo 是私有的
我不这么认为,但不确定如何以另一种方式实现。

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

【问题讨论】:

  • 您的意思是文件路径是“github.com/foo/bar/tree/master/files/1000001/text.txt”吗? GitHub 也不允许通过问题评论上传文件。您是指使用拉取请求添加的文件吗?
  • 不,文件已经存在于路径https://github.com/foo/bar/files/1000001/text.txt 。然后请求将失败。现在我明白了,但不确定如何通过 API 检索它(甚至是否可能)。
  • 我不知道这样的 URL。我记不起https://github.com/[owner]/[repo]/files 形式的路径。你能分享一个有效的示例 URL 来下载这样的文件吗?

标签: javascript github httprequest github-api octokit


【解决方案1】:

没有 REST API 端点来检索已上传到评论的文件。您提到的 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"

提取 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") 下载。

我不确定这是否适用于私有存储库,因为到亚马逊 S3 的重定向 URL 可能需要仅适用于浏览器的身份验证。

我还建议联系 GitHub 支持:https://support.github.com/contact。也许他们正计划为使用 cmets 上传的文件添加 REST API 端点,也许已经有一种使用 GraphQL 端点的方法

【讨论】:

  • 我发送了一个请求。让我看看回复,然后给你的答案打勾。
  • 有人知道吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-11
  • 1970-01-01
相关资源
最近更新 更多