Another round of improvements
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -436,5 +436,3 @@ azureDevOps:
|
||||
host: dev.azure.com
|
||||
token: my-token
|
||||
organization: my-company
|
||||
azurePipelines:
|
||||
top: 25
|
||||
|
||||
@@ -188,7 +188,7 @@ export const cicdContent = (
|
||||
</EntitySwitch.Case>
|
||||
|
||||
<EntitySwitch.Case if={isAzureDevOpsAvailable}>
|
||||
<EntityAzurePipelinesContent />
|
||||
<EntityAzurePipelinesContent defaultLimit={25} />
|
||||
</EntitySwitch.Case>
|
||||
|
||||
<EntitySwitch.Case>
|
||||
|
||||
@@ -17,8 +17,6 @@ azureDevOps:
|
||||
host: dev.azure.com
|
||||
token: ${AZURE_TOKEN}
|
||||
organization: my-company
|
||||
azurePipelines:
|
||||
top: 50
|
||||
```
|
||||
|
||||
Configuration Details:
|
||||
@@ -26,7 +24,6 @@ Configuration Details:
|
||||
- `host` and `token` can be the same as the ones used for the `integration` section
|
||||
- `AZURE_TOKEN` environment variable must be set to a [Personal Access Token](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page) with read access to both Code and Build
|
||||
- `organization` is your Azure DevOps Organization name or for Azure DevOps Server (on-premise) this will be your Collection name
|
||||
- `top` is strictly used by the frontend to limit the number of items returned, if not provided it defaults to 10. Currently only used for Builds
|
||||
|
||||
### Backend
|
||||
|
||||
@@ -96,7 +93,9 @@ To get the frontend working you'll need to do the following two steps:
|
||||
<EntitySwitch>
|
||||
// ...
|
||||
<EntitySwitch.Case if={isAzureDevOpsAvailable}>
|
||||
<EntityAzurePipelinesContent />
|
||||
// Set defaultLimit to the max number of builds you would like to be able to see
|
||||
// the default if not set is 10
|
||||
<EntityAzurePipelinesContent defaultLimit={25} />
|
||||
</EntitySwitch.Case>
|
||||
// ...
|
||||
</EntitySwitch>
|
||||
|
||||
Vendored
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export interface Config {
|
||||
/** Configuration options for the azure-devops-backend plugin */
|
||||
azureDevOps: {
|
||||
azurePipelines: {
|
||||
/**
|
||||
* The max number of items to return - applies to builds
|
||||
* @visibility frontend
|
||||
*/
|
||||
top: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -57,8 +57,6 @@
|
||||
"msw": "^0.29.0"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"config.d.ts"
|
||||
],
|
||||
"configSchema": "config.d.ts"
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -31,17 +31,18 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
this.identityApi = options.identityApi;
|
||||
}
|
||||
|
||||
getRepoBuilds(
|
||||
async getRepoBuilds(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
options?: RepoBuildOptions,
|
||||
): Promise<{ items: RepoBuild[] }> {
|
||||
return this.get(
|
||||
const items = await this.get<RepoBuild[]>(
|
||||
`repo-builds/${projectName}/${repoName}?top=${options?.top}`,
|
||||
);
|
||||
return { items };
|
||||
}
|
||||
|
||||
private async get(path: string): Promise<{ items: any }> {
|
||||
private async get<T>(path: string): Promise<T> {
|
||||
const baseUrl = `${await this.discoveryApi.getBaseUrl('azure-devops')}/`;
|
||||
const url = new URL(path, baseUrl);
|
||||
|
||||
@@ -54,6 +55,6 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
throw await ResponseError.fromResponse(response);
|
||||
}
|
||||
|
||||
return response.json() as Promise<{ items: any }>;
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -19,9 +19,13 @@ import React from 'react';
|
||||
import { useRepoBuilds } from '../../hooks/useRepoBuilds';
|
||||
import { BuildTable } from '../BuildTable/BuildTable';
|
||||
|
||||
export const EntityPageAzurePipelines = () => {
|
||||
export const EntityPageAzurePipelines = ({
|
||||
defaultLimit,
|
||||
}: {
|
||||
defaultLimit?: number;
|
||||
}) => {
|
||||
const { entity } = useEntity();
|
||||
const { items, loading, error } = useRepoBuilds(entity);
|
||||
const { items, loading, error } = useRepoBuilds(entity, defaultLimit);
|
||||
|
||||
return <BuildTable items={items} loading={loading} error={error} />;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ import { MissingAnnotationEmptyState } from '@backstage/core-components';
|
||||
export const isAzureDevOpsAvailable = (entity: Entity) =>
|
||||
Boolean(entity.metadata.annotations?.[AZURE_DEVOPS_ANNOTATION]);
|
||||
|
||||
export const Router = () => {
|
||||
export const Router = ({ defaultLimit }: { defaultLimit?: number }) => {
|
||||
const { entity } = useEntity();
|
||||
|
||||
if (!isAzureDevOpsAvailable(entity)) {
|
||||
@@ -36,7 +36,7 @@ export const Router = () => {
|
||||
<Routes>
|
||||
<Route
|
||||
path={`/${azureDevOpsRouteRef.path}`}
|
||||
element={<EntityPageAzurePipelines />}
|
||||
element={<EntityPageAzurePipelines defaultLimit={defaultLimit} />}
|
||||
/>
|
||||
</Routes>
|
||||
);
|
||||
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
import { useAsync } from 'react-use';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { useApi, configApiRef } from '@backstage/core-plugin-api';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { azureDevOpsApiRef } from '../api';
|
||||
import { RepoBuild, RepoBuildOptions } from '../api/types';
|
||||
import { useProjectRepoFromEntity } from './useProjectRepoFromEntity';
|
||||
import { AZURE_DEVOPS_DEFAULT_TOP } from '../constants';
|
||||
|
||||
export function useRepoBuilds(entity: Entity): {
|
||||
export function useRepoBuilds(
|
||||
entity: Entity,
|
||||
defaultLimit?: number,
|
||||
): {
|
||||
items: RepoBuild[];
|
||||
loading: boolean;
|
||||
error: any;
|
||||
} {
|
||||
const config = useApi(configApiRef);
|
||||
const top =
|
||||
config.getOptionalNumber('azureDevOps.azurePipelines.top') ??
|
||||
AZURE_DEVOPS_DEFAULT_TOP;
|
||||
const top = defaultLimit ?? AZURE_DEVOPS_DEFAULT_TOP;
|
||||
const options: RepoBuildOptions = {
|
||||
top: top,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user