iAmoric
iAmoric

Reputation: 1975

Github API: List the last N public repositories

I would like to get the 'n' last public repositories from Github, using their API (here)

I'm trying to understand how List all public repositories endpoint works, especially the since parameter.

What's this parameter? Will that return me a list of repositories whose id is greater than the since value?

How can I use it in order to get the 'n' last public repositories? For example, I would like to list the 50 last public repositories.

Upvotes: 1

Views: 275

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45503

You can use Github search api with the parameters is:public created:>2018-04-28:18:00:00Z to get all public repositories created after a specific date. You can pick the datetime of last hour. If you have less than 50 repositories returned just set 2 hour back for instance

Using GraphQL API v4 :

{
  search(query: "is:public created:>2018-04-28T18:00:00Z", type: REPOSITORY, last: 50) {
    repositoryCount
    pageInfo {
      endCursor
      startCursor
    }
    edges {
      node {
        ... on Repository {
          name
          createdAt
        }
      }
    }
  }
}

You will have to make the sort by createdAt on your side because there are no sort by created date (only by author-date and commiter date check this)

Try it in the explorer

For Rest API v3

Use https://api.github.com/search/repositories?q=is:public%20created:%3E2018-04-28T18:00:00Z and traversing pagination with the Link header

Upvotes: 2

Related Questions