如何知道多个存储库已重命名为新名称?

How to know the new names that multiple repositories have been renamed to?

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

  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 获取每个存储库的存储库信息,然后获取新名称。但这需要为每个回购发送请求。我的问题是 if there is any method to get the new names for a list of repos in one request?

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

我尝试使用 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
        }
      ]
    }
  ]
}

有人可以帮忙吗?谢谢。

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

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