How to get a source repository of a fork repository


#1

Currently it is possible to fetch a parent repository of a fork. Is there a way to fetch a root repository with a single query?


#2

Hi @akosyakov,

Yes, this is possible! Here’s a query that should work:

{
  repository(owner: "josh", name: "rails") {
    nameWithOwner
    url
    parent {
      nameWithOwner
      url
    }
  }
}

#3

@kytrinyx it fetches only a parent of a fork, not a root repository.
If there are 3 repos A, B, C where B is fork of A and C is a fork of B then B is a parent of C and A is a root of all forks. My question is how to get A from C.


#4

@akosyakov, this seems to work:

{
  repository(owner: "AlexTugarev", name: "vscode-languageserver-node") {
    nameWithOwner
    url
    parent {
      nameWithOwner
      url
      parent {
      	nameWithOwner
      	url
        parent {
          nameWithOwner
          url
        }
      }
    }
  }
}

it returns you:

{
  "data": {
    "repository": {
      "nameWithOwner": "AlexTugarev/vscode-languageserver-node",
      "url": "https://github.com/AlexTugarev/vscode-languageserver-node",
      "parent": {
        "nameWithOwner": "gorkem/vscode-languageserver-node",
        "url": "https://github.com/gorkem/vscode-languageserver-node",
        "parent": {
          "nameWithOwner": "Microsoft/vscode-languageserver-node",
          "url": "https://github.com/Microsoft/vscode-languageserver-node",
          "parent": null
        }
      }
    }
  }
}

#5

@AlexTugarev It does not necessarily return a source, but some parent if a fork is very deep. Also, it requires loading multiple nodes. I was looking for something like:

{
  repository(owner: "AlexTugarev", name: "vscode-languageserver-node") {
    nameWithOwner
    url
    source {
      nameWithOwner
      url
    }
  }
}