Fix fallback to latest version in tools.ts

This commit is contained in:
Shivam Mathur
2025-11-25 17:27:09 +05:30
parent 3961404d06
commit 91d37511e3
3 changed files with 15 additions and 2 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` it.each`
version | version_prefix | url version | version_prefix | url
${'latest'} | ${''} | ${'https://example.com/tool.phar'} ${'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 * @param data
*/ */
export async function getUrl(data: RS): Promise<string> { export async function getUrl(data: RS): Promise<string> {
if (data['version'] === 'latest') { if ((data['version'] ?? 'latest') === 'latest') {
return [ return [
data['domain'], data['domain'],
data['repository'], data['repository'],