diff --git a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx index 5fc035595c..21080cb408 100644 --- a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx +++ b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx @@ -15,23 +15,19 @@ */ import { useEntity } from '@backstage/plugin-catalog-react'; import { useReleases } from '../../hooks/useReleases'; -import { - getProjectIdAnnotationFromEntity, - getSpaceIdAnnotationFromEntity, -} from '../../utils/getAnnotationFromEntity'; +import { getProjectReferenceAnnotationFromEntity } from '../../utils/getAnnotationFromEntity'; import React from 'react'; import { ReleaseTable } from '../ReleaseTable'; export const EntityPageOctopusDeploy = (props: { defaultLimit?: number }) => { const { entity } = useEntity(); - const projectId = getProjectIdAnnotationFromEntity(entity); - const spaceId = getSpaceIdAnnotationFromEntity(entity); + const projectReference = getProjectReferenceAnnotationFromEntity(entity); const { environments, releases, loading, error } = useReleases( - projectId, + projectReference.projectId, props.defaultLimit ?? 3, - spaceId, + projectReference.spaceId, ); return ( diff --git a/plugins/octopus-deploy/src/constants.ts b/plugins/octopus-deploy/src/constants.ts index cb3b2356af..3bdc48252f 100644 --- a/plugins/octopus-deploy/src/constants.ts +++ b/plugins/octopus-deploy/src/constants.ts @@ -16,5 +16,3 @@ /** @public */ export const OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION = 'octopus.com/project-id'; -/** @public */ -export const OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION = 'octopus.com/space-id'; diff --git a/plugins/octopus-deploy/src/index.ts b/plugins/octopus-deploy/src/index.ts index 07fcdc82f5..e3264efaf0 100644 --- a/plugins/octopus-deploy/src/index.ts +++ b/plugins/octopus-deploy/src/index.ts @@ -21,7 +21,4 @@ export { export * from './api'; -export { - OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION, - OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION, -} from './constants'; +export { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from './constants'; diff --git a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts index 14d8739962..29881a1daa 100644 --- a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts +++ b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION, - OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION, -} from '../constants'; +import { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from '../constants'; import { Entity } from '@backstage/catalog-model'; -export function getProjectIdAnnotationFromEntity(entity: Entity): string { +export type ProjectReference = { projectId: string; spaceId?: string }; + +export function getProjectReferenceAnnotationFromEntity( + entity: Entity, +): ProjectReference { const annotation = entity.metadata.annotations?.[OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION]; if (!annotation) { @@ -29,14 +30,9 @@ export function getProjectIdAnnotationFromEntity(entity: Entity): string { ); } - return annotation; -} - -export function getSpaceIdAnnotationFromEntity( - entity: Entity, -): string | undefined { - const annotation = - entity.metadata.annotations?.[OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION]; - - return annotation || undefined; + const referencedProject = annotation.split('/', 2); + if (referencedProject.length === 2) { + return { projectId: referencedProject[1], spaceId: referencedProject[0] }; + } + return { projectId: referencedProject[0] }; }