Any way to get authenticated user's fork of a given repo?

schema-request

#1

Is there a way to a) check if the current user has a fork of a specific repo and b) get its nameWithOwner?

The closest we got was to get all current user’s repos that are forks, but a) that seems inefficient and b) in theory there could be more than 100 and pagination is a pain.


#2

Is there a way to a) check if the current user has a fork of a specific repo and b) get its nameWithOwner?

I don’t think there’s a way to do this purely from GraphQL. As you pointed out we could enumerate a user’s forked repositories and see if it’s in there. Another approach would be something like this:

query {
  repository(owner:"bswinnerton", name:"tmk_keyboard") {
    isFork
    parent {
      nameWithOwner
    }
  }
}

Where owner would be the user in question and name would be the name of the forked repository. This would return either:

  1. "repository": null: if there is no repository of that name
  2. "repository": {"isFork": false} if there is a repository of that name but it is not a fork
  3. Something like:
    {
      "data": {
        "repository": {
          "isFork": true,
          "parent": {
            "nameWithOwner": "tmk/tmk_keyboard"
          }
        }
      }
    }
    

In which case you could verify that the nameWithOwner of the parent is the actual parent you’re looking for. But this would all need to be done in your own application code.

If you were looking for a more definitive answer from GraphQL, we may be able to add a owner argument to the repository.forks connection with something like this:

query {
  repository(owner:"tmk_keyboard", name:"tmk_keyboard") {
    forks(owner:"bswinnerton") {
      edges {
        node {
          nameWithOwner
        }
      }
    }
  }
}

But it may take a little while to get this work prioritized on our end.


#3

With the proposed approach, we need to know what the name of the forked repo is. But, that is not known given the name of the upstream repo (as the user could rename their fork).

So, it would be great if you could add an owner argument to the repository.forks connections as that would solve the issue of not knowing the fork’s name.


#4

:+1:. I’ve marked this as a schema request and added it to our internal tracker for prioritization. We’ll update you here as soon as we have more to share.