From 87211bc28733addab02ff06022dcf34c45c00afc Mon Sep 17 00:00:00 2001 From: Graeme Christie Date: Mon, 27 Mar 2023 17:00:19 +0800 Subject: [PATCH 01/17] Added support for spaces to Octopus Deploy plugin Added octopus plugin to catalog/EntityPage.tsx and package.json so it is available in default/test implementation in line with other CI/CD plugins Signed-off-by: Graeme Christie --- .changeset/red-cheetahs-invite.md | 5 +++++ packages/app/package.json | 1 + .../app/src/components/catalog/EntityPage.tsx | 8 ++++++++ plugins/octopus-deploy/README.md | 6 +++--- plugins/octopus-deploy/src/api/index.ts | 16 ++++++++++++++-- .../EntityPageOctopusDeploy.tsx | 9 +++++++-- plugins/octopus-deploy/src/constants.ts | 1 + plugins/octopus-deploy/src/hooks/useReleases.ts | 5 +++-- plugins/octopus-deploy/src/index.ts | 5 ++++- .../src/utils/getAnnotationFromEntity.ts | 14 ++++++++++++-- 10 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 .changeset/red-cheetahs-invite.md 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; +} From 34d987132e0e754e3672fdae57a9682ad37c089d Mon Sep 17 00:00:00 2001 From: Graeme Christie Date: Mon, 27 Mar 2023 17:11:42 +0800 Subject: [PATCH 02/17] Fixed spelling issue Signed-off-by: Graeme Christie --- plugins/octopus-deploy/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/octopus-deploy/README.md b/plugins/octopus-deploy/README.md index 4fda4cff32..0901163bcf 100644 --- a/plugins/octopus-deploy/README.md +++ b/plugins/octopus-deploy/README.md @@ -44,7 +44,7 @@ const cicdContent = ( 3. Add `octopus.com/project-id` and optionally an `octopus.com/space-id` annotation in the catalog descriptor file. -To obtain a projects ID you will have to query the Octopus API. You can get the space ID from the projects url in the octopus deploy UI. In the future we'll add support for using a projects slug as well. +To obtain a projects ID you will have to query the Octopus API. You can get the space ID from the projects URL in the octopus deploy UI. In the future we'll add support for using a projects slug as well. ``` // catalog-info.yaml From fce43f70232d52c97061d450575c4cc873bc538e Mon Sep 17 00:00:00 2001 From: Graeme Christie Date: Tue, 28 Mar 2023 10:33:46 +0800 Subject: [PATCH 03/17] Committing yan lock file Signed-off-by: Graeme Christie --- yarn.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 0cd30db248..b27a6f4274 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7508,7 +7508,7 @@ __metadata: languageName: unknown linkType: soft -"@backstage/plugin-octopus-deploy@workspace:plugins/octopus-deploy": +"@backstage/plugin-octopus-deploy@workspace:^, @backstage/plugin-octopus-deploy@workspace:plugins/octopus-deploy": version: 0.0.0-use.local resolution: "@backstage/plugin-octopus-deploy@workspace:plugins/octopus-deploy" dependencies: @@ -23583,6 +23583,7 @@ __metadata: "@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:^" From a72f9af55ef2d833e304bc9722d03d4dc5c0084b Mon Sep 17 00:00:00 2001 From: Graeme Christie Date: Tue, 28 Mar 2023 11:25:10 +0800 Subject: [PATCH 04/17] Updated apireports.md for octopus plugin Added public metadata to exported constant Signed-off-by: Graeme Christie --- plugins/octopus-deploy/api-report.md | 5 +++++ plugins/octopus-deploy/src/constants.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/plugins/octopus-deploy/api-report.md b/plugins/octopus-deploy/api-report.md index 82512ebcef..2a4a60e443 100644 --- a/plugins/octopus-deploy/api-report.md +++ b/plugins/octopus-deploy/api-report.md @@ -22,11 +22,15 @@ export const isOctopusDeployAvailable: (entity: Entity) => boolean; // @public (undocumented) export const OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION = 'octopus.com/project-id'; +// @public (undocumented) +export const OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION = 'octopus.com/space-id'; + // @public (undocumented) export interface OctopusDeployApi { // (undocumented) getReleaseProgression( projectId: string, + spaceId: string | null, releaseHistoryCount: number, ): Promise; } @@ -44,6 +48,7 @@ export class OctopusDeployClient implements OctopusDeployApi { // (undocumented) getReleaseProgression( projectId: string, + spaceId: string | null, releaseHistoryCount: number, ): Promise; } diff --git a/plugins/octopus-deploy/src/constants.ts b/plugins/octopus-deploy/src/constants.ts index b7786c3a64..cb3b2356af 100644 --- a/plugins/octopus-deploy/src/constants.ts +++ b/plugins/octopus-deploy/src/constants.ts @@ -16,4 +16,5 @@ /** @public */ export const OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION = 'octopus.com/project-id'; +/** @public */ export const OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION = 'octopus.com/space-id'; From 7f8936c3cf0a72c11037ac50b8b606f5caecbbef Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 18 Apr 2023 08:47:59 +0200 Subject: [PATCH 05/17] Reverted unnecessary changes Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/octopus-deploy/package.json b/plugins/octopus-deploy/package.json index 92e29a33f4..b4ae8d397d 100644 --- a/plugins/octopus-deploy/package.json +++ b/plugins/octopus-deploy/package.json @@ -1,6 +1,6 @@ { "name": "@backstage/plugin-octopus-deploy", - "version": "0.1.2-next.0", + "version": "0.1.1-next.1", "main": "src/index.ts", "types": "src/index.ts", "license": "Apache-2.0", From f54026a64dc265c91dedacb07da87cc0e499ba50 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 18 Apr 2023 08:53:09 +0200 Subject: [PATCH 06/17] Break API for once Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/src/api/index.ts | 44 +++++++++++++------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/plugins/octopus-deploy/src/api/index.ts b/plugins/octopus-deploy/src/api/index.ts index c74df08617..b9dcf330bf 100644 --- a/plugins/octopus-deploy/src/api/index.ts +++ b/plugins/octopus-deploy/src/api/index.ts @@ -57,11 +57,11 @@ const DEFAULT_PROXY_PATH_BASE = '/octopus-deploy'; /** @public */ export interface OctopusDeployApi { - getReleaseProgression( - projectId: string, - spaceId: string | null, - releaseHistoryCount: number, - ): Promise; + getReleaseProgression(opts: { + projectId: string; + spaceId?: string; + releaseHistoryCount: number; + }): Promise; } /** @public */ @@ -80,12 +80,12 @@ export class OctopusDeployClient implements OctopusDeployApi { this.proxyPathBase = options.proxyPathBase ?? DEFAULT_PROXY_PATH_BASE; } - async getReleaseProgression( - projectId: string, - spaceId: string | null, - releaseHistoryCount: number, - ): Promise { - const url = await this.getApiUrl(projectId, spaceId, releaseHistoryCount); + async getReleaseProgression(opts: { + projectId: string; + spaceId?: string; + releaseHistoryCount: number; + }): Promise { + const url = await this.getApiUrl(opts); const response = await this.fetchApi.fetch(url); @@ -108,23 +108,25 @@ export class OctopusDeployClient implements OctopusDeployApi { return responseJson; } - private async getApiUrl( - projectId: string, - spaceId: string | null, - releaseHistoryCount: number, - ) { + private async getApiUrl(opts: { + projectId: string; + spaceId?: string; + releaseHistoryCount: number; + }) { const proxyUrl = await this.discoveryApi.getBaseUrl('proxy'); const queryParameters = new URLSearchParams({ - releaseHistoryCount: releaseHistoryCount.toString(), + releaseHistoryCount: opts.releaseHistoryCount.toString(), }); - if (spaceId !== null) + if (opts.spaceId !== undefined) { return `${proxyUrl}${this.proxyPathBase}/${encodeURIComponent( - spaceId, + opts.spaceId, )}/projects/${encodeURIComponent( - projectId, + opts.projectId, )}/progression?${queryParameters}`; + } + return `${proxyUrl}${this.proxyPathBase}/projects/${encodeURIComponent( - projectId, + opts.projectId, )}/progression?${queryParameters}`; } } From f1622e1eafe62cd119765216e5a586616a0fedfe Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 18 Apr 2023 09:00:23 +0200 Subject: [PATCH 07/17] React to breaking change Signed-off-by: Jonathan Mezach --- .../EntityPageOctopusDeploy.tsx | 6 +++--- plugins/octopus-deploy/src/hooks/useReleases.ts | 14 +++++++------- .../src/utils/getAnnotationFromEntity.ts | 6 ++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx index b263c67566..34ff780f70 100644 --- a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx +++ b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx @@ -28,11 +28,11 @@ export const EntityPageOctopusDeploy = (props: { defaultLimit?: number }) => { const projectId = getProjectIdAnnotationFromEntity(entity); const spaceId = getSpaceIdAnnotationFromEntity(entity); - const { environments, releases, loading, error } = useReleases( + const { environments, releases, loading, error } = useReleases({ projectId, spaceId, - props.defaultLimit ?? 3, - ); + releaseHistoryCount: props.defaultLimit ?? 3, + }); return ( { - return api.getReleaseProgression(projectId, spaceId, releaseHistoryCount); - }, [api, projectId, spaceId, releaseHistoryCount]); + return api.getReleaseProgression(opts); + }, [api, opts]); return { environments: value?.Environments, diff --git a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts index 5c4a2e1788..14d8739962 100644 --- a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts +++ b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts @@ -32,9 +32,11 @@ export function getProjectIdAnnotationFromEntity(entity: Entity): string { return annotation; } -export function getSpaceIdAnnotationFromEntity(entity: Entity): string | null { +export function getSpaceIdAnnotationFromEntity( + entity: Entity, +): string | undefined { const annotation = entity.metadata.annotations?.[OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION]; - return annotation || null; + return annotation || undefined; } From 26d2e605fb28ceeb5348fb7ebbd987120ef12b46 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 18 Apr 2023 09:03:26 +0200 Subject: [PATCH 08/17] Fix up API report Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/api-report.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/octopus-deploy/api-report.md b/plugins/octopus-deploy/api-report.md index 2a4a60e443..96497b6adf 100644 --- a/plugins/octopus-deploy/api-report.md +++ b/plugins/octopus-deploy/api-report.md @@ -28,11 +28,11 @@ export const OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION = 'octopus.com/space-id'; // @public (undocumented) export interface OctopusDeployApi { // (undocumented) - getReleaseProgression( - projectId: string, - spaceId: string | null, - releaseHistoryCount: number, - ): Promise; + getReleaseProgression(opts: { + projectId: string; + spaceId?: string; + releaseHistoryCount: number; + }): Promise; } // @public (undocumented) @@ -46,11 +46,11 @@ export class OctopusDeployClient implements OctopusDeployApi { proxyPathBase?: string; }); // (undocumented) - getReleaseProgression( - projectId: string, - spaceId: string | null, - releaseHistoryCount: number, - ): Promise; + getReleaseProgression(opts: { + projectId: string; + spaceId?: string; + releaseHistoryCount: number; + }): Promise; } // @public (undocumented) From 2f18f97f987d769c30bfc6273796d9250226ada2 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 18 Apr 2023 10:40:04 +0200 Subject: [PATCH 09/17] Fix endless loop Signed-off-by: Jonathan Mezach --- .../EntityPageOctopusDeploy.tsx | 6 +++--- .../octopus-deploy/src/hooks/useReleases.ts | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx index 34ff780f70..5fc035595c 100644 --- a/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx +++ b/plugins/octopus-deploy/src/components/EntityPageOctopusDeploy/EntityPageOctopusDeploy.tsx @@ -28,11 +28,11 @@ export const EntityPageOctopusDeploy = (props: { defaultLimit?: number }) => { const projectId = getProjectIdAnnotationFromEntity(entity); const spaceId = getSpaceIdAnnotationFromEntity(entity); - const { environments, releases, loading, error } = useReleases({ + const { environments, releases, loading, error } = useReleases( projectId, + props.defaultLimit ?? 3, spaceId, - releaseHistoryCount: props.defaultLimit ?? 3, - }); + ); return ( { - return api.getReleaseProgression(opts); - }, [api, opts]); + return api.getReleaseProgression({ + projectId, + spaceId, + releaseHistoryCount, + }); + }, [api, projectId, spaceId, releaseHistoryCount]); return { environments: value?.Environments, From 43aa5cab96279770bdd7381a3eb697e56a4cf2f7 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Mon, 24 Apr 2023 18:45:55 +0200 Subject: [PATCH 10/17] Simplify to one annotation Signed-off-by: Jonathan Mezach --- .../EntityPageOctopusDeploy.tsx | 12 +++------ plugins/octopus-deploy/src/constants.ts | 2 -- plugins/octopus-deploy/src/index.ts | 5 +--- .../src/utils/getAnnotationFromEntity.ts | 26 ++++++++----------- 4 files changed, 16 insertions(+), 29 deletions(-) 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] }; } From 1f5988656b6b230f1a9e398ad6b2119e53ab2850 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Mon, 24 Apr 2023 18:57:35 +0200 Subject: [PATCH 11/17] Update changeset Signed-off-by: Jonathan Mezach --- .changeset/red-cheetahs-invite.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/red-cheetahs-invite.md b/.changeset/red-cheetahs-invite.md index 8e86764132..439de70dc7 100644 --- a/.changeset/red-cheetahs-invite.md +++ b/.changeset/red-cheetahs-invite.md @@ -2,4 +2,5 @@ '@backstage/plugin-octopus-deploy': minor --- -Added support for octopus deploy spaces. +Added support for Octopus Deploy spaces. The octopus.com/project-id annotation can now (optionally) be prefixed by a space identifier, ie. Spaces-1/Projects-102. +Also note that some of this plugins exported API's have changed to accomodate this change, changing from separate arguments to a single object. From 974979fb7cfee145d1330ce94bb63675385f8f59 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Mon, 24 Apr 2023 19:01:34 +0200 Subject: [PATCH 12/17] Updated API report Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/api-report.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/octopus-deploy/api-report.md b/plugins/octopus-deploy/api-report.md index 96497b6adf..55b44a0ce9 100644 --- a/plugins/octopus-deploy/api-report.md +++ b/plugins/octopus-deploy/api-report.md @@ -22,9 +22,6 @@ export const isOctopusDeployAvailable: (entity: Entity) => boolean; // @public (undocumented) export const OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION = 'octopus.com/project-id'; -// @public (undocumented) -export const OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION = 'octopus.com/space-id'; - // @public (undocumented) export interface OctopusDeployApi { // (undocumented) From 92c40cf1861a0f935c5b75805069f502212210fa Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Mon, 24 Apr 2023 19:04:35 +0200 Subject: [PATCH 13/17] Fix some spelling mistakes Signed-off-by: Jonathan Mezach --- .changeset/red-cheetahs-invite.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/red-cheetahs-invite.md b/.changeset/red-cheetahs-invite.md index 439de70dc7..ef1711c761 100644 --- a/.changeset/red-cheetahs-invite.md +++ b/.changeset/red-cheetahs-invite.md @@ -2,5 +2,5 @@ '@backstage/plugin-octopus-deploy': minor --- -Added support for Octopus Deploy spaces. The octopus.com/project-id annotation can now (optionally) be prefixed by a space identifier, ie. Spaces-1/Projects-102. -Also note that some of this plugins exported API's have changed to accomodate this change, changing from separate arguments to a single object. +Added support for Octopus Deploy spaces. The octopus.com/project-id annotation can now (optionally) be prefixed by a space identifier, for example. Spaces-1/Projects-102. +Also note that some of this plugins exported API's have changed to accommodate this change, changing from separate arguments to a single object. From 31c872ed7c3b7b59950900a664d1ee4f70ac06a3 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 2 May 2023 13:03:30 +0200 Subject: [PATCH 14/17] Fix docs Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/octopus-deploy/README.md b/plugins/octopus-deploy/README.md index 0901163bcf..6039856998 100644 --- a/plugins/octopus-deploy/README.md +++ b/plugins/octopus-deploy/README.md @@ -42,9 +42,9 @@ const cicdContent = ( ) ``` -3. Add `octopus.com/project-id` and optionally an `octopus.com/space-id` annotation in the catalog descriptor file. +3. Add `octopus.com/project-id` annotation in the catalog descriptor file. -To obtain a projects ID you will have to query the Octopus API. You can get the space ID from the projects URL in the octopus deploy UI. In the future we'll add support for using a projects slug as well. +To obtain a projects ID you will have to query the Octopus API. In the future we'll add support for using a projects slug as well. ``` // catalog-info.yaml @@ -58,4 +58,20 @@ spec: type: service ``` +If your project is not part of the default space you can add the space ID to the annotation as a prefix. For example: + +``` +// catalog-info.yaml +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + # ... + annotations: + octopus.com/project-id: Spaces-2/Projects-102 +spec: + type: service +``` + +You can get the ID of the space from the URL in the Octopus Deploy UI. + All set, you will be able to see the plugin in action! From 7dc02fa5b5c4b9e093680253de5e468c9a91335c Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 2 May 2023 13:06:46 +0200 Subject: [PATCH 15/17] Restore package version Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/octopus-deploy/package.json b/plugins/octopus-deploy/package.json index b4ae8d397d..92e29a33f4 100644 --- a/plugins/octopus-deploy/package.json +++ b/plugins/octopus-deploy/package.json @@ -1,6 +1,6 @@ { "name": "@backstage/plugin-octopus-deploy", - "version": "0.1.1-next.1", + "version": "0.1.2-next.0", "main": "src/index.ts", "types": "src/index.ts", "license": "Apache-2.0", From 4ff2cd81971f268d5c8281abf870d69b370db08c Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 2 May 2023 13:16:17 +0200 Subject: [PATCH 16/17] Change API to use projectReference Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/src/api/index.ts | 18 ++++++++---------- .../octopus-deploy/src/hooks/useReleases.ts | 3 +-- .../src/utils/getAnnotationFromEntity.ts | 1 + 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/octopus-deploy/src/api/index.ts b/plugins/octopus-deploy/src/api/index.ts index b9dcf330bf..0364bed269 100644 --- a/plugins/octopus-deploy/src/api/index.ts +++ b/plugins/octopus-deploy/src/api/index.ts @@ -18,6 +18,7 @@ import { DiscoveryApi, FetchApi, } from '@backstage/core-plugin-api'; +import { ProjectReference } from '../utils/getAnnotationFromEntity'; /** @public */ export type OctopusProgression = { @@ -58,8 +59,7 @@ const DEFAULT_PROXY_PATH_BASE = '/octopus-deploy'; /** @public */ export interface OctopusDeployApi { getReleaseProgression(opts: { - projectId: string; - spaceId?: string; + projectReference: ProjectReference; releaseHistoryCount: number; }): Promise; } @@ -81,8 +81,7 @@ export class OctopusDeployClient implements OctopusDeployApi { } async getReleaseProgression(opts: { - projectId: string; - spaceId?: string; + projectReference: ProjectReference; releaseHistoryCount: number; }): Promise { const url = await this.getApiUrl(opts); @@ -109,24 +108,23 @@ export class OctopusDeployClient implements OctopusDeployApi { } private async getApiUrl(opts: { - projectId: string; - spaceId?: string; + projectReference: ProjectReference; releaseHistoryCount: number; }) { const proxyUrl = await this.discoveryApi.getBaseUrl('proxy'); const queryParameters = new URLSearchParams({ releaseHistoryCount: opts.releaseHistoryCount.toString(), }); - if (opts.spaceId !== undefined) { + if (opts.projectReference.spaceId !== undefined) { return `${proxyUrl}${this.proxyPathBase}/${encodeURIComponent( - opts.spaceId, + opts.projectReference.spaceId, )}/projects/${encodeURIComponent( - opts.projectId, + opts.projectReference.projectId, )}/progression?${queryParameters}`; } return `${proxyUrl}${this.proxyPathBase}/projects/${encodeURIComponent( - opts.projectId, + opts.projectReference.projectId, )}/progression?${queryParameters}`; } } diff --git a/plugins/octopus-deploy/src/hooks/useReleases.ts b/plugins/octopus-deploy/src/hooks/useReleases.ts index 56897ec5ed..671a0a7e7f 100644 --- a/plugins/octopus-deploy/src/hooks/useReleases.ts +++ b/plugins/octopus-deploy/src/hooks/useReleases.ts @@ -35,8 +35,7 @@ export function useReleases( const { value, loading, error } = useAsync(() => { return api.getReleaseProgression({ - projectId, - spaceId, + projectReference: { projectId, spaceId }, releaseHistoryCount, }); }, [api, projectId, spaceId, releaseHistoryCount]); diff --git a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts index 29881a1daa..80ebaab76a 100644 --- a/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts +++ b/plugins/octopus-deploy/src/utils/getAnnotationFromEntity.ts @@ -17,6 +17,7 @@ import { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from '../constants'; import { Entity } from '@backstage/catalog-model'; +/** @public */ export type ProjectReference = { projectId: string; spaceId?: string }; export function getProjectReferenceAnnotationFromEntity( From 8d4b350afd34718d801a538012777bf80ee2e312 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 2 May 2023 13:21:35 +0200 Subject: [PATCH 17/17] Regenerate API report Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/api-report.md | 12 ++++++++---- plugins/octopus-deploy/src/index.ts | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/octopus-deploy/api-report.md b/plugins/octopus-deploy/api-report.md index 55b44a0ce9..53c92403bd 100644 --- a/plugins/octopus-deploy/api-report.md +++ b/plugins/octopus-deploy/api-report.md @@ -26,8 +26,7 @@ export const OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION = 'octopus.com/project-id'; export interface OctopusDeployApi { // (undocumented) getReleaseProgression(opts: { - projectId: string; - spaceId?: string; + projectReference: ProjectReference; releaseHistoryCount: number; }): Promise; } @@ -44,8 +43,7 @@ export class OctopusDeployClient implements OctopusDeployApi { }); // (undocumented) getReleaseProgression(opts: { - projectId: string; - spaceId?: string; + projectReference: ProjectReference; releaseHistoryCount: number; }): Promise; } @@ -84,5 +82,11 @@ export type OctopusReleaseProgression = { }; }; +// @public (undocumented) +export type ProjectReference = { + projectId: string; + spaceId?: string; +}; + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/octopus-deploy/src/index.ts b/plugins/octopus-deploy/src/index.ts index e3264efaf0..2b39431606 100644 --- a/plugins/octopus-deploy/src/index.ts +++ b/plugins/octopus-deploy/src/index.ts @@ -21,4 +21,6 @@ export { export * from './api'; +export type { ProjectReference } from './utils/getAnnotationFromEntity'; + export { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from './constants';