Skip to content

Commit

Permalink
made project endpoint fail gracefully when rich info fetching fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ZibanPirate committed Apr 15, 2023
1 parent a9ee143 commit b5c2f60
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions api/src/project/controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AccountEntity } from "@dzcode.io/models/dist/account";
import { Controller, Get } from "routing-controllers";
import { OpenAPI, ResponseSchema } from "routing-controllers-openapi";
import { DataService } from "src/data/service";
Expand Down Expand Up @@ -34,35 +35,34 @@ export class ProjectController {
repositories: await Promise.all(
repositories.map(async ({ provider, owner, repository }) => {
let contributionCount = 0;
let contributors: AccountEntity[] = [];
let languages: string[] = [];
try {
contributionCount = (
await this.githubService.listRepositoryIssues({ owner, repository })
).length;
[contributionCount, contributors, languages] = await Promise.all([
(await this.githubService.listRepositoryIssues({ owner, repository })).length,
await Promise.all(
(
await this.githubService.listRepositoryContributors({ owner, repository })
).map(async ({ login }) => {
const githubUser = await this.githubService.getUser({ username: login });
return this.githubService.githubUserToAccountEntity(githubUser);
}),
),
await this.githubService.listRepositoryLanguages({ owner, repository }),
]);
} catch (error) {
this.loggerService.warn({
message: `Failed to fetch contributionCount for ${owner}/${repository}: ${error}`,
meta: { owner, repository },
this.loggerService.error({
message: `Failed to fetch rich info for project: ${owner}/${repository}`,
meta: { owner, repository, error },
});
}

return {
provider,
owner,
repository,
stats: {
contributionCount,
languages: await this.githubService.listRepositoryLanguages({
owner,
repository,
}),
},
contributors: await Promise.all(
(
await this.githubService.listRepositoryContributors({ owner, repository })
).map(async ({ login }) => {
const githubUser = await this.githubService.getUser({ username: login });
return this.githubService.githubUserToAccountEntity(githubUser);
}),
),
stats: { contributionCount, languages },
contributors,
};
}),
),
Expand Down

0 comments on commit b5c2f60

Please sign in to comment.