Get info on multiple GitHub repos given list of owner/repo names
Asked Answered
I

2

2

There is the below API endpoint which returns info on a single repo given owner/repo names:

https://developer.github.com/v3/repos/#get

GET /repos/:owner/:repo

Is there a way to batch-get info on multiple repos given multiple pairs of owner/repo names, without having to make a ton of requests?

There's the search endpoint which returns info on 100 repos at once, so seems like GitHub would allow this to a reasonable limit.

https://developer.github.com/v3/search/#search-repositories

Infestation answered 10/6, 2014 at 20:47 Comment(0)
P
2

No there isn't any way to do this. You have to make one request per repository.

Privative answered 11/6, 2014 at 13:17 Comment(2)
That's unfortunate, I'll just keep keep hammering the server with multiple http GETs then.Infestation
This answer is obsolete and not correct anymore. There are multiple way with CLI and graphQL.Draggle
D
1

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.

Draggle answered 25/11, 2023 at 19:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.