skywinder
skywinder

Reputation: 21426

Get all tags from GitHub repository

I use GitHub api, that described here: GET /repos/:owner/:repo/tags

The command looks like:

curl https://api.github.com/repos/skywinder/ActionSheetPicker-3.0/tags

But this command get only last 30 tags.

Is it possible to receive all tags from GitHub repo?

Upvotes: 2

Views: 1854

Answers (2)

Matt Dressel
Matt Dressel

Reputation: 2194

Definitely pagination as the first answer indicates. The default pagination is 30 per page. You can tweak this to return up to 100 per page, by passing in the per_page parameter.

Although there is no API command to return all records at once, I would recommend looking at how the GitHub ruby client implements its auto_paginate feature and/or the oktokit.js paginate method and/or the API documentation regarding a custom js pagination implementation.

I'll use the ruby client implementation as an example. It defaults to the standard pagination, but this can be overridden by calling client.auto_paginate = true

When auto_paginate is true and pagination is applied to a given endpoint, the client will:

  1. Set per_page to the max of 100
  2. Fetch the first 100
  3. If the response contains header links to rel['next'], it means there's another page to fetch.
  4. Continue fetching while there are more pages AND you have not reached the API rate limit (typically, 5000 per hour)

Note, you can check your rate limit status by calling the https://api.github.com/rate_limit endpoint and checking rate.remaining. If you hit the limit, you will get an error and need to wait until the rate.reset time.

Upvotes: 0

Ivan Zuzak
Ivan Zuzak

Reputation: 18782

I'm guessing you're getting trolled by pagination:

https://docs.github.com/en/rest/overview/resources-in-the-rest-api#pagination

API responses contain links to fetch other pages of the list.

Upvotes: 4

Related Questions