【问题标题】:How to know the new names that multiple repositories have been renamed to?如何知道多个存储库已重命名的新名称?
【发布时间】:2018-01-02 16:01:53
【问题描述】:

我有一个应用程序在数据库中记录一些 GitHub 存储库的名称。以以下 3 个 repo 为例。

  1. https://github.com/zhangkun-Jser/react-experience
  2. https://github.com/zhangkun-Jser/vue-plug
  3. https://github.com/hsluoyz/casbin

但问题是我记录的 repos 可能会被重命名。比如上面三个repos已经分别改名为:

  1. https://github.com/zhangkun-Jser/react-kit
  2. https://github.com/zhangkun-Jser/FE-plugs
  3. https://github.com/casbin/casbin

我想编写一些代码来主动将数据库中的任何旧仓库名称更新为新的仓库名称。例如,将zhangkun-Jser/react-experience 更新为zhangkun-Jser/react-kit

我知道我可以使用 GitHub V3 API 获取每个 repo 的存储库信息,然后获取新名称。但这需要为每个 repo 发送请求。我的问题是if there is any method to get the new names for a list of repos in one request

注意:repos 可以来自不同的所有者,如示例中所示。

我尝试使用GraphQL API v4,但我不知道如何获取存储库列表的信息。而且 V4 API 似乎无法识别旧名称。例如,如果我发送以下请求:

{
  repository(owner: "zhangkun-Jser" name: "react-experience") {
    name
    id
  }
}

回复是:

{
  "data": {
    "repository": null
  },
  "errors": [
    {
      "message": "Could not resolve to a Repository with the name 'react-experience'.",
      "type": "NOT_FOUND",
      "path": [
        "repository"
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

有人可以帮忙吗?谢谢。

【问题讨论】:

    标签: github graphql github-api github-graphql


    【解决方案1】:

    您可以存储存储库的节点 ID 并通过 ID 查找节点:

    query { 
      repository (owner:"osowskit", name:"about") { 
        id
      },
      node(id:"MDEwOlJlcG9zaXRvcnk1NjE2NzA2OQ") {
      ... on Repository {
          id,
          name,
          nameWithOwner
        }
      }
    }
    

    【讨论】:

    • 假设我存储了多个 repos 的节点 ID(来自多个用户)。如何在一个 GraphQL 请求中查询他们的最新名称?如果我必须使用多个请求,则与 GitHub V3 API 没有区别。
    • 我很抱歉错过了这部分问题。长期策略是存储节点 ID 而不是存储库名称,以避免检测到名称更改。但是,您可以使用Alias 查找多组数据。 ``` repo1:存储库(...){},repo2:存储库(...){} ```
    猜你喜欢
    • 2011-05-02
    • 2018-03-17
    • 2014-10-02
    • 2012-04-28
    • 2023-04-06
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 2010-10-01
    相关资源
    最近更新 更多