Gathering detailed insights and metrics for @octokit/plugin-paginate-rest
Gathering detailed insights and metrics for @octokit/plugin-paginate-rest
Gathering detailed insights and metrics for @octokit/plugin-paginate-rest
Gathering detailed insights and metrics for @octokit/plugin-paginate-rest
Octokit plugin to paginate REST API endpoint responses
npm install @octokit/plugin-paginate-rest
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99
Supply Chain
99.6
Quality
90.4
Maintenance
100
Vulnerability
100
License
TypeScript (95.49%)
JavaScript (4.51%)
Total Downloads
1,518,307,664
Last Day
2,218,493
Last Week
12,607,781
Last Month
51,052,736
Last Year
497,307,611
MIT License
52 Stars
740 Commits
27 Forks
7 Watchers
8 Branches
23 Contributors
Updated on May 21, 2025
Latest Version
13.0.0
Package Id
@octokit/plugin-paginate-rest@13.0.0
Unpacked Size
176.14 kB
Size
19.78 kB
File Count
22
NPM Version
10.9.2
Node Version
22.15.0
Published on
May 20, 2025
Cumulative downloads
Total Downloads
Last Day
4.2%
2,218,493
Compared to previous day
Last Week
5.5%
12,607,781
Compared to previous week
Last Month
3.1%
51,052,736
Compared to previous month
Last Year
36.1%
497,307,611
Compared to previous year
1
1
Octokit plugin to paginate REST API endpoint responses
Browsers |
Load
|
---|---|
Node |
Install with
|
1const MyOctokit = Octokit.plugin(paginateRest); 2const octokit = new MyOctokit({ auth: "secret123" }); 3 4// See https://developer.github.com/v3/issues/#list-issues-for-a-repository 5const issues = await octokit.paginate("GET /repos/{owner}/{repo}/issues", { 6 owner: "octocat", 7 repo: "hello-world", 8 since: "2010-10-01", 9 per_page: 100, 10});
If you want to utilize the pagination methods in another plugin, use composePaginateRest
.
1function myPlugin(octokit, options) {
2 return {
3 allStars({owner, repo}) => {
4 return composePaginateRest(
5 octokit,
6 "GET /repos/{owner}/{repo}/stargazers",
7 {owner, repo }
8 )
9 }
10 }
11}
[!IMPORTANT] As we use conditional exports, you will need to adapt your
tsconfig.json
. See the TypeScript docs on package.json "exports".
octokit.paginate()
The paginateRest
plugin adds a new octokit.paginate()
method which accepts the same parameters as octokit.request
. Only "List ..." endpoints such as List issues for a repository are supporting pagination. Their response includes a Link header. For other endpoints, octokit.paginate()
behaves the same as octokit.request()
.
The per_page
parameter is usually defaulting to 30
, and can be set to up to 100
, which helps retrieving a big amount of data without hitting the rate limits too soon.
An optional mapFunction
can be passed to map each page response to a new value, usually an array with only the data you need. This can help to reduce memory usage, as only the relevant data has to be kept in memory until the pagination is complete.
1const issueTitles = await octokit.paginate( 2 "GET /repos/{owner}/{repo}/issues", 3 { 4 owner: "octocat", 5 repo: "hello-world", 6 since: "2010-10-01", 7 per_page: 100, 8 }, 9 (response) => response.data.map((issue) => issue.title), 10);
The mapFunction
gets a 2nd argument done
which can be called to end the pagination early.
1const issues = await octokit.paginate( 2 "GET /repos/{owner}/{repo}/issues", 3 { 4 owner: "octocat", 5 repo: "hello-world", 6 since: "2010-10-01", 7 per_page: 100, 8 }, 9 (response, done) => { 10 if (response.data.find((issue) => issue.title.includes("something"))) { 11 done(); 12 } 13 return response.data; 14 }, 15);
Alternatively you can pass a request
method as first argument. This is great when using in combination with @octokit/plugin-rest-endpoint-methods
:
1const issues = await octokit.paginate(octokit.rest.issues.listForRepo, { 2 owner: "octocat", 3 repo: "hello-world", 4 since: "2010-10-01", 5 per_page: 100, 6});
octokit.paginate.iterator()
If your target runtime environments supports async iterators (such as most modern browsers and Node 10+), you can iterate through each response
1const parameters = { 2 owner: "octocat", 3 repo: "hello-world", 4 since: "2010-10-01", 5 per_page: 100, 6}; 7for await (const response of octokit.paginate.iterator( 8 "GET /repos/{owner}/{repo}/issues", 9 parameters, 10)) { 11 // do whatever you want with each response, break out of the loop, etc. 12 const issues = response.data; 13 console.log("%d issues found", issues.length); 14}
Alternatively you can pass a request
method as first argument. This is great when using in combination with @octokit/plugin-rest-endpoint-methods
:
1const parameters = { 2 owner: "octocat", 3 repo: "hello-world", 4 since: "2010-10-01", 5 per_page: 100, 6}; 7for await (const response of octokit.paginate.iterator( 8 octokit.rest.issues.listForRepo, 9 parameters, 10)) { 11 // do whatever you want with each response, break out of the loop, etc. 12 const issues = response.data; 13 console.log("%d issues found", issues.length); 14}
composePaginateRest
and composePaginateRest.iterator
The compose*
methods work just like their octokit.*
counterparts described above, with the differenct that both methods require an octokit
instance to be passed as first argument
octokit.paginate()
wraps octokit.request()
. As long as a rel="next"
link value is present in the response's Link
header, it sends another request for that URL, and so on.
Most of GitHub's paginating REST API endpoints return an array, but there are a few exceptions which return an object with a key that includes the items array. For example:
items
)check_runs
)check_suites
)repositories
)installations
)octokit.paginate()
is working around these inconsistencies so you don't have to worry about it.
If a response is lacking the Link
header, octokit.paginate()
still resolves with an array, even if the response returns a single object.
The plugin also exposes some types and runtime type guards for TypeScript projects.
Types |
|
---|---|
Guards |
|
An interface
that declares all the overloads of the .paginate
method.
An interface
which describes all API endpoints supported by the plugin. Some overloads of .paginate()
method and composePaginateRest()
function depend on PaginatingEndpoints
, using the keyof PaginatingEndpoints
as a type for one of its arguments.
1import { Octokit } from "@octokit/core"; 2import { 3 PaginatingEndpoints, 4 composePaginateRest, 5} from "@octokit/plugin-paginate-rest"; 6 7type DataType<T> = "data" extends keyof T ? T["data"] : unknown; 8 9async function myPaginatePlugin<E extends keyof PaginatingEndpoints>( 10 octokit: Octokit, 11 endpoint: E, 12 parameters?: PaginatingEndpoints[E]["parameters"], 13): Promise<DataType<PaginatingEndpoints[E]["response"]>> { 14 return await composePaginateRest(octokit, endpoint, parameters); 15}
A type guard, isPaginatingEndpoint(arg)
returns true
if arg
is one of the keys in PaginatingEndpoints
(is keyof PaginatingEndpoints
).
1import { Octokit } from "@octokit/core"; 2import { 3 isPaginatingEndpoint, 4 composePaginateRest, 5} from "@octokit/plugin-paginate-rest"; 6 7async function myPlugin(octokit: Octokit, arg: unknown) { 8 if (isPaginatingEndpoint(arg)) { 9 return await composePaginateRest(octokit, arg); 10 } 11 // ... 12}
See CONTRIBUTING.md
5.3/10
Summary
@octokit/plugin-paginate-rest has a Regular Expression in iterator Leads to ReDoS Vulnerability Due to Catastrophic Backtracking
Affected Versions
>= 1.0.0, < 9.2.2
Patched Versions
9.2.2
5.3/10
Summary
@octokit/plugin-paginate-rest has a Regular Expression in iterator Leads to ReDoS Vulnerability Due to Catastrophic Backtracking
Affected Versions
>= 9.3.0-beta.1, < 11.4.1
Patched Versions
11.4.1
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
14 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool is run on all commits
Details
Reason
0 existing vulnerabilities detected
Reason
Found 10/11 approved changesets -- score normalized to 9
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-05-12
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More