【问题标题】:“Validation failed” error on searching in private repository with installation of GitHub App安装 GitHub 应用程序在私有存储库中搜索时出现“验证失败”错误
【发布时间】:2021-07-07 05:57:45
【问题描述】:

我创建了一个 GitHub 应用程序并将其安装在我的帐户中,使其能够访问我帐户中的私有存储库。 GitHub 应用程序具有元数据的读取权限。 然后,我按照此处的步骤生成了一个 JWT 并使用它来创建安装访问令牌。 我尝试使用这个令牌在上面的私有存储库中使用 GitHub 搜索 API 搜索关键字,如下所示:

https://api.github.com/search/code?q=abc+in:file+repo:username/private-repo

但是,这会返回以下响应。

{
    "message": "Validation Failed",
    "errors": [
        {
            "message": "The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.",
            "resource": "Search",
            "field": "q",
            "code": "invalid"
        }
    ],
    "documentation_url": "https://docs.github.com/v3/search/"
}

我尝试使用此访问令牌来获取此 GitHub 应用安装的存储库,并在响应中成功返回了私有存储库。我认为这意味着安装可以访问私有仓库并且令牌按预期工作。 使用的 API:https://api.github.com/installation/repositories

那为什么搜索会失败呢?

【问题讨论】:

    标签: github-api-v3 octokit.net github-app


    【解决方案1】:

    通过 GitHub 支持提出票证。他们的回应:

    查询失败,因为 GitHub 应用没有权限 read 私有仓库的内容。元数据read 权限将允许您搜索存储库,但没有 read 存储库内容的足够范围(私有)。

    docs 在元数据下列出搜索 API,但它应该在内容权限下。向 GitHub 应用授予 Content read 权限解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2019-05-03
      • 2021-11-24
      • 2021-12-13
      • 2022-11-04
      • 2015-02-07
      • 1970-01-01
      • 2012-01-14
      • 2015-07-19
      • 2011-07-09
      相关资源
      最近更新 更多