GitHub GraphQL:获取特定存储库的所有分支

时间:2019-11-20 23:36:14

标签: github graphql fork

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

当我在explorer上尝试以下操作

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

它正确返回派生计数,但是在节点内部,该名称只是原始回购名称。但我希望提供所有分叉存储库的名称。

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

2 个答案:

答案 0 :(得分:1)

如果分叉存储库然后更改名称,则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"
          }
        ]
      }
    }
  }
}

答案 1 :(得分:0)

今天,您还可以请求添加 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.

        }
    }
  }
}