18

GitHub api -

For the getRepos action, you will get a list of the user's repositories.

The repository objects that are returned have some information in them. However, they don't seem to have any information about "what repository am i forked from?"

How can I get that?

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152

1 Answers1

16

In the "Get" section of the repo API, you can see two fields which address your question:

The parent and source objects are present when the repo is a fork:

  • parent is the repo this repo was forked from,
  • source is the ultimate source for the network.

When I get my fork of the git repo, I see:

curl -s "https://api.github.com/repos/VonC/git"

  "parent": {
    "id": 36502,
    "name": "git",
    "full_name": "git/git",
    "owner": {
      "login": "git",
      "id": 18133,

You can get the forked repo information by reading the content of the parent field.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 5
    I wish they would have included that in the repositories provided from the api call "getAuthUser". They include a bunch of stuff no one cares about, but leave out that important stuff. – Nicholas DiPiazza Sep 03 '13 at 14:54
  • @NicholasDiPiazza I agree: that forces you to make individual queries per repo. But considering the size of `parent` and `source` field, GitHub may have excluded them from an API call which lists *all* repos from a given user. – VonC Sep 03 '13 at 14:58
  • Given the list of Repos that came from the getAuthUser call... is there a way to get multiple {parent} {source} elements for more than one repo in a single call? – Nicholas DiPiazza Sep 03 '13 at 18:51
  • @NicholasDiPiazza from my last comment, I don't think so (not fully tested though) – VonC Sep 03 '13 at 18:54
  • My use-case: i'm using the api to get github stats to see if the user is an avid github user. One of the things you'd like to see in such a report are the repositories from the open source community they contribute to. Given that many of the users have 50+ repositories, the query quickly becomes out of hand and my api limits will die quickly. – Nicholas DiPiazza Sep 03 '13 at 18:54
  • 2
    @NicholasDiPiazza so maybe another approach is in order? http://stackoverflow.com/a/9128958/6309 perhaps? Using http://developer.github.com/v3/activity/events/types/#forkevent? – VonC Sep 03 '13 at 18:57