I am wondering how to get the original repository from my forked repositories.
I am using https://api.github.com/users/:user/repos?type=forks
to get the list of forked repositories. It returns various links on the forks, but I cannot find how to get the original repository.
Any idea ?
Note: something else that looping over https://api.github.com/users/:user/events
You can load a list of the forked repositories using just the endpoint you mentioned:
curl https://api.github.com/users/:user/repos?type=forks
which will return something like the following JSON feed (irrelevant informations omitted):
[
{
"id": 24328834,
"name": "repo_name",
"full_name": ":user/repo_name",
"owner": {
}
...
"url": "https://api.github.com/repos/:user/repo_name",
...
}
{
"id": 24328835,
"name": "repo_name_2",
"full_name": ":user/repo_name_2",
"owner": {
...
}
...
"url": "https://api.github.com/repos/:user/repo_name_2"
...
}
]
Then, out from the list returned, you pull out the repo_name under the name element key and use it to construct the repository url, or just refer to the url element to issue a GET request against as follows:
curl https://api.github.com/repos/:user/repo_name
that in return will give you the requested user repository informations (note that is the simplest of queried urls) from which you can retrieve:
Something like the following (here the parent is nothing but the source, i.e. the repository was forked from the original one):
{
"id": 24328834,
"name": "repo_name",
"full_name": "user/repo_name",
"owner": {
...
},
...
"parent": {
"id": 354448,
"name": "repo_name",
"full_name": "real_owner_name/repo_name",
"owner": {
...
}
}
"source": {
"id": 354448,
"name": "repo_name",
"full_name": "real_owner_name/repo_name",
"owner": {
...
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With