Refactored to use positive return
Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
@@ -61,7 +61,7 @@ describe('getAnnotationValuesFromEntity', () => {
|
||||
};
|
||||
|
||||
expect(test).toThrow(
|
||||
'Value for annotation dev.azure.com/project-repo was not in the correct format: <project-name>/<repo-name>',
|
||||
'Invalid value for annotation "dev.azure.com/project-repo"; expected format is: <project-name>/<repo-name>, 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: <project-name>/<repo-name>',
|
||||
'Invalid value for annotation "dev.azure.com/project-repo"; expected format is: <project-name>/<repo-name>, 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: <project-name>/<repo-name>',
|
||||
'Invalid value for annotation "dev.azure.com/project-repo"; expected format is: <project-name>/<repo-name>, 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: <host-name>/<organization-name>',
|
||||
'Invalid value for annotation "dev.azure.com/host-org"; expected format is: <host-name>/<organization-name>, 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: <host-name>/<organization-name>',
|
||||
'Invalid value for annotation "dev.azure.com/host-org"; expected format is: <host-name>/<organization-name>, 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: <host-name>/<organization-name>',
|
||||
'Invalid value for annotation "dev.azure.com/host-org"; expected format is: <host-name>/<organization-name>, found: "host/"',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,27 +69,16 @@ function getProjectRepo(annotations?: Record<string, string>): {
|
||||
return { project: undefined, repo: undefined };
|
||||
}
|
||||
|
||||
if (!annotation.includes('/')) {
|
||||
throw new Error(
|
||||
`Value for annotation ${AZURE_DEVOPS_REPO_ANNOTATION} was not in the correct format: <project-name>/<repo-name>`,
|
||||
);
|
||||
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: <project-name>/<repo-name>`,
|
||||
);
|
||||
}
|
||||
|
||||
if (!repo) {
|
||||
throw new Error(
|
||||
`Repo Name for annotation ${AZURE_DEVOPS_REPO_ANNOTATION} was not found; expected format is: <project-name>/<repo-name>`,
|
||||
);
|
||||
}
|
||||
|
||||
return { project, repo };
|
||||
throw new Error(
|
||||
`Invalid value for annotation "${AZURE_DEVOPS_REPO_ANNOTATION}"; expected format is: <project-name>/<repo-name>, found: "${annotation}"`,
|
||||
);
|
||||
}
|
||||
|
||||
function getHostOrg(annotations?: Record<string, string>): {
|
||||
@@ -101,25 +90,14 @@ function getHostOrg(annotations?: Record<string, string>): {
|
||||
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: <host-name>/<organization-name>`,
|
||||
);
|
||||
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: <host-name>/<organization-name>`,
|
||||
);
|
||||
}
|
||||
|
||||
if (!org) {
|
||||
throw new Error(
|
||||
`Organization for annotation ${AZURE_DEVOPS_HOST_ORG_ANNOTATION} was not found; expected format is: <host-name>/<organization-name>`,
|
||||
);
|
||||
}
|
||||
|
||||
return { host, org };
|
||||
throw new Error(
|
||||
`Invalid value for annotation "${AZURE_DEVOPS_HOST_ORG_ANNOTATION}"; expected format is: <host-name>/<organization-name>, found: "${annotation}"`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user