diff --git a/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.test.ts b/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.test.ts index 0d7a11f48b..a5d3725716 100644 --- a/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.test.ts +++ b/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.test.ts @@ -61,7 +61,7 @@ describe('getAnnotationValuesFromEntity', () => { }; expect(test).toThrow( - 'Value for annotation dev.azure.com/project-repo was not in the correct format: /', + 'Invalid value for annotation "dev.azure.com/project-repo"; expected format is: /, found: "project"', ); }); }); @@ -85,7 +85,7 @@ describe('getAnnotationValuesFromEntity', () => { }; expect(test).toThrow( - 'Project Name for annotation dev.azure.com/project-repo was not found; expected format is: /', + 'Invalid value for annotation "dev.azure.com/project-repo"; expected format is: /, found: "/repo"', ); }); }); @@ -109,7 +109,7 @@ describe('getAnnotationValuesFromEntity', () => { }; expect(test).toThrow( - 'Repo Name for annotation dev.azure.com/project-repo was not found; expected format is: /', + 'Invalid value for annotation "dev.azure.com/project-repo"; expected format is: /, found: "project/"', ); }); }); @@ -255,7 +255,7 @@ describe('getAnnotationValuesFromEntity', () => { }; expect(test).toThrow( - 'Value for annotation dev.azure.com/host-org was not in the correct format: /', + 'Invalid value for annotation "dev.azure.com/host-org"; expected format is: /, found: "host"', ); }); }); @@ -279,7 +279,7 @@ describe('getAnnotationValuesFromEntity', () => { }; expect(test).toThrow( - 'Host for annotation dev.azure.com/host-org was not found; expected format is: /', + 'Invalid value for annotation "dev.azure.com/host-org"; expected format is: /, found: "/org"', ); }); }); @@ -303,7 +303,7 @@ describe('getAnnotationValuesFromEntity', () => { }; expect(test).toThrow( - 'Organization for annotation dev.azure.com/host-org was not found; expected format is: /', + 'Invalid value for annotation "dev.azure.com/host-org"; expected format is: /, found: "host/"', ); }); }); diff --git a/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.ts b/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.ts index 7099352524..99b194a834 100644 --- a/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.ts +++ b/plugins/azure-devops/src/utils/getAnnotationValuesFromEntity.ts @@ -69,27 +69,16 @@ function getProjectRepo(annotations?: Record): { return { project: undefined, repo: undefined }; } - if (!annotation.includes('/')) { - throw new Error( - `Value for annotation ${AZURE_DEVOPS_REPO_ANNOTATION} was not in the correct format: /`, - ); + if (annotation.includes('/')) { + const [project, repo] = annotation.split('/'); + if (project && repo) { + return { project, repo }; + } } - const [project, repo] = annotation.split('/'); - - if (!project) { - throw new Error( - `Project Name for annotation ${AZURE_DEVOPS_REPO_ANNOTATION} was not found; expected format is: /`, - ); - } - - if (!repo) { - throw new Error( - `Repo Name for annotation ${AZURE_DEVOPS_REPO_ANNOTATION} was not found; expected format is: /`, - ); - } - - return { project, repo }; + throw new Error( + `Invalid value for annotation "${AZURE_DEVOPS_REPO_ANNOTATION}"; expected format is: /, found: "${annotation}"`, + ); } function getHostOrg(annotations?: Record): { @@ -101,25 +90,14 @@ function getHostOrg(annotations?: Record): { return { host: undefined, org: undefined }; } - if (!annotation.includes('/')) { - throw new Error( - `Value for annotation ${AZURE_DEVOPS_HOST_ORG_ANNOTATION} was not in the correct format: /`, - ); + if (annotation.includes('/')) { + const [host, org] = annotation.split('/'); + if (host && org) { + return { host, org }; + } } - const [host, org] = annotation.split('/'); - - if (!host) { - throw new Error( - `Host for annotation ${AZURE_DEVOPS_HOST_ORG_ANNOTATION} was not found; expected format is: /`, - ); - } - - if (!org) { - throw new Error( - `Organization for annotation ${AZURE_DEVOPS_HOST_ORG_ANNOTATION} was not found; expected format is: /`, - ); - } - - return { host, org }; + throw new Error( + `Invalid value for annotation "${AZURE_DEVOPS_HOST_ORG_ANNOTATION}"; expected format is: /, found: "${annotation}"`, + ); }