fix: use getReleaseByTag API instead of iterating all releases (#725)

* fix: use getReleaseByTag API instead of iterating all releases

This avoids GitHub's API pagination limit of 10000 results which causes
failures for repositories with many releases.

The `findTagFromReleases` function now uses the direct `getReleaseByTag`
API for O(1) lookup instead of iterating through all releases with
`allReleases`. This is both more efficient and fixes the 10k limit issue.

Fixes #724

* fix: rebuild bundle after release lookup rebase

Signed-off-by: Rui Chen <rui@chenrui.dev>

---------

Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-authored-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
Kim Morrison
2026-03-15 10:57:54 +11:00
committed by GitHub
parent b3b644b91a
commit 320a0beb24
3 changed files with 91 additions and 200 deletions

View File

@@ -494,7 +494,11 @@ export const listReleaseAssets = async (
};
/**
* Finds a release by tag name from all a repository's releases.
* Finds a release by tag name.
*
* Uses the direct getReleaseByTag API for O(1) lookup instead of iterating
* through all releases. This also avoids GitHub's API pagination limit of
* 10000 results which would cause failures for repositories with many releases.
*
* @param releaser - The GitHub API wrapper for release operations
* @param owner - The owner of the repository
@@ -508,16 +512,17 @@ export async function findTagFromReleases(
repo: string,
tag: string,
): Promise<Release | undefined> {
for await (const { data: releases } of releaser.allReleases({
owner,
repo,
})) {
const release = releases.find((release) => release.tag_name === tag);
if (release) {
return release;
try {
const { data: release } = await releaser.getReleaseByTag({ owner, repo, tag });
return release;
} catch (error) {
// Release not found (404) or other error - return undefined to allow creation
if (error.status === 404) {
return undefined;
}
// Re-throw unexpected errors
throw error;
}
return undefined;
}
async function createRelease(