Initial improvements from feedback
Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
committed by
Andre Wanlin
parent
9987f11687
commit
904d7f1240
@@ -31,13 +31,14 @@ describe('getAnnotationValuesFromEntity', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const { project, repo, definition, host, org } =
|
||||
getAnnotationValuesFromEntity(entity);
|
||||
expect(project).toEqual('projectName');
|
||||
expect(repo).toEqual('repoName');
|
||||
expect(definition).toEqual(undefined);
|
||||
expect(host).toEqual(undefined);
|
||||
expect(org).toEqual(undefined);
|
||||
const values = getAnnotationValuesFromEntity(entity);
|
||||
expect(values).toEqual({
|
||||
project: 'projectName',
|
||||
repo: 'repoName',
|
||||
definition: undefined,
|
||||
host: undefined,
|
||||
org: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -127,13 +128,14 @@ describe('getAnnotationValuesFromEntity', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const { project, repo, definition, host, org } =
|
||||
getAnnotationValuesFromEntity(entity);
|
||||
expect(project).toEqual('projectName');
|
||||
expect(repo).toEqual(undefined);
|
||||
expect(definition).toEqual('buildDefinitionName');
|
||||
expect(host).toEqual(undefined);
|
||||
expect(org).toEqual(undefined);
|
||||
const values = getAnnotationValuesFromEntity(entity);
|
||||
expect(values).toEqual({
|
||||
project: 'projectName',
|
||||
repo: undefined,
|
||||
definition: 'buildDefinitionName',
|
||||
host: undefined,
|
||||
org: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -197,13 +199,14 @@ describe('getAnnotationValuesFromEntity', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const { project, repo, definition, host, org } =
|
||||
getAnnotationValuesFromEntity(entity);
|
||||
expect(project).toEqual('projectName');
|
||||
expect(repo).toEqual('repoName');
|
||||
expect(definition).toEqual(undefined);
|
||||
expect(host).toEqual('hostName');
|
||||
expect(org).toEqual('organizationName');
|
||||
const values = getAnnotationValuesFromEntity(entity);
|
||||
expect(values).toEqual({
|
||||
project: 'projectName',
|
||||
repo: 'repoName',
|
||||
definition: undefined,
|
||||
host: 'hostName',
|
||||
org: 'organizationName',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -222,13 +225,14 @@ describe('getAnnotationValuesFromEntity', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const { project, repo, definition, host, org } =
|
||||
getAnnotationValuesFromEntity(entity);
|
||||
expect(project).toEqual('projectName');
|
||||
expect(repo).toEqual(undefined);
|
||||
expect(definition).toEqual('buildDefinitionName');
|
||||
expect(host).toEqual('hostName');
|
||||
expect(org).toEqual('organizationName');
|
||||
const values = getAnnotationValuesFromEntity(entity);
|
||||
expect(values).toEqual({
|
||||
project: 'projectName',
|
||||
repo: undefined,
|
||||
definition: 'buildDefinitionName',
|
||||
host: 'hostName',
|
||||
org: 'organizationName',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -256,7 +260,7 @@ describe('getAnnotationValuesFromEntity', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('with host-rg annotation missing host', () => {
|
||||
describe('with host-org annotation missing host', () => {
|
||||
it('should throw missing project error', () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
|
||||
@@ -30,16 +30,16 @@ export function getAnnotationValuesFromEntity(entity: Entity): {
|
||||
host?: string;
|
||||
org?: string;
|
||||
} {
|
||||
const hostOrgAnnotation =
|
||||
entity.metadata.annotations?.[AZURE_DEVOPS_HOST_ORG_ANNOTATION];
|
||||
const { host, org } = getHostOrg(hostOrgAnnotation);
|
||||
const { host, org } = getHostOrg(entity.metadata.annotations);
|
||||
|
||||
const projectRepoAnnotation =
|
||||
entity.metadata.annotations?.[AZURE_DEVOPS_REPO_ANNOTATION];
|
||||
if (projectRepoAnnotation) {
|
||||
const { project, repo } = getProjectRepo(projectRepoAnnotation);
|
||||
const definition = undefined;
|
||||
return { project, repo, definition, host, org };
|
||||
const projectRepoValues = getProjectRepo(entity.metadata.annotations);
|
||||
if (projectRepoValues.project && projectRepoValues.repo) {
|
||||
return {
|
||||
project: projectRepoValues.project,
|
||||
repo: projectRepoValues.repo,
|
||||
host,
|
||||
org,
|
||||
};
|
||||
}
|
||||
|
||||
const project =
|
||||
@@ -57,15 +57,18 @@ export function getAnnotationValuesFromEntity(entity: Entity): {
|
||||
`Value for annotation ${AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION} was not found`,
|
||||
);
|
||||
}
|
||||
|
||||
const repo = undefined;
|
||||
return { project, repo, definition, host, org };
|
||||
return { project, definition, host, org };
|
||||
}
|
||||
|
||||
function getProjectRepo(annotation: string): {
|
||||
project: string;
|
||||
repo: string;
|
||||
function getProjectRepo(annotations?: Record<string, string>): {
|
||||
project?: string;
|
||||
repo?: string;
|
||||
} {
|
||||
const annotation = annotations?.[AZURE_DEVOPS_REPO_ANNOTATION];
|
||||
if (!annotation) {
|
||||
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>`,
|
||||
@@ -89,10 +92,11 @@ function getProjectRepo(annotation: string): {
|
||||
return { project, repo };
|
||||
}
|
||||
|
||||
function getHostOrg(annotation?: string): {
|
||||
function getHostOrg(annotations?: Record<string, string>): {
|
||||
host?: string;
|
||||
org?: string;
|
||||
} {
|
||||
const annotation = annotations?.[AZURE_DEVOPS_HOST_ORG_ANNOTATION];
|
||||
if (!annotation) {
|
||||
return { host: undefined, org: undefined };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user