@@ -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}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user