Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ function _registerGraphqlRateLimitHeaderLogging(
export function extractArchitectureFromUrl(
url: string,
expectedArchitectures: ExpectedArchitectures = EXPECTED_ARCHITECTURES,
): ExpectedArchitecture {
): ExpectedArchitecture | undefined {
// fallback to all archs when none are provided
const architectures =
expectedArchitectures.length === 0
Expand All @@ -857,7 +857,7 @@ export function extractArchitectureFromUrl(
if (filename.includes('MacOS_x86_64') || filename.includes('MacOS_x86-64')) {
return 'MacOS_x86_64';
}
throw new Error(`Unknown architecture in filename: ${filename}`);
return undefined;
}

function detectPresentArchitectures(
Expand All @@ -869,7 +869,8 @@ function detectPresentArchitectures(
.filter((asset) => asset.downloadUrl.endsWith('.JASPModule'))
.map((asset) =>
extractArchitectureFromUrl(asset.downloadUrl, expectedArchitectures),
),
)
.filter((arch): arch is ExpectedArchitecture => arch !== undefined),
);
}

Expand Down Expand Up @@ -1170,12 +1171,15 @@ export function transformRelease(
assets: releaseAssets.nodes
.filter((asset) => asset.downloadUrl.endsWith('.JASPModule'))
.map((a) => {
const architecture = extractArchitectureFromUrl(a.downloadUrl);
if (!architecture) return undefined;
const asset: Asset = {
...a,
architecture: extractArchitectureFromUrl(a.downloadUrl),
architecture,
};
return asset;
})
.filter((a): a is Asset => a !== undefined)
.sort((a, b) => a.architecture.localeCompare(b.architecture, 'en')),
};
return newRelease;
Expand Down
12 changes: 6 additions & 6 deletions src/scrape.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,19 @@ describe('extractArchitectureFromUrl', () => {
);
});

test('throws error for unknown architecture', () => {
expect(() =>
test('returns undefined for unknown architecture', () => {
expect(
extractArchitectureFromUrl('jaspAnova_0.95.0_UnknownArch.JASPModule'),
).toThrow('Unknown architecture in filename');
).toBeUndefined();
});

test('when url does not match expected pattern, throws error', () => {
expect(() =>
test('returns undefined when url does not match expected pattern', () => {
expect(
extractArchitectureFromUrl(
'jaspAnova_0.95.0_Windows_x86-64_R-4-5-1.JASPModule',
['Flatpak_x86_64'],
),
).toThrow('Unknown architecture in filename');
).toBeUndefined();
});
});

Expand Down