Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

GitHub.searchIssues fails with 422 when perPage does not evenly divide the 1000-result cap

オープン 初心者向け
#56 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
typescript
領域
api

調査の方向性

src/prompt-generators/github/github.ts から始めて、normalizeMaxResults と GITHUB_SEARCH_RESULT_LIMIT に加えて、searchIssues のページネーションループを調べてください。perPage: 70 と 1,000 件を超える結果を返すクエリで問題を再現し、ページウィンドウが上限を超えるリクエストを行う前に、422 をスローせずページネーションが停止することを確認してください。

索引モデルが issue の本文から書いたものです。

説明

bug S3

Observed behavior

GitHub.searchIssues throws GitHub API error 422: Only the first 1000 search results are available when perPage is set to a value that does not evenly divide 1000 and the underlying query has more than 1000 matching issues.

GitHub's REST search API has a hard cap of 1,000 results per query, and any request where page * per_page > 1000 is rejected with HTTP 422. normalizeMaxResults caps the effective maximum at GITHUB_SEARCH_RESULT_LIMIT (1000), and the pagination loop in searchIssues continues until issues.length >= maxResults. With a non-divisor perPage value, the loop reaches a page where page * perPage overshoots 1000 before issues.length reaches 1000.

Example with perPage: 70 and the default maxResults of 1000 against a query that returns 5000+ issues:

  • Pages 1 to 14 return 70 items each, accumulating 980 issues.
  • The break conditions at the end of page 14 are all false (items.length (70) < perPage (70) is false, 980 < total_count is true, 980 < 1000 is true), so the loop continues.
  • Page 15 is requested with per_page=70, so 15 * 70 = 1050 > 1000. GitHub returns HTTP 422 and searchIssues throws.

This is silent at the type/config level: the docstring on GitHubIssueSearchParams.perPage says "GitHub accepts 1 to 100" with no caveat about result-window alignment.

Expected behavior

searchIssues should not crash with a 422 when used within the documented perPage and maxResults contracts. It should either stop paginating once the next request would overshoot the 1000-result window, or normalize perPage so that it always evenly divides the effective cap.

Minimal reproduction

import { GitHub } from 'loop-the-loop/prompt-generators/github/github';
import { vi } from 'vitest';

vi.stubGlobal(
  'fetch',
  vi.fn().mockImplementation((url: string) => {
    const u = new URL(url);
    const page = Number(u.searchParams.get('page'));
    const perPage = Number(u.searchParams.get('per_page'));
    if (page * perPage > 1000) {
      return Promise.resolve({
        ok: false,
        status: 422,
        text: () =>
          Promise.resolve(
            JSON.stringify({
              message: 'Only the first 1000 search results are available',
            }),
          ),
      });
    }
    return Promise.resolve({
      ok: true,
      status: 200,
      text: () =>
        Promise.resolve(
          JSON.stringify({
            total_count: 5000,
            items: Array.from({ length: perPage }, (_v, i) => ({
              number: (page - 1) * perPage + i + 1,
              title: 't',
              html_url: 'https://github.test/x',
              state: 'open',
            })),
          }),
        ),
    });
  }),
);

const github = new GitHub({ origin: 'https://api.test' });
await github.searchIssues({
  repository: 'octocat/Hello-World',
  query: 'is:open',
  perPage: 70,
});
// throws: GitHub API error 422: Only the first 1000 search results are available

Suggested fix

In the pagination loop in src/prompt-generators/github/github.ts, stop iterating once the next request would push past the result window. For example, extend the post-page break to also handle the cap:

if (
  reply.items.length < perPage ||
  issues.length >= reply.total_count ||
  issues.length >= maxResults ||
  (page + 1) * perPage > GITHUB_SEARCH_RESULT_LIMIT
) {
  break;
}

Alternatively, normalize perPage so that it always divides maxResults (and therefore GITHUB_SEARCH_RESULT_LIMIT) cleanly when the cap is in effect, and document the rounding behavior on GitHubIssueSearchParams.perPage.

主要言語
TypeScript
スター
2
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

joewalker/loop-the-loop のほかの issue

joewalker/loop-the-loop の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。