From 06980ee398c3636cfe2904ad20809cb2b35ba622 Mon Sep 17 00:00:00 2001 From: Quadman Date: Sun, 7 Apr 2024 18:02:28 +0200 Subject: [PATCH] Refactor getAllTeams method to accept options parameter. Added teamsLimit parameter to PullRequestDashBoardProvider options Signed-off-by: Quadman --- .../src/api/PullRequestsDashboardProvider.ts | 9 ++++----- plugins/azure-devops-backend/src/service/router.ts | 4 ++-- plugins/azure-devops-common/src/types.ts | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts b/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts index 1efbafd842..ec36d17e8c 100644 --- a/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts +++ b/plugins/azure-devops-backend/src/api/PullRequestsDashboardProvider.ts @@ -108,12 +108,11 @@ export class PullRequestsDashboardProvider { public async getDashboardPullRequests( projectName: string, options: PullRequestOptions, - teamsLimit?: number, ): Promise { const dashboardPullRequests = await this.azureDevOpsApi.getDashboardPullRequests(projectName, options); - await this.getAllTeams(teamsLimit); // Make sure team members are loaded + await this.getAllTeams({ limit: options.teamsLimit }); // Make sure team members are loaded return dashboardPullRequests.map(pr => { if (pr.createdBy?.id) { @@ -129,7 +128,7 @@ export class PullRequestsDashboardProvider { } public async getUserTeamIds(email: string): Promise { - await this.getAllTeams(); // Make sure team members are loaded + await this.getAllTeams({}); // Make sure team members are loaded return ( Array.from(this.teamMembers.values()).find( teamMember => teamMember.uniqueName === email, @@ -137,9 +136,9 @@ export class PullRequestsDashboardProvider { ); } - public async getAllTeams(limit?: number): Promise { + public async getAllTeams(options: { limit?: number }): Promise { if (!this.teams.size) { - const maxTeams = limit ?? DEFAULT_TEAMS_LIMIT; + const maxTeams = options?.limit ?? 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 73204193f2..98d719898a 100644 --- a/plugins/azure-devops-backend/src/service/router.ts +++ b/plugins/azure-devops-backend/src/service/router.ts @@ -241,6 +241,7 @@ export async function createRouter( const pullRequestOptions: PullRequestOptions = { top: top, status: status, + teamsLimit: teamsLimit, }; const token = getBearerTokenFromAuthorizationHeader( @@ -267,7 +268,6 @@ export async function createRouter( await pullRequestsDashboardProvider.getDashboardPullRequests( projectName, pullRequestOptions, - teamsLimit, ); res.status(200).json(pullRequests); @@ -275,7 +275,7 @@ export async function createRouter( router.get('/all-teams', async (req, res) => { const limit = req.query.limit ? Number(req.query.limit) : undefined; - const allTeams = await pullRequestsDashboardProvider.getAllTeams(limit); + const allTeams = await pullRequestsDashboardProvider.getAllTeams({ limit }); res.status(200).json(allTeams); }); diff --git a/plugins/azure-devops-common/src/types.ts b/plugins/azure-devops-common/src/types.ts index ab53af66cb..fc98255629 100644 --- a/plugins/azure-devops-common/src/types.ts +++ b/plugins/azure-devops-common/src/types.ts @@ -142,6 +142,7 @@ export type PullRequest = { export type PullRequestOptions = { top: number; status: PullRequestStatus; + teamsLimit?: number; }; /** @public */