From f54026a64dc265c91dedacb07da87cc0e499ba50 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 18 Apr 2023 08:53:09 +0200 Subject: [PATCH] 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}`; } }