Refactor getAllTeams method to accept options parameter.
Added teamsLimit parameter to PullRequestDashBoardProvider options Signed-off-by: Quadman <QuadmanSWE@gmail.com>
This commit is contained in:
@@ -108,12 +108,11 @@ export class PullRequestsDashboardProvider {
|
||||
public async getDashboardPullRequests(
|
||||
projectName: string,
|
||||
options: PullRequestOptions,
|
||||
teamsLimit?: number,
|
||||
): Promise<DashboardPullRequest[]> {
|
||||
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<string[]> {
|
||||
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<Team[]> {
|
||||
public async getAllTeams(options: { limit?: number }): Promise<Team[]> {
|
||||
if (!this.teams.size) {
|
||||
const maxTeams = limit ?? DEFAULT_TEAMS_LIMIT;
|
||||
const maxTeams = options?.limit ?? DEFAULT_TEAMS_LIMIT;
|
||||
await this.readTeams(maxTeams);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ export type PullRequest = {
|
||||
export type PullRequestOptions = {
|
||||
top: number;
|
||||
status: PullRequestStatus;
|
||||
teamsLimit?: number;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user