diff --git a/.changeset/brown-beers-share.md b/.changeset/brown-beers-share.md index 9fae8ffda9..4ca548ebb4 100644 --- a/.changeset/brown-beers-share.md +++ b/.changeset/brown-beers-share.md @@ -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 diff --git a/plugins/azure-devops-backend/api-report.md b/plugins/azure-devops-backend/api-report.md index f80f023661..ae78098400 100644 --- a/plugins/azure-devops-backend/api-report.md +++ b/plugins/azure-devops-backend/api-report.md @@ -56,7 +56,7 @@ export class AzureDevOpsApi { }, ): AzureDevOpsApi; // (undocumented) - getAllTeams(topTeams?: number): Promise; + getAllTeams(teamsLimit?: number): Promise; // (undocumented) getBuildDefinitions( projectName: string, diff --git a/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts b/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts index 18d0e41358..08fa157204 100644 --- a/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts +++ b/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts @@ -397,7 +397,7 @@ export class AzureDevOpsApi { .filter((policy): policy is Policy => Boolean(policy)); } - public async getAllTeams(topTeams?: number): Promise { + public async getAllTeams(teamsLimit?: number): Promise { 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, ); diff --git a/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts b/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts index 6605bfbd07..9d927cdfa1 100644 --- a/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts +++ b/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts @@ -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(); @@ -45,10 +45,10 @@ export class PullRequestsDashboardProvider { return provider; } - public async readTeams(topTeams?: number): Promise { + public async readTeams(teamsLimit?: number): Promise { 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 { 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 { + public async getAllTeams(teamsLimit?: number): Promise { if (!this.teams.size) { - const maxTeams = topTeams ?? DEFAULT_TOP_TEAMS; + const maxTeams = teamsLimit ?? DEFAULT_TEAMS_LIMIT; await this.readTeams(maxTeams); } diff --git a/plugins/azure-devops-backend/src/service/router.ts b/plugins/azure-devops-backend/src/service/router.ts index b9ea1c6cf4..dd41cf636f 100644 --- a/plugins/azure-devops-backend/src/service/router.ts +++ b/plugins/azure-devops-backend/src/service/router.ts @@ -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); }); diff --git a/plugins/azure-devops/api-report.md b/plugins/azure-devops/api-report.md index cd890edf9f..e470d255d6 100644 --- a/plugins/azure-devops/api-report.md +++ b/plugins/azure-devops/api-report.md @@ -65,7 +65,7 @@ export type AssignedToUserFilter = BaseFilter & // @public (undocumented) export interface AzureDevOpsApi { // (undocumented) - getAllTeams(topTeams?: number): Promise; + getAllTeams(teamsLimit?: number): Promise; // (undocumented) getBuildRuns( projectName: string, @@ -81,7 +81,7 @@ export interface AzureDevOpsApi { // (undocumented) getDashboardPullRequests( projectName: string, - topTeams?: number, + teamsLimit?: number, ): Promise; // (undocumented) getGitTags( @@ -127,7 +127,7 @@ export const azureDevOpsApiRef: ApiRef; export class AzureDevOpsClient implements AzureDevOpsApi { constructor(options: { discoveryApi: DiscoveryApi; fetchApi: FetchApi }); // (undocumented) - getAllTeams(topTeams?: number): Promise; + getAllTeams(teamsLimit?: number): Promise; // (undocumented) getBuildRuns( projectName: string, @@ -143,7 +143,7 @@ export class AzureDevOpsClient implements AzureDevOpsApi { // (undocumented) getDashboardPullRequests( projectName: string, - topTeams?: number, + teamsLimit?: number, ): Promise; // (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) diff --git a/plugins/azure-devops/src/api/AzureDevOpsApi.ts b/plugins/azure-devops/src/api/AzureDevOpsApi.ts index 31704f4314..6f839d824d 100644 --- a/plugins/azure-devops/src/api/AzureDevOpsApi.ts +++ b/plugins/azure-devops/src/api/AzureDevOpsApi.ts @@ -64,10 +64,10 @@ export interface AzureDevOpsApi { getDashboardPullRequests( projectName: string, - topTeams?: number, + teamsLimit?: number, ): Promise; - getAllTeams(topTeams?: number): Promise; + getAllTeams(teamsLimit?: number): Promise; getUserTeamIds(userId: string): Promise; diff --git a/plugins/azure-devops/src/api/AzureDevOpsClient.ts b/plugins/azure-devops/src/api/AzureDevOpsClient.ts index 25e23f65a6..8b0bf50523 100644 --- a/plugins/azure-devops/src/api/AzureDevOpsClient.ts +++ b/plugins/azure-devops/src/api/AzureDevOpsClient.ts @@ -124,21 +124,21 @@ export class AzureDevOpsClient implements AzureDevOpsApi { public getDashboardPullRequests( projectName: string, - topTeams?: number, + teamsLimit?: number, ): Promise { 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(urlSegment); } - public getAllTeams(topTeams?: number): Promise { + public getAllTeams(teamsLimit?: number): Promise { 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()) { diff --git a/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx b/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx index 0c87bd7f54..ed35545812 100644 --- a/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx +++ b/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx @@ -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( diff --git a/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts b/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts index 73e3cf687a..f812b2abbb 100644 --- a/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts +++ b/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts @@ -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,