azure-devops-backend: only warn if teams fail to load at startup
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-azure-devops-backend': patch
|
||||
---
|
||||
|
||||
Only warn if teams fail to load at startup.
|
||||
@@ -40,7 +40,11 @@ export class PullRequestsDashboardProvider {
|
||||
azureDevOpsApi: AzureDevOpsApi,
|
||||
): Promise<PullRequestsDashboardProvider> {
|
||||
const provider = new PullRequestsDashboardProvider(logger, azureDevOpsApi);
|
||||
await provider.readTeams();
|
||||
try {
|
||||
await provider.readTeams();
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to load azure team information, ${error}`);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
@@ -124,10 +128,12 @@ export class PullRequestsDashboardProvider {
|
||||
});
|
||||
}
|
||||
|
||||
public getUserTeamIds(email: string): string[] {
|
||||
public async getUserTeamIds(email: string): Promise<string[]> {
|
||||
await this.getAllTeams(); // Make sure team members are loaded
|
||||
return (
|
||||
this.getTeamMembers().find(teamMember => teamMember.uniqueName === email)
|
||||
?.memberOf ?? []
|
||||
Array.from(this.teamMembers.values()).find(
|
||||
teamMember => teamMember.uniqueName === email,
|
||||
)?.memberOf ?? []
|
||||
);
|
||||
}
|
||||
|
||||
@@ -138,8 +144,4 @@ export class PullRequestsDashboardProvider {
|
||||
|
||||
return Array.from(this.teams.values());
|
||||
}
|
||||
|
||||
public getTeamMembers(): TeamMember[] {
|
||||
return Array.from(this.teamMembers.values());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('createRouter', () => {
|
||||
getPullRequests: jest.fn(),
|
||||
getBuilds: jest.fn(),
|
||||
getBuildRuns: jest.fn(),
|
||||
getAllTeams: jest.fn().mockReturnValue([]),
|
||||
getAllTeams: jest.fn(),
|
||||
getTeamMembers: jest.fn(),
|
||||
} as any;
|
||||
const router = await createRouter({
|
||||
@@ -411,6 +411,7 @@ describe('createRouter', () => {
|
||||
|
||||
describe('GET /users/:userId/team-ids', () => {
|
||||
it('fetches a a list of teams', async () => {
|
||||
azureDevOpsApi.getAllTeams.mockResolvedValue([]);
|
||||
const response = await request(app).get('/users/user1/team-ids');
|
||||
expect(response.status).toEqual(200);
|
||||
});
|
||||
|
||||
@@ -176,7 +176,7 @@ export async function createRouter(
|
||||
|
||||
router.get('/users/:userId/team-ids', async (req, res) => {
|
||||
const { userId } = req.params;
|
||||
const teamIds = pullRequestsDashboardProvider.getUserTeamIds(userId);
|
||||
const teamIds = await pullRequestsDashboardProvider.getUserTeamIds(userId);
|
||||
res.status(200).json(teamIds);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user