Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
53 changes: 46 additions & 7 deletions apps/server/src/services/githubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 },
Expand Down
Loading