diff --git a/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts b/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts index c4e0e46774..6605bfbd07 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'; -const DEFAULT_TOP_TEAMS = 100; +export const DEFAULT_TOP_TEAMS = 100; export class PullRequestsDashboardProvider { private teams = new Map(); @@ -108,11 +108,12 @@ export class PullRequestsDashboardProvider { public async getDashboardPullRequests( projectName: string, options: PullRequestOptions, + topTeams?: number, ): Promise { const dashboardPullRequests = await this.azureDevOpsApi.getDashboardPullRequests(projectName, options); - await this.getAllTeams(); // Make sure team members are loaded + await this.getAllTeams(topTeams); // Make sure team members are loaded return dashboardPullRequests.map(pr => { if (pr.createdBy?.id) { diff --git a/plugins/azure-devops-backend/src/service/router.ts b/plugins/azure-devops-backend/src/service/router.ts index d77ed16d29..b9ea1c6cf4 100644 --- a/plugins/azure-devops-backend/src/service/router.ts +++ b/plugins/azure-devops-backend/src/service/router.ts @@ -23,7 +23,10 @@ import { import { AzureDevOpsApi } from '../api'; import { Config } from '@backstage/config'; import { Logger } from 'winston'; -import { PullRequestsDashboardProvider } from '../api/PullRequestsDashboardProvider'; +import { + PullRequestsDashboardProvider, + DEFAULT_TOP_TEAMS, +} from '../api/PullRequestsDashboardProvider'; import Router from 'express-promise-router'; import { errorHandler, UrlReader } from '@backstage/backend-common'; import express from 'express'; @@ -227,6 +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 status = req.query.status ? Number(req.query.status) @@ -261,6 +267,7 @@ export async function createRouter( await pullRequestsDashboardProvider.getDashboardPullRequests( projectName, pullRequestOptions, + topTeams, ); res.status(200).json(pullRequests); diff --git a/plugins/azure-devops/src/api/AzureDevOpsApi.ts b/plugins/azure-devops/src/api/AzureDevOpsApi.ts index e6a5af7766..31704f4314 100644 --- a/plugins/azure-devops/src/api/AzureDevOpsApi.ts +++ b/plugins/azure-devops/src/api/AzureDevOpsApi.ts @@ -64,6 +64,7 @@ export interface AzureDevOpsApi { getDashboardPullRequests( projectName: string, + topTeams?: number, ): Promise; getAllTeams(topTeams?: number): Promise; diff --git a/plugins/azure-devops/src/api/AzureDevOpsClient.ts b/plugins/azure-devops/src/api/AzureDevOpsClient.ts index 422d4b3cd7..25e23f65a6 100644 --- a/plugins/azure-devops/src/api/AzureDevOpsClient.ts +++ b/plugins/azure-devops/src/api/AzureDevOpsClient.ts @@ -124,10 +124,15 @@ export class AzureDevOpsClient implements AzureDevOpsApi { public getDashboardPullRequests( projectName: string, + topTeams?: number, ): Promise { - return this.get( - `dashboard-pull-requests/${projectName}?top=100`, - ); + const queryString = new URLSearchParams(); + queryString.append('top', '100'); + if (topTeams) { + queryString.append('topTeams', topTeams.toString()); + } + const urlSegment = `dashboard-pull-requests/${projectName}?${queryString}`; + return this.get(urlSegment); } public getAllTeams(topTeams?: number): Promise { diff --git a/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx b/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx index 5971a03afd..0c87bd7f54 100644 --- a/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx +++ b/plugins/azure-devops/src/components/PullRequestsPage/PullRequestsPage.tsx @@ -70,14 +70,17 @@ type PullRequestsPageProps = { projectName?: string; pollingInterval?: number; defaultColumnConfigs?: PullRequestColumnConfig[]; + topTeams?: number; }; export const PullRequestsPage = (props: PullRequestsPageProps) => { - const { projectName, pollingInterval, defaultColumnConfigs } = props; + const { projectName, pollingInterval, defaultColumnConfigs, topTeams } = + props; const { pullRequests, loading, error } = useDashboardPullRequests( projectName, pollingInterval, + topTeams, ); const [columnConfigs] = useState( diff --git a/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts b/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts index 8ace9663fa..73e3cf687a 100644 --- a/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts +++ b/plugins/azure-devops/src/hooks/useDashboardPullRequests.ts @@ -27,6 +27,7 @@ const POLLING_INTERVAL = 10000; export function useDashboardPullRequests( project?: string, pollingInterval: number = POLLING_INTERVAL, + topTeams?: number, ): { pullRequests?: DashboardPullRequest[]; loading: boolean; @@ -43,7 +44,7 @@ export function useDashboardPullRequests( } try { - return await api.getDashboardPullRequests(project); + return await api.getDashboardPullRequests(project, topTeams); } catch (error) { if (error instanceof Error) { errorApi.post(error); @@ -51,7 +52,7 @@ export function useDashboardPullRequests( return Promise.reject(error); } - }, [project, api, errorApi]); + }, [project, api, topTeams, errorApi]); const { value: pullRequests,