Skip to content

Commit

Permalink
fix: change 'pageSize' inputs/args to 'per_page'
Browse files Browse the repository at this point in the history
It's possible 'pageSize' works as intended, potentially due to some
kind of hard to find legacy support or overlap with octokit.net
(where the parameter name is explicitly that), but the correct name
of this parameter in the REST API is 'per_page'.

It appears likely that 'pageSize' has had no effect whatsoever. The
actual action code defaults the value to '30' which happens to align
with the REST API's default for when 'per_page' is not provided. While
the tests do use an explicit value (namely '3'), the Jest nock for each
endpoint dictate the number of results there instead of the actual
parameter value.
  • Loading branch information
oblivioncth authored and jpoehnelt committed Sep 26, 2024
1 parent 8117dba commit 7a2e787
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ afterAll(() => {
});

describe("listing repos from github", () => {
const pageSize = 3;
const per_page = 3;
beforeEach(() => {
nock("https://api.github.com")
.get(/\/user\/repos?.*page=1.*/)
Expand All @@ -72,7 +72,7 @@ describe("listing repos from github", () => {
const repos = await listAllMatchingRepos({
patterns: [".*"],
octokit,
pageSize,
per_page,
});

expect(repos.length).toEqual(3);
Expand All @@ -82,7 +82,7 @@ describe("listing repos from github", () => {
const repos = await listAllMatchingRepos({
patterns: ["octokit.*"],
octokit,
pageSize,
per_page,
});

expect(repos.length).toEqual(3);
Expand Down
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,29 +186,29 @@ function getRepos({ patterns, octokit, }) {
});
}
exports.getRepos = getRepos;
function listAllMatchingRepos({ patterns, octokit, affiliation = "owner,collaborator,organization_member", pageSize = 30, }) {
function listAllMatchingRepos({ patterns, octokit, affiliation = "owner,collaborator,organization_member", per_page = 30, }) {
return __awaiter(this, void 0, void 0, function* () {
const repos = yield listAllReposForAuthenticatedUser({
octokit,
affiliation,
pageSize,
per_page,
});
core.info(`Available repositories: ${JSON.stringify(repos.map((r) => r.full_name))}`);
return filterReposByPatterns(repos, patterns);
});
}
exports.listAllMatchingRepos = listAllMatchingRepos;
function listAllReposForAuthenticatedUser({ octokit, affiliation, pageSize, }) {
function listAllReposForAuthenticatedUser({ octokit, affiliation, per_page, }) {
return __awaiter(this, void 0, void 0, function* () {
const repos = [];
for (let page = 1;; page++) {
const response = yield octokit.repos.listForAuthenticatedUser({
affiliation,
page,
pageSize,
per_page,
});
repos.push(...response.data);
if (response.data.length < pageSize) {
if (response.data.length < per_page) {
break;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ export async function listAllMatchingRepos({
patterns,
octokit,
affiliation = "owner,collaborator,organization_member",
pageSize = 30,
per_page = 30,
}: {
patterns: string[];
octokit: any;
affiliation?: string;
pageSize?: number;
per_page?: number;
}): Promise<Repository[]> {
const repos = await listAllReposForAuthenticatedUser({
octokit,
affiliation,
pageSize,
per_page,
});

core.info(
Expand All @@ -126,23 +126,23 @@ export async function listAllMatchingRepos({
export async function listAllReposForAuthenticatedUser({
octokit,
affiliation,
pageSize,
per_page,
}: {
octokit: any;
affiliation: string;
pageSize: number;
per_page: number;
}): Promise<Repository[]> {
const repos: Repository[] = [];

for (let page = 1; ; page++) {
const response = await octokit.repos.listForAuthenticatedUser({
affiliation,
page,
pageSize,
per_page,
});
repos.push(...response.data);

if (response.data.length < pageSize) {
if (response.data.length < per_page) {
break;
}
}
Expand Down

0 comments on commit 7a2e787

Please sign in to comment.