diff --git a/api/src/project/controller.ts b/api/src/project/controller.ts index f6515e2ca..b5403d8f1 100644 --- a/api/src/project/controller.ts +++ b/api/src/project/controller.ts @@ -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"; @@ -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, }; }), ),