mirror of
https://github.com/softprops/action-gh-release.git
synced 2026-03-18 20:28:56 +08:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user