Renamed the parameter to teamsLimit, reran api report, tsc, lint, and tests.
Signed-off-by: Quadman <QuadmanSWE@gmail.com>
This commit is contained in:
@@ -3,4 +3,4 @@
|
||||
'@backstage/plugin-azure-devops': patch
|
||||
---
|
||||
|
||||
`getAllTeams` now accepts an optional `topTeams` parameter which can be used to return more than the default top 100 teams from the Azure DevOps API
|
||||
`getAllTeams` now accepts an optional `teamsLimit` parameter which can be used to return more than the default limit of 100 teams from the Azure DevOps API
|
||||
|
||||
@@ -56,7 +56,7 @@ export class AzureDevOpsApi {
|
||||
},
|
||||
): AzureDevOpsApi;
|
||||
// (undocumented)
|
||||
getAllTeams(topTeams?: number): Promise<Team[]>;
|
||||
getAllTeams(teamsLimit?: number): Promise<Team[]>;
|
||||
// (undocumented)
|
||||
getBuildDefinitions(
|
||||
projectName: string,
|
||||
|
||||
@@ -397,7 +397,7 @@ export class AzureDevOpsApi {
|
||||
.filter((policy): policy is Policy => Boolean(policy));
|
||||
}
|
||||
|
||||
public async getAllTeams(topTeams?: number): Promise<Team[]> {
|
||||
public async getAllTeams(teamsLimit?: number): Promise<Team[]> {
|
||||
this.logger?.debug('Getting all teams.');
|
||||
|
||||
const webApi = await this.getWebApi();
|
||||
@@ -405,7 +405,7 @@ export class AzureDevOpsApi {
|
||||
|
||||
const webApiTeams: WebApiTeam[] = await client.getAllTeams(
|
||||
undefined,
|
||||
topTeams,
|
||||
teamsLimit,
|
||||
undefined,
|
||||
undefined,
|
||||
);
|
||||
|
||||
@@ -25,7 +25,7 @@ import { AzureDevOpsApi } from './AzureDevOpsApi';
|
||||
import { Logger } from 'winston';
|
||||
import limiterFactory from 'p-limit';
|
||||
|
||||
export const DEFAULT_TOP_TEAMS = 100;
|
||||
export const DEFAULT_TEAMS_LIMIT = 100;
|
||||
|
||||
export class PullRequestsDashboardProvider {
|
||||
private teams = new Map<string, Team>();
|
||||
@@ -45,10 +45,10 @@ export class PullRequestsDashboardProvider {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public async readTeams(topTeams?: number): Promise<void> {
|
||||
public async readTeams(teamsLimit?: number): Promise<void> {
|
||||
this.logger.info('Reading teams.');
|
||||
|
||||
let teams = await this.azureDevOpsApi.getAllTeams(topTeams);
|
||||
let teams = await this.azureDevOpsApi.getAllTeams(teamsLimit);
|
||||
|
||||
// This is used to filter out the default Azure Devops project teams.
|
||||
teams = teams.filter(team =>
|
||||
@@ -108,12 +108,12 @@ export class PullRequestsDashboardProvider {
|
||||
public async getDashboardPullRequests(
|
||||
projectName: string,
|
||||
options: PullRequestOptions,
|
||||
topTeams?: number,
|
||||
teamsLimit?: number,
|
||||
): Promise<DashboardPullRequest[]> {
|
||||
const dashboardPullRequests =
|
||||
await this.azureDevOpsApi.getDashboardPullRequests(projectName, options);
|
||||
|
||||
await this.getAllTeams(topTeams); // Make sure team members are loaded
|
||||
await this.getAllTeams(teamsLimit); // Make sure team members are loaded
|
||||
|
||||
return dashboardPullRequests.map(pr => {
|
||||
if (pr.createdBy?.id) {
|
||||
@@ -137,9 +137,9 @@ export class PullRequestsDashboardProvider {
|
||||
);
|
||||
}
|
||||
|
||||
public async getAllTeams(topTeams?: number): Promise<Team[]> {
|
||||
public async getAllTeams(teamsLimit?: number): Promise<Team[]> {
|
||||
if (!this.teams.size) {
|
||||
const maxTeams = topTeams ?? DEFAULT_TOP_TEAMS;
|
||||
const maxTeams = teamsLimit ?? DEFAULT_TEAMS_LIMIT;
|
||||
await this.readTeams(maxTeams);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import { Config } from '@backstage/config';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
PullRequestsDashboardProvider,
|
||||
DEFAULT_TOP_TEAMS,
|
||||
DEFAULT_TEAMS_LIMIT,
|
||||
} from '../api/PullRequestsDashboardProvider';
|
||||
import Router from 'express-promise-router';
|
||||
import { errorHandler, UrlReader } from '@backstage/backend-common';
|
||||
@@ -230,9 +230,9 @@ export async function createRouter(
|
||||
const { projectName } = req.params;
|
||||
|
||||
const top = req.query.top ? Number(req.query.top) : DEFAULT_TOP;
|
||||
const topTeams = req.query.topTeams
|
||||
? Number(req.query.topTeams)
|
||||
: DEFAULT_TOP_TEAMS;
|
||||
const teamsLimit = req.query.teamsLimit
|
||||
? Number(req.query.teamsLimit)
|
||||
: DEFAULT_TEAMS_LIMIT;
|
||||
|
||||
const status = req.query.status
|
||||
? Number(req.query.status)
|
||||
@@ -267,17 +267,19 @@ export async function createRouter(
|
||||
await pullRequestsDashboardProvider.getDashboardPullRequests(
|
||||
projectName,
|
||||
pullRequestOptions,
|
||||
topTeams,
|
||||
teamsLimit,
|
||||
);
|
||||
|
||||
res.status(200).json(pullRequests);
|
||||
});
|
||||
|
||||
router.get('/all-teams', async (req, res) => {
|
||||
const topTeams = req.query.topTeams
|
||||
? Number(req.query.topTeams)
|
||||
const teamsLimit = req.query.teamsLimit
|
||||
? Number(req.query.teamsLimit)
|
||||
: undefined;
|
||||
const allTeams = await pullRequestsDashboardProvider.getAllTeams(topTeams);
|
||||
const allTeams = await pullRequestsDashboardProvider.getAllTeams(
|
||||
teamsLimit,
|
||||
);
|
||||
res.status(200).json(allTeams);
|
||||
});
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ export type AssignedToUserFilter = BaseFilter &
|
||||
// @public (undocumented)
|
||||
export interface AzureDevOpsApi {
|
||||
// (undocumented)
|
||||
getAllTeams(topTeams?: number): Promise<Team[]>;
|
||||
getAllTeams(teamsLimit?: number): Promise<Team[]>;
|
||||
// (undocumented)
|
||||
getBuildRuns(
|
||||
projectName: string,
|
||||
@@ -81,7 +81,7 @@ export interface AzureDevOpsApi {
|
||||
// (undocumented)
|
||||
getDashboardPullRequests(
|
||||
projectName: string,
|
||||
topTeams?: number,
|
||||
teamsLimit?: number,
|
||||
): Promise<DashboardPullRequest[]>;
|
||||
// (undocumented)
|
||||
getGitTags(
|
||||
@@ -127,7 +127,7 @@ export const azureDevOpsApiRef: ApiRef<AzureDevOpsApi>;
|
||||
export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
constructor(options: { discoveryApi: DiscoveryApi; fetchApi: FetchApi });
|
||||
// (undocumented)
|
||||
getAllTeams(topTeams?: number): Promise<Team[]>;
|
||||
getAllTeams(teamsLimit?: number): Promise<Team[]>;
|
||||
// (undocumented)
|
||||
getBuildRuns(
|
||||
projectName: string,
|
||||
@@ -143,7 +143,7 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
// (undocumented)
|
||||
getDashboardPullRequests(
|
||||
projectName: string,
|
||||
topTeams?: number,
|
||||
teamsLimit?: number,
|
||||
): Promise<DashboardPullRequest[]>;
|
||||
// (undocumented)
|
||||
getGitTags(
|
||||
@@ -195,7 +195,7 @@ export const AzurePullRequestsPage: (props: {
|
||||
projectName?: string | undefined;
|
||||
pollingInterval?: number | undefined;
|
||||
defaultColumnConfigs?: PullRequestColumnConfig[] | undefined;
|
||||
topTeams?: number | undefined;
|
||||
teamsLimit?: number | undefined;
|
||||
}) => JSX_2.Element;
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -64,10 +64,10 @@ export interface AzureDevOpsApi {
|
||||
|
||||
getDashboardPullRequests(
|
||||
projectName: string,
|
||||
topTeams?: number,
|
||||
teamsLimit?: number,
|
||||
): Promise<DashboardPullRequest[]>;
|
||||
|
||||
getAllTeams(topTeams?: number): Promise<Team[]>;
|
||||
getAllTeams(teamsLimit?: number): Promise<Team[]>;
|
||||
|
||||
getUserTeamIds(userId: string): Promise<string[]>;
|
||||
|
||||
|
||||
@@ -124,21 +124,21 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
|
||||
public getDashboardPullRequests(
|
||||
projectName: string,
|
||||
topTeams?: number,
|
||||
teamsLimit?: number,
|
||||
): Promise<DashboardPullRequest[]> {
|
||||
const queryString = new URLSearchParams();
|
||||
queryString.append('top', '100');
|
||||
if (topTeams) {
|
||||
queryString.append('topTeams', topTeams.toString());
|
||||
if (teamsLimit) {
|
||||
queryString.append('teamsLimit', teamsLimit.toString());
|
||||
}
|
||||
const urlSegment = `dashboard-pull-requests/${projectName}?${queryString}`;
|
||||
return this.get<DashboardPullRequest[]>(urlSegment);
|
||||
}
|
||||
|
||||
public getAllTeams(topTeams?: number): Promise<Team[]> {
|
||||
public getAllTeams(teamsLimit?: number): Promise<Team[]> {
|
||||
const queryString = new URLSearchParams();
|
||||
if (topTeams) {
|
||||
queryString.append('topTeams', topTeams.toString());
|
||||
if (teamsLimit) {
|
||||
queryString.append('teamsLimit', teamsLimit.toString());
|
||||
}
|
||||
let urlSegment = 'all-teams';
|
||||
if (queryString.toString()) {
|
||||
|
||||
@@ -70,17 +70,17 @@ type PullRequestsPageProps = {
|
||||
projectName?: string;
|
||||
pollingInterval?: number;
|
||||
defaultColumnConfigs?: PullRequestColumnConfig[];
|
||||
topTeams?: number;
|
||||
teamsLimit?: number;
|
||||
};
|
||||
|
||||
export const PullRequestsPage = (props: PullRequestsPageProps) => {
|
||||
const { projectName, pollingInterval, defaultColumnConfigs, topTeams } =
|
||||
const { projectName, pollingInterval, defaultColumnConfigs, teamsLimit } =
|
||||
props;
|
||||
|
||||
const { pullRequests, loading, error } = useDashboardPullRequests(
|
||||
projectName,
|
||||
pollingInterval,
|
||||
topTeams,
|
||||
teamsLimit,
|
||||
);
|
||||
|
||||
const [columnConfigs] = useState(
|
||||
|
||||
@@ -27,7 +27,7 @@ const POLLING_INTERVAL = 10000;
|
||||
export function useDashboardPullRequests(
|
||||
project?: string,
|
||||
pollingInterval: number = POLLING_INTERVAL,
|
||||
topTeams?: number,
|
||||
teamsLimit?: number,
|
||||
): {
|
||||
pullRequests?: DashboardPullRequest[];
|
||||
loading: boolean;
|
||||
@@ -44,7 +44,7 @@ export function useDashboardPullRequests(
|
||||
}
|
||||
|
||||
try {
|
||||
return await api.getDashboardPullRequests(project, topTeams);
|
||||
return await api.getDashboardPullRequests(project, teamsLimit);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
errorApi.post(error);
|
||||
@@ -52,7 +52,7 @@ export function useDashboardPullRequests(
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}, [project, api, topTeams, errorApi]);
|
||||
}, [project, api, teamsLimit, errorApi]);
|
||||
|
||||
const {
|
||||
value: pullRequests,
|
||||
|
||||
Reference in New Issue
Block a user