diff --git a/apps/server/prisma/schema.prisma b/apps/server/prisma/schema.prisma index d2f50a3..ffc2653 100644 --- a/apps/server/prisma/schema.prisma +++ b/apps/server/prisma/schema.prisma @@ -238,6 +238,8 @@ model GitHubSync { projectName String projectUrl String issueCount Int @default(0) + onlyIssueCount Int @default(0) + prCount Int @default(0) todoCount Int @default(0) inProgressCount Int @default(0) doneCount Int @default(0) diff --git a/apps/server/src/services/githubService.ts b/apps/server/src/services/githubService.ts index 2b75676..b9dcd0c 100644 --- a/apps/server/src/services/githubService.ts +++ b/apps/server/src/services/githubService.ts @@ -191,6 +191,8 @@ const getGitHubStats = async () => { projectName: latest.projectName, stats: { total: latest.issueCount, + issues: latest.onlyIssueCount, + pullRequests: latest.prCount, todo: latest.todoCount, inProgress: latest.inProgressCount, done: latest.doneCount, @@ -424,17 +426,54 @@ const syncGitHubStatsFromGitHub = async () => { ); } - const [todoCount, inProgressCount, doneCount] = await Promise.all([ - tx.gitHubSyncItem.count({ where: { syncId: sync.id, status: "todo" } }), - tx.gitHubSyncItem.count({ where: { syncId: sync.id, status: "in-progress" } }), - tx.gitHubSyncItem.count({ where: { syncId: sync.id, status: "done" } }), - ]); + const groupedStats = await tx.gitHubSyncItem.groupBy({ + by: ["status", "kind"], + where: { + syncId: sync.id, + }, + _count: { + id: true, + }, + }); + + let todoCount = 0; + let inProgressCount = 0; + let doneCount = 0; + + let onlyIssueCount = 0; + let prCount = 0; + + for (const item of groupedStats) { + const count = item._count.id; + + //status counts + if (item.status === "todo") { + todoCount += count; + } + + if (item.status === "in-progress") { + inProgressCount += count; + } + + if (item.status === "done") { + doneCount += count; + } + + //kind counts + if (item.kind === "issue") { + onlyIssueCount += count; + } + + if (item.kind === "pull-request") { + prCount += count; + } + } - const issueCount = todoCount + inProgressCount + doneCount; + const issueCount = onlyIssueCount + prCount; return tx.gitHubSync.update({ where: { id: sync.id }, - data: { issueCount, todoCount, inProgressCount, doneCount }, + data: { issueCount, todoCount, inProgressCount, doneCount, onlyIssueCount, prCount }, }); }, { timeout: 30000 },