octokit.js
octokit.js copied to clipboard
[BUG]: auto pagination is not working for listPackagesForOrganization
What happened?
Trying to use octokit.paginate with octokit.rest.packages.listPackagesForOrganization to return all results.
Example:
const packages = await octokit.paginate(octokit.rest.packages.listPackagesForOrganization, {
org: '<org>',
package_type: 'npm',
});
I have provided personal access token with follow scope: read:packages, repo, user:email
Expect: Return all packages for given organization (more than 30 results) Actual: Only returns the first page results limited to the default page size of 30
- Note: testing with
octokit.rest.repos.listForOrgseems to work fine
Versions
Octokit.js v2.0.14, Node v16.18.1
Relevant log output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Are you using the plugin-paginate-rest package when doing so?
I didn't know you needed that, I assume that comes when you install the full octokit module? eg.
// npm install octokit
const { Octokit } = require('octokit');
const octokit = new Octokit({ auth: "<token>" });
const packages = await octokit.paginate(octokit.rest.packages.listPackagesForOrganization, {
org: '<org>',
package_type: 'npm',
});
But even after switching to use the plugin like so, it still is only return the default length (30). My workaround right now is to do the pagination manually via loop, but I assume the paginate helper so suppose to help with that.
// npm install @octokit/core
// npm install @octokit/plugin-paginate-rest
const { Octokit } = require('@octokit/core');
const { paginateRest } = require('@octokit/plugin-paginate-rest');
const MyOctokit = Octokit.plugin(paginateRest);
const octokit = new MyOctokit({ auth: "<token>" });
const packages = await octokit.paginate('GET /orgs/{org}/packages', {
org: '<org>',
package_type: 'npm',
});
console.log(packages.length) // returns first 30, even though I expect it to return all
As I noted above, the paginate helper does seem to work with the octokit.rest.repos.listForOrg endpoint just not the octokit.rest.packages.listPackagesForOrganization endpoint.