diff --git a/.changeset/red-cheetahs-invite.md b/.changeset/red-cheetahs-invite.md new file mode 100644 index 0000000000..8e86764132 --- /dev/null +++ b/.changeset/red-cheetahs-invite.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-octopus-deploy': minor +--- + +Added support for octopus deploy spaces. diff --git a/packages/app/package.json b/packages/app/package.json index 74a41993d3..df626c16ba 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -47,6 +47,7 @@ "@backstage/plugin-microsoft-calendar": "workspace:^", "@backstage/plugin-newrelic": "workspace:^", "@backstage/plugin-newrelic-dashboard": "workspace:^", + "@backstage/plugin-octopus-deploy": "workspace:^", "@backstage/plugin-org": "workspace:^", "@backstage/plugin-pagerduty": "workspace:^", "@backstage/plugin-permission-react": "workspace:^", diff --git a/packages/app/src/components/catalog/EntityPage.tsx b/packages/app/src/components/catalog/EntityPage.tsx index d2f6fbe109..026544ab26 100644 --- a/packages/app/src/components/catalog/EntityPage.tsx +++ b/packages/app/src/components/catalog/EntityPage.tsx @@ -41,6 +41,10 @@ import { isAzureDevOpsAvailable, isAzurePipelinesAvailable, } from '@backstage/plugin-azure-devops'; +import { + isOctopusDeployAvailable, + EntityOctopusDeployContent, +} from '@backstage/plugin-octopus-deploy'; import { EntityBadgesDialog } from '@backstage/plugin-badges'; import { EntityAboutCard, @@ -262,6 +266,10 @@ export const cicdContent = ( + + + + ; } @@ -81,9 +82,10 @@ export class OctopusDeployClient implements OctopusDeployApi { async getReleaseProgression( projectId: string, + spaceId: string | null, releaseHistoryCount: number, ): Promise { - const url = await this.getApiUrl(projectId, releaseHistoryCount); + const url = await this.getApiUrl(projectId, spaceId, releaseHistoryCount); const response = await this.fetchApi.fetch(url); @@ -106,11 +108,21 @@ export class OctopusDeployClient implements OctopusDeployApi { return responseJson; } - private async getApiUrl(projectId: string, releaseHistoryCount: number) { + private async getApiUrl( + projectId: string, + spaceId: string | null, + releaseHistoryCount: number, + ) { const proxyUrl = await this.discoveryApi.getBaseUrl('proxy'); const queryParameters = new URLSearchParams({ releaseHistoryCount: releaseHistoryCount.toString(), }); + if (spaceId !== null) + return `${proxyUrl}${this.proxyPathBase}/${encodeURIComponent( + spaceId, + )}/projects/${encodeURIComponent( + projectId, + )}/progression?${queryParameters}`; return `${proxyUrl}${this.proxyPathBase}/projects/${encodeURIComponent( projectId, )}/progression?${queryParameters}`; diff --git a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx index de28edb9e0..b263c67566 100644 --- a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx +++ b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx @@ -15,17 +15,22 @@ */ import { useEntity } from '@backstage/plugin-catalog-react'; import { useReleases } from '../../hooks/useReleases'; -import { getAnnotationFromEntity } from '../../utils/getAnnotationFromEntity'; +import { + getProjectIdAnnotationFromEntity, + getSpaceIdAnnotationFromEntity, +} from '../../utils/getAnnotationFromEntity'; import React from 'react'; import { ReleaseTable } from '../ReleaseTable'; export const EntityPageOctopusDeploy = (props: { defaultLimit?: number }) => { const { entity } = useEntity(); - const projectId = getAnnotationFromEntity(entity); + const projectId = getProjectIdAnnotationFromEntity(entity); + const spaceId = getSpaceIdAnnotationFromEntity(entity); const { environments, releases, loading, error } = useReleases( projectId, + spaceId, props.defaultLimit ?? 3, ); diff --git a/plugins/octopus-deploy/src/constants.ts b/plugins/octopus-deploy/src/constants.ts index 3bdc48252f..b7786c3a64 100644 --- a/plugins/octopus-deploy/src/constants.ts +++ b/plugins/octopus-deploy/src/constants.ts @@ -16,3 +16,4 @@ /** @public */ export const OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION = 'octopus.com/project-id'; +export const OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION = 'octopus.com/space-id'; diff --git a/plugins/octopus-deploy/src/hooks/useReleases.ts b/plugins/octopus-deploy/src/hooks/useReleases.ts index 742ce78dca..3643956a2a 100644 --- a/plugins/octopus-deploy/src/hooks/useReleases.ts +++ b/plugins/octopus-deploy/src/hooks/useReleases.ts @@ -23,6 +23,7 @@ import { export function useReleases( projectId: string, + spaceId: string | null, releaseHistoryCount: number, ): { environments?: OctopusEnvironment[]; @@ -33,8 +34,8 @@ export function useReleases( const api = useApi(octopusDeployApiRef); const { value, loading, error } = useAsync(() => { - return api.getReleaseProgression(projectId, releaseHistoryCount); - }, [api, projectId, releaseHistoryCount]); + return api.getReleaseProgression(projectId, spaceId, releaseHistoryCount); + }, [api, projectId, spaceId, releaseHistoryCount]); return { environments: value?.Environments, diff --git a/plugins/octopus-deploy/src/index.ts b/plugins/octopus-deploy/src/index.ts index e3264efaf0..07fcdc82f5 100644 --- a/plugins/octopus-deploy/src/index.ts +++ b/plugins/octopus-deploy/src/index.ts @@ -21,4 +21,7 @@ export { export * from './api'; -export { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from './constants'; +export { + OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION, + OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION, +} from './constants'; diff --git a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts index e59a32235f..5c4a2e1788 100644 --- a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts +++ b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts @@ -13,11 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from '../constants'; +import { + OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION, + OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION, +} from '../constants'; import { Entity } from '@backstage/catalog-model'; -export function getAnnotationFromEntity(entity: Entity): string { +export function getProjectIdAnnotationFromEntity(entity: Entity): string { const annotation = entity.metadata.annotations?.[OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION]; if (!annotation) { @@ -28,3 +31,10 @@ export function getAnnotationFromEntity(entity: Entity): string { return annotation; } + +export function getSpaceIdAnnotationFromEntity(entity: Entity): string | null { + const annotation = + entity.metadata.annotations?.[OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION]; + + return annotation || null; +}