Skip to content

Commit b8e94c0

Browse files
Merge pull request #210 from projectsyn/fix/null-urls
Do not crash when a package URL cannot be inferred
2 parents b3680eb + aa952cc commit b8e94c0

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/commodore/__fixtures__/1/params.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ parameters:
2222
foo-test:
2323
url: https://gitlab.com/projectsyn/component-foo-test.git
2424
version: v2.2.0
25+
bar-test:
26+
version: v2.2.0
2527
packages:
2628
monitoring:
2729
url: https://github.com/projectsyn/package-monitoring

src/commodore/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,23 @@ export async function extractPackageFile(
286286
}
287287

288288
const githubBaseUrl = extraConfig.githubBaseUrl;
289-
const deps = components.map((v: CommodoreDependency) => ({
290-
depName: `${v.name} in ${fileName}`,
291-
packageName: v.url.startsWith(githubBaseUrl)
292-
? v.url.slice(githubBaseUrl.length).replace(/\.git$/, '')
293-
: v.url,
294-
currentValue: v.version,
295-
datasource: v.url.startsWith(githubBaseUrl)
296-
? githubRelease.GithubReleasesDatasource.id
297-
: gitRef.GitRefsDatasource.id,
298-
}));
289+
const deps = components
290+
.filter((dep: CommodoreDependency) => {
291+
if (dep.url !== undefined) return true;
292+
logger.warn(
293+
`Could not infer package for dependency: ${dep.name} in ${fileName}. Skipping package.`
294+
);
295+
return false;
296+
})
297+
.map((v: CommodoreDependency) => ({
298+
depName: `${v.name} in ${fileName}`,
299+
packageName: v.url?.startsWith(githubBaseUrl)
300+
? v.url.slice(githubBaseUrl.length).replace(/\.git$/, '')
301+
: v.url,
302+
currentValue: v.version,
303+
datasource: v.url?.startsWith(githubBaseUrl)
304+
? githubRelease.GithubReleasesDatasource.id
305+
: gitRef.GitRefsDatasource.id,
306+
}));
299307
return { deps };
300308
}

0 commit comments

Comments
 (0)