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 <gchristie@bunnings.com.au>
This commit is contained in:
committed by
Jonathan Mezach
parent
d1797f0e91
commit
87211bc287
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-octopus-deploy': minor
|
||||
---
|
||||
|
||||
Added support for octopus deploy spaces.
|
||||
@@ -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:^",
|
||||
|
||||
@@ -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 = (
|
||||
<EntityAzurePipelinesContent defaultLimit={25} />
|
||||
</EntitySwitch.Case>
|
||||
|
||||
<EntitySwitch.Case if={isOctopusDeployAvailable}>
|
||||
<EntityOctopusDeployContent defaultLimit={25} />
|
||||
</EntitySwitch.Case>
|
||||
|
||||
<EntitySwitch.Case>
|
||||
<EmptyState
|
||||
title="No CI/CD available for this entity"
|
||||
|
||||
@@ -42,9 +42,9 @@ const cicdContent = (
|
||||
)
|
||||
```
|
||||
|
||||
3. Add `octopus.com/project-id` annotation in catalog descriptor file
|
||||
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. 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
|
||||
@@ -58,4 +58,4 @@ spec:
|
||||
type: service
|
||||
```
|
||||
|
||||
All set , you will be able to see the plugin in action!
|
||||
All set, you will be able to see the plugin in action!
|
||||
|
||||
@@ -59,6 +59,7 @@ const DEFAULT_PROXY_PATH_BASE = '/octopus-deploy';
|
||||
export interface OctopusDeployApi {
|
||||
getReleaseProgression(
|
||||
projectId: string,
|
||||
spaceId: string | null,
|
||||
releaseHistoryCount: number,
|
||||
): Promise<OctopusProgression>;
|
||||
}
|
||||
@@ -81,9 +82,10 @@ export class OctopusDeployClient implements OctopusDeployApi {
|
||||
|
||||
async getReleaseProgression(
|
||||
projectId: string,
|
||||
spaceId: string | null,
|
||||
releaseHistoryCount: number,
|
||||
): Promise<OctopusProgression> {
|
||||
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}`;
|
||||
|
||||
+7
-2
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user