Skip to content

Commit

Permalink
fix HttpNotFound error, update to node20, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cardinalby committed Feb 2, 2024
1 parent cedef2f commit 2a2df52
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ outputs:
assets:
description: 'JSON of assets object'
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
branding:
icon: 'tag'
11 changes: 10 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,19 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.findLatestRelease = void 0;
const findReleaseByPredicate_1 = __nccwpck_require__(5254);
const filtering_1 = __nccwpck_require__(7826);
const NotFoundError_1 = __nccwpck_require__(9248);
function findLatestRelease(github, repoInfo, filters) {
return __awaiter(this, void 0, void 0, function* () {
if (filters.draft === undefined && filters.prerelease === undefined) {
return (yield github.rest.repos.getLatestRelease(repoInfo)).data;
try {
return (yield github.rest.repos.getLatestRelease(repoInfo)).data;
}
catch (error) {
if (error instanceof Error && error.status === 404) {
throw new NotFoundError_1.NotFoundError("latest release not found: " + typeof error);
}
throw error;
}
}
return (0, findReleaseByPredicate_1.findReleaseByPredicate)(github, repoInfo, (release) => __awaiter(this, void 0, void 0, function* () { return (0, filtering_1.checkReleaseFilters)(release, filters); }));
});
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"@types/jest": "^29.2.0",
"jest": "^29.2.2",
"ts-jest": "^29.0.3",
"github-action-ts-run-api": "^2.3.0"
"github-action-ts-run-api": "^3.0.4"
}
}
10 changes: 9 additions & 1 deletion src/search/findLatestRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ import {GithubApi, ReleaseResponse} from "./types";
import {findReleaseByPredicate} from "./findReleaseByPredicate";
import {checkReleaseFilters} from "./filtering";
import {ReleaseFilters, RepoInfo} from "../actionInputs";
import {NotFoundError} from "../NotFoundError";

export async function findLatestRelease(
github: GithubApi,
repoInfo: RepoInfo,
filters: ReleaseFilters
): Promise<ReleaseResponse> {
if (filters.draft === undefined && filters.prerelease === undefined) {
return (await github.rest.repos.getLatestRelease(repoInfo)).data;
try {
return (await github.rest.repos.getLatestRelease(repoInfo)).data;
} catch (error: any) {
if (error instanceof Error && (error as any).status === 404) {
throw new NotFoundError("latest release not found: " + typeof error)
}
throw error;
}
}
return findReleaseByPredicate(
github,
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/action.test.ts
<
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('git-get-release-action', () => {
expect(Array.isArray(assets)).toBe(true);
expect(assets.length).toEqual(1);
expect(assets[0].name).toEqual('github-actions-webext.png');
expect(res.warnings).toHaveLength(0);
expect(res.runnerWarnings).toHaveLength(0);
});

it('should not get by id', async () => {
Expand All @@ -45,7 +45,7 @@ describe('git-get-release-action', () => {
expect(res.commands.outputs.id).toBeUndefined();
expect(res.commands.errors).toEqual([]);
expect(res.commands.warnings).not.toEqual([]);
expect(res.warnings).toHaveLength(0);
expect(res.runnerWarnings).toHaveLength(0);
});

test.each([
Expand All @@ -69,7 +69,7 @@ describe('git-get-release-action', () => {
if (expectSuccess) {
expect(res.commands.outputs.id).toEqual('56669824');
}
expect(res.warnings).toHaveLength(0);
expect(res.runnerWarnings).toHaveLength(0);
});

test.each([