fix(catalog-backend-module-azure): fix URL encoding alignment and move analyzer to alpha export

Signed-off-by: Lokesh Kaki <lokeshkaki1@gmail.com>
This commit is contained in:
Lokesh Kaki
2026-03-15 21:15:13 -05:00
parent 121690f95c
commit 308b36ffad
4 changed files with 39 additions and 10 deletions
@@ -19,3 +19,5 @@ import { default as feature } from './module';
/** @alpha */
const _feature = feature;
export default _feature;
export { analyzeAzureDevOpsWebhookEvent } from './events/analyzeAzureDevOpsWebhookEvent';
@@ -127,6 +127,40 @@ describe('analyzeAzureDevOpsWebhookEvent', () => {
});
});
it('does not double-encode branch names containing slashes', async () => {
const repoWithSlashBranch = {
...baseRepository,
defaultBranch: 'refs/heads/feature/my-branch',
};
await expect(
analyzeAzureDevOpsWebhookEvent(
'git.push',
withPushEvent({
repository: repoWithSlashBranch,
refUpdates: [{ name: 'refs/heads/feature/my-branch' }],
commits: [
{
commitId: 'abc',
changes: [
{ changeType: 'add', item: { path: '/catalog-info.yaml' } },
],
},
],
}),
{ isRelevantPath },
),
).resolves.toEqual({
result: 'ok',
events: [
{
type: 'location.created',
url: `${baseRepository.remoteUrl}?path=/catalog-info.yaml&version=GBfeature/my-branch`,
context: { commitUrl: `${baseRepository.remoteUrl}/commit/abc` },
},
],
});
});
it('ignores non-default-branch pushes', async () => {
await expect(
analyzeAzureDevOpsWebhookEvent(
@@ -156,16 +156,10 @@ function toLocationUrl(options: {
const url = new URL(options.remoteUrl);
const branch = branchNameFromRef(options.branchRef);
// Encode each path segment individually to protect against special chars while
// preserving '/' separators, which is what Azure DevOps expects in the path param.
const encodedPath = options.path
.split('/')
.map(encodeURIComponent)
.join('/');
url.search = branch
? `path=${encodedPath}&version=GB${encodeURIComponent(branch)}`
: `path=${encodedPath}`;
return url.toString();
? `path=${options.path}&version=GB${branch}`
: `path=${options.path}`;
return encodeURI(url.toString());
}
function toCommitUrl(
@@ -23,4 +23,3 @@
export { default } from './module';
export { AzureDevOpsDiscoveryProcessor } from './processors';
export { AzureDevOpsEntityProvider } from './providers';
export { analyzeAzureDevOpsWebhookEvent } from './events/analyzeAzureDevOpsWebhookEvent';