You can also use the GitHub GraphQL API:
PRO: get only what you need without any clutter by specifying only the fields you need.
CON: You need to get the GraphQL node ids first, which is a bit complicated and still requires multiple calls.
Get the repository ID like this:
{
repository(owner: "github", name: "gitignore") {
databaseId
id
name
nameWithOwner
}
}
Response:
{
"data": {
"repository": {
"databaseId": 1062897,
"id": "MDEwOlJlcG9zaXRvcnkxMDYyODk3",
"name": "gitignore",
"nameWithOwner": "github/gitignore"
}
}
}
- get "owner" + "name" directly from the GitHub URL in your browser: https://github.com/github/gitignore
databaseId
is the integer id field you also get from the REST API
id
is a base64 encoded representation of the databaseId
- find all possible fields in the GraphQL docs
If you decode MDEwOlJlcG9zaXRvcnkxMDYyODk3
with base64 you get 010:Repository1062897
. You can read more what this means in this github community discussion.
Now you can get multiple repositories in a single call:
You need to use global node IDs (GraphQL docs):
{
nodes(ids: ["MDEwOlJlcG9zaXRvcnkxMDYyODk3", "MDEwOlJlcG9zaXRvcnk3NjkxNjMx"]) {
... on Repository {
databaseId
nameWithOwner
createdAt
}
}
}
Result:
{
"data": {
"nodes": [
{
"databaseId": 7691631,
"nameWithOwner": "moby/moby",
"createdAt": "2013-01-18T18:10:57Z"
},
{
"databaseId": 1062897,
"nameWithOwner": "github/gitignore",
"createdAt": "2010-11-08T20:17:14Z"
}
]
}
}
Unfortunately, the databaseIds don't work on nodes
.
GET
s then. – Infestation