【问题标题】:GitHub GraphQL: Get all forks of specific repositoryGitHub GraphQL:获取特定存储库的所有分支
【发布时间】:2020-03-16 19:14:46
【问题描述】:

我想获取特定存储库的所有分支的列表。

当我在explorer 上尝试以下操作时

  repository( owner: "someOrg", name: "specificRepo"){
        name
        forkCount
        forks(first: 12){
          totalCount
          nodes{
            name
          }
        }
  }
}

它正确返回分叉计数,但在节点内部,名称只是原始 repo 名称。但我希望它给出所有分叉存储库的名称。

{
  "data": {
    "repository": {
      "name": "specificRepo",
      "forkCount": 12,
      "forks": {
        "totalCount": 1,
        "nodes": [
          {
            "name": "specificRepo",
          }
        ]
      }
    }
  }
}

【问题讨论】:

  • 你说的name是什么意思?仓库名称没有改变,nameWithOwner 是你要找的吗?
  • 分叉名称
  • 如果有人分叉了一个 repo,然后更改了他们的分叉名称

标签: github graphql fork


【解决方案1】:

今天您可以请求添加nameWithOwner 字段,甚至url。这将为您提供所需的信息。

{
  repository(
    owner: "Semantic-Org"
    name: "Semantic-Ui"
  ) {
    name
    forkCount
    forks(
      first: 12
      orderBy: { field: NAME, direction: DESC }
    ) {
      totalCount
      nodes {
        name
        nameWithOwner
        url
      }
    }
  }
}

这会给你:

{
  "data": {
    "repository": {
      "name": "Semantic-UI",
      "forkCount": 5133,
      "forks": {
        "totalCount": 4919,
        "nodes": [
          {
            "name": "Vanz-Sing-In",
            "nameWithOwner": "semantic-apps/Vanz-Sing-In",
            "url": "https://github.com/semantic-apps/Vanz-Sing-In"
          },

          etc.

        }
    }
  }
}

【讨论】:

    【解决方案2】:

    如果你 fork 一个 repo 然后更改名称,name 字段将反映更改后的名称,而不是原始名称。例如,这是Semantic-UI 的一个分支:

    {
      repository(
        owner: "Semantic-Org"
        name: "Semantic-Ui"
      ) {
        name
        forkCount
        forks(
          first: 12
          orderBy: { field: NAME, direction: DESC }
        ) {
          totalCount
          nodes {
            name
          }
        }
      }
    }
    
    {
      "data": {
        "repository": {
          "name": "Semantic-UI",
          "forkCount": 4936,
          "forks": {
            "totalCount": 4743,
            "nodes": [
              {
                "name": "WEB_JS_GUI-Semantic-UI"
              },
              {
                "name": "Vanz-Sing-In"
              },
              {
                "name": "Somewhat-Semantic-UI"
              },
              {
                "name": "semantic_1.0_experiment"
              },
              {
                "name": "semanticui"
              },
              {
                "name": "semantic.ui_main"
              },
              {
                "name": "Semantic-UI-V2"
              },
              {
                "name": "Semantic-UI-tr"
              },
              {
                "name": "Semantic-UI-tr"
              },
              {
                "name": "Semantic-UI-Stylus"
              },
              {
                "name": "Semantic-UI-pt-br"
              },
              {
                "name": "Semantic-UI-pp"
              }
            ]
          }
        }
      }
    }
    

    【讨论】:

    • hmm - 因为这是一个github graphql问题,你能提供graph ql解决方案吗?
    • @maddie 用示例更新了答案
    • 我正在寻找的解决方案将回答帖子的标题,即如何获取特定存储库的所有分支。你知道如何更改我的查询,以便我可以列出存储库的所有分支(访问分支的名称和分支的所有者)。我可以用 curl 命令做到这一点:curl GET https://api.github.com/repos/:owner/:repo/forks
    • 如果你问如何绕过限制,你不能。您一次只能获取 100 个节点。因此,除了必须对结果进行分页之外,您的原始查询很好。
    • 但是我的原始查询没有得到分叉的名称,它只返回原始存储库的名称——我想查看所有 12 个分叉的名称。这对于已更改为不同于原始存储库的名称的分叉很有用
    猜你喜欢
    • 2019-12-18
    • 2015-03-10
    • 2022-07-30
    • 2019-07-12
    • 2018-08-02
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    相关资源
    最近更新 更多