maddie
maddie

Reputation: 1954

GitHub GraphQL: Get all forks of specific repository

I would like to get a list of all the forks of a specific repository.

When I try the following on explorer

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

It returns the fork count correctly, but inside nodes, the name is just the original repo name. But I would like it to give the names of all the forked repositories.

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

Upvotes: 1

Views: 791

Answers (2)

Rob Bos
Rob Bos

Reputation: 1471

Today you can request to add the nameWithOwner field as well and even the url. That will give you the information you need.

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

Which will give you:

{
  "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.

        }
    }
  }
}

Upvotes: 0

Daniel Rearden
Daniel Rearden

Reputation: 84687

If you fork a repo and then change the name, the name field will reflect the changed name, not the original name. For example, here's a fork of 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"
          }
        ]
      }
    }
  }
}

Upvotes: 2

Related Questions