Fix fallback to latest version in tools.ts

This commit is contained in:
Shivam Mathur
2025-11-25 17:27:09 +05:30
parent 14ee952199
commit 537d716000
3 changed files with 15 additions and 3 deletions

View File

@ -244,6 +244,19 @@ describe('Tools tests', () => {
}
);
it('checking getUrl handles undefined version without double slash', async () => {
const data = getData({
tool: 'cs2pr',
repository: 'staabm/annotate-pull-request-from-checkstyle',
domain: 'https://github.com'
});
data['extension'] = '';
delete data['version'];
expect(await tools.getUrl(data)).toBe(
'https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/cs2pr'
);
});
it.each`
version | version_prefix | url
${'latest'} | ${''} | ${'https://example.com/tool.phar'}

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -156,7 +156,7 @@ export async function filterList(tools_list: string[]): Promise<string[]> {
* @param data
*/
export async function getUrl(data: RS): Promise<string> {
if (data['version'] === 'latest') {
if ((data['version'] ?? 'latest') === 'latest') {
return [
data['domain'],
data['repository'],
@ -578,7 +578,6 @@ export async function addTools(
break;
case 'phar' === data['type']:
data['url'] = await getUrl(data);
console.log(data['url']);
script += await addArchive(data);
break;
case 'composer' === data['type']: