Merge pull request #7643 from marleypowell/marley/7641-export-ado-types
refactor(`@backstage/plugin-azure-devops-backend`): re-exported types from `azure-devops-node-api`
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-azure-devops-backend': patch
|
||||
---
|
||||
|
||||
Re-exported types from azure-devops-node-api in @backstage/plugin-azure-devops-backend.
|
||||
@@ -45,6 +45,10 @@ export class AzureDevOpsApi {
|
||||
): Promise<RepoBuild[]>;
|
||||
}
|
||||
|
||||
export { BuildResult };
|
||||
|
||||
export { BuildStatus };
|
||||
|
||||
// Warning: (ae-missing-release-tag) "createRouter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -14,42 +14,47 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Logger } from 'winston';
|
||||
import { WebApi } from 'azure-devops-node-api';
|
||||
import {
|
||||
Build,
|
||||
BuildResult,
|
||||
BuildStatus,
|
||||
} from 'azure-devops-node-api/interfaces/BuildInterfaces';
|
||||
import {
|
||||
GitPullRequest,
|
||||
GitPullRequestSearchCriteria,
|
||||
} from 'azure-devops-node-api/interfaces/GitInterfaces';
|
||||
import { PullRequest, PullRequestOptions, RepoBuild } from './types';
|
||||
GitRepository,
|
||||
PullRequest,
|
||||
PullRequestOptions,
|
||||
RepoBuild,
|
||||
} from './types';
|
||||
|
||||
import { Logger } from 'winston';
|
||||
import { WebApi } from 'azure-devops-node-api';
|
||||
|
||||
export class AzureDevOpsApi {
|
||||
constructor(
|
||||
public constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly webApi: WebApi,
|
||||
) {}
|
||||
|
||||
async getGitRepository(projectName: string, repoName: string) {
|
||||
if (this.logger) {
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
public async getGitRepository(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
): Promise<GitRepository> {
|
||||
this.logger?.debug(
|
||||
`Calling Azure DevOps REST API, getting Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
|
||||
const client = await this.webApi.getGitApi();
|
||||
return client.getRepository(repoName, projectName);
|
||||
}
|
||||
|
||||
async getBuildList(projectName: string, repoId: string, top: number) {
|
||||
if (this.logger) {
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Builds for Repository Id ${repoId} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
public async getBuildList(
|
||||
projectName: string,
|
||||
repoId: string,
|
||||
top: number,
|
||||
): Promise<Build[]> {
|
||||
this.logger?.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Builds for Repository Id ${repoId} for Project ${projectName}`,
|
||||
);
|
||||
|
||||
const client = await this.webApi.getBuildApi();
|
||||
return client.getBuilds(
|
||||
@@ -77,12 +82,14 @@ export class AzureDevOpsApi {
|
||||
);
|
||||
}
|
||||
|
||||
async getRepoBuilds(projectName: string, repoName: string, top: number) {
|
||||
if (this.logger) {
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Builds for Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
public async getRepoBuilds(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
top: number,
|
||||
) {
|
||||
this.logger?.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Builds for Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
|
||||
const gitRepository = await this.getGitRepository(projectName, repoName);
|
||||
const buildList = await this.getBuildList(
|
||||
@@ -98,16 +105,14 @@ export class AzureDevOpsApi {
|
||||
return repoBuilds;
|
||||
}
|
||||
|
||||
async getPullRequests(
|
||||
public async getPullRequests(
|
||||
projectName: string,
|
||||
repoName: string,
|
||||
options: PullRequestOptions,
|
||||
) {
|
||||
if (this.logger) {
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Pull Requests for Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
): Promise<PullRequest[]> {
|
||||
this.logger?.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Pull Requests for Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
|
||||
const gitRepository = await this.getGitRepository(projectName, repoName);
|
||||
const client = await this.webApi.getGitApi();
|
||||
@@ -133,7 +138,7 @@ export class AzureDevOpsApi {
|
||||
}
|
||||
}
|
||||
|
||||
export function mappedRepoBuild(build: Build) {
|
||||
export function mappedRepoBuild(build: Build): RepoBuild {
|
||||
return {
|
||||
id: build.id,
|
||||
title: [build.definition?.name, build.buildNumber]
|
||||
@@ -150,7 +155,7 @@ export function mappedRepoBuild(build: Build) {
|
||||
export function mappedPullRequest(
|
||||
pullRequest: GitPullRequest,
|
||||
linkBaseUrl: string,
|
||||
) {
|
||||
): PullRequest {
|
||||
return {
|
||||
pullRequestId: pullRequest.pullRequestId,
|
||||
repoName: pullRequest.repository?.name,
|
||||
|
||||
@@ -15,4 +15,5 @@
|
||||
*/
|
||||
|
||||
export { AzureDevOpsApi } from './AzureDevOpsApi';
|
||||
export { BuildResult, BuildStatus } from './types';
|
||||
export type { RepoBuild, PullRequest } from './types';
|
||||
|
||||
@@ -15,10 +15,24 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
Build,
|
||||
BuildResult,
|
||||
BuildStatus,
|
||||
} from 'azure-devops-node-api/interfaces/BuildInterfaces';
|
||||
import { PullRequestStatus } from 'azure-devops-node-api/interfaces/GitInterfaces';
|
||||
import {
|
||||
GitPullRequest,
|
||||
GitPullRequestSearchCriteria,
|
||||
GitRepository,
|
||||
PullRequestStatus,
|
||||
} from 'azure-devops-node-api/interfaces/GitInterfaces';
|
||||
|
||||
export { BuildResult, BuildStatus, PullRequestStatus };
|
||||
export type {
|
||||
Build,
|
||||
GitPullRequest,
|
||||
GitPullRequestSearchCriteria,
|
||||
GitRepository,
|
||||
};
|
||||
|
||||
export type RepoBuild = {
|
||||
id?: number;
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export { AzureDevOpsApi } from './api';
|
||||
export { AzureDevOpsApi, BuildResult, BuildStatus } from './api';
|
||||
export type { RepoBuild, PullRequest } from './api';
|
||||
export * from './service/router';
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PullRequestOptions, PullRequestStatus } from '../api/types';
|
||||
import { WebApi, getPersonalAccessTokenHandler } from 'azure-devops-node-api';
|
||||
|
||||
import { AzureDevOpsApi } from '../api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Logger } from 'winston';
|
||||
import Router from 'express-promise-router';
|
||||
import { errorHandler } from '@backstage/backend-common';
|
||||
import express from 'express';
|
||||
import Router from 'express-promise-router';
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
import { getPersonalAccessTokenHandler, WebApi } from 'azure-devops-node-api';
|
||||
import { AzureDevOpsApi } from '../api';
|
||||
import { PullRequestStatus } from 'azure-devops-node-api/interfaces/GitInterfaces';
|
||||
import { PullRequestOptions } from '../api/types';
|
||||
|
||||
const DEFAULT_TOP: number = 10;
|
||||
|
||||
|
||||
@@ -14,26 +14,27 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { DateTime } from 'luxon';
|
||||
import {
|
||||
Link,
|
||||
Table,
|
||||
TableColumn,
|
||||
StatusError,
|
||||
StatusOK,
|
||||
StatusWarning,
|
||||
StatusAborted,
|
||||
StatusRunning,
|
||||
StatusPending,
|
||||
ResponseErrorPanel,
|
||||
} from '@backstage/core-components';
|
||||
import { Box, Typography } from '@material-ui/core';
|
||||
import { RepoBuild } from '../../api/types';
|
||||
import {
|
||||
BuildResult,
|
||||
BuildStatus,
|
||||
} from 'azure-devops-node-api/interfaces/BuildInterfaces';
|
||||
import {
|
||||
Link,
|
||||
ResponseErrorPanel,
|
||||
StatusAborted,
|
||||
StatusError,
|
||||
StatusOK,
|
||||
StatusPending,
|
||||
StatusRunning,
|
||||
StatusWarning,
|
||||
Table,
|
||||
TableColumn,
|
||||
} from '@backstage/core-components';
|
||||
|
||||
import { DateTime } from 'luxon';
|
||||
import React from 'react';
|
||||
import { RepoBuild } from '../../api/types';
|
||||
|
||||
const getBuildResultComponent = (result: number | undefined) => {
|
||||
switch (result) {
|
||||
@@ -154,13 +155,13 @@ const columns: TableColumn[] = [
|
||||
},
|
||||
];
|
||||
|
||||
type Props = {
|
||||
type BuildTableProps = {
|
||||
items?: RepoBuild[];
|
||||
loading: boolean;
|
||||
error?: any;
|
||||
error?: Error;
|
||||
};
|
||||
|
||||
export const BuildTable = ({ items, loading, error }: Props) => {
|
||||
export const BuildTable = ({ items, loading, error }: BuildTableProps) => {
|
||||
if (error) {
|
||||
return (
|
||||
<div>
|
||||
@@ -180,7 +181,7 @@ export const BuildTable = ({ items, loading, error }: Props) => {
|
||||
showEmptyDataSourceMessage: !loading,
|
||||
}}
|
||||
title={`Builds (${items ? items.length : 0})`}
|
||||
data={items || []}
|
||||
data={items ?? []}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -14,28 +14,31 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useAsync } from 'react-use';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
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';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { azureDevOpsApiRef } from '../api';
|
||||
import { useApi } from '@backstage/core-plugin-api';
|
||||
import { useAsync } from 'react-use';
|
||||
import { useProjectRepoFromEntity } from './useProjectRepoFromEntity';
|
||||
|
||||
export function useRepoBuilds(
|
||||
entity: Entity,
|
||||
defaultLimit?: number,
|
||||
): {
|
||||
items: RepoBuild[] | undefined;
|
||||
items?: RepoBuild[];
|
||||
loading: boolean;
|
||||
error: any;
|
||||
error?: Error;
|
||||
} {
|
||||
const top = defaultLimit ?? AZURE_DEVOPS_DEFAULT_TOP;
|
||||
const options: RepoBuildOptions = {
|
||||
top: top,
|
||||
};
|
||||
|
||||
const api = useApi(azureDevOpsApiRef);
|
||||
const { project, repo } = useProjectRepoFromEntity(entity);
|
||||
|
||||
const { value, loading, error } = useAsync(() => {
|
||||
return api.getRepoBuilds(project, repo, options);
|
||||
}, [api, project, repo, entity]);
|
||||
|
||||
Reference in New Issue
Block a user