From 4ff2cd81971f268d5c8281abf870d69b370db08c Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 2 May 2023 13:16:17 +0200 Subject: [PATCH] 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(