Use extname

Signed-off-by: sblausten <sam@roadie.io>
This commit is contained in:
sblausten
2024-06-14 14:49:56 +02:00
parent 1d495e6555
commit bb3cdd685f
2 changed files with 29 additions and 1 deletions
@@ -162,4 +162,30 @@ describe('GithubLocationAnalyzer', () => {
target: 'https://github.com/foo/bar/blob/my_default_branch/anvil.yaml',
});
});
it('should use the provided entity file extension in search query only if present', async () => {
octokit.search.code.mockImplementation((opts: { q: string }) => {
if (opts.q === 'filename:.gitignore repo:foo/bar') {
return Promise.resolve({
data: { items: [{ path: '.gitignore' }], total_count: 1 },
});
}
return Promise.reject();
});
const analyzer = new GithubLocationAnalyzer({
discovery: mockDiscoveryApi,
auth: mockAuthService,
config,
});
const result = await analyzer.analyze({
url: 'https://github.com/foo/bar',
catalogFilename: '.gitignore',
});
expect(result.existing[0].location).toEqual({
type: 'url',
target: 'https://github.com/foo/bar/blob/my_default_branch/.gitignore',
});
});
});
@@ -78,7 +78,9 @@ export class GithubLocationAnalyzer implements ScmLocationAnalyzer {
const catalogFile = catalogFilename || 'catalog-info.yaml';
const extension = extname(catalogFile);
const extensionQuery = !isEmpty(extension) ? `extension:${extension}` : '';
const extensionQuery = !isEmpty(extension)
? `extension:${extension.replace('.', '')}`
: '';
const query = `filename:${catalogFile} ${extensionQuery} repo:${owner}/${repo}`;