Skip to content

Commit 38b7a4b

Browse files
feat(compare): add Pull Requests and Issues count to StatBattle
1 parent 7f6cb5c commit 38b7a4b

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

app/(root)/dashboard/[username]/page.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ describe('DashboardPage', () => {
9494
peakStreak: 15,
9595
totalContributions: 500,
9696
codingHabit: 'Night Owl',
97+
totalPRs: 10,
98+
totalIssues: 5,
9799
},
98100
languages: [{ name: 'TypeScript', percentage: 100, color: '#3178c6' }],
99101
activity: [],

app/compare/CompareClient.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
Plus,
2323
Minus,
2424
Code2,
25+
GitPullRequest,
26+
CircleDot,
2527
} from 'lucide-react';
2628

2729
/* ── types ────────────────────────────────────────────────────────────── */
@@ -48,6 +50,8 @@ interface UserStats {
4850
peakStreak: number;
4951
totalContributions: number;
5052
codingHabit?: string;
53+
totalPRs?: number;
54+
totalIssues?: number;
5155
}
5256

5357
interface LanguageData {
@@ -890,6 +894,18 @@ export default function CompareClient() {
890894
valueA={d1.profile.stats.followers}
891895
valueB={d2.profile.stats.followers}
892896
/>
897+
<StatBattle
898+
label="Pull Requests"
899+
icon={GitPullRequest}
900+
valueA={d1.stats.totalPRs || 0}
901+
valueB={d2.stats.totalPRs || 0}
902+
/>
903+
<StatBattle
904+
label="Issues"
905+
icon={CircleDot}
906+
valueA={d1.stats.totalIssues || 0}
907+
valueB={d2.stats.totalIssues || 0}
908+
/>
893909
</div>
894910
</div>
895911

lib/github.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ interface GitHubGraphQLResponse {
222222
data?: {
223223
user: {
224224
contributionsCollection: {
225+
totalPullRequestContributions: number;
226+
totalIssueContributions: number;
225227
contributionCalendar: ContributionCalendar;
226228
commitContributionsByRepository: RepoContribution[];
227229
};
@@ -482,6 +484,8 @@ async function fetchContributionsUncached(
482484
query($login: String!, $from: DateTime, $to: DateTime) {
483485
user(login: $login) {
484486
contributionsCollection(from: $from, to: $to) {
487+
totalPullRequestContributions
488+
totalIssueContributions
485489
contributionCalendar {
486490
totalContributions
487491
weeks {
@@ -557,12 +561,17 @@ async function fetchContributionsUncached(
557561
};
558562
}
559563

564+
let totalPRs = data.data.user.contributionsCollection?.totalPullRequestContributions || 0;
565+
let totalIssues = data.data.user.contributionsCollection?.totalIssueContributions || 0;
566+
560567
if (isDeltaSync && cached) {
561568
calendar = mergeCalendars(
562569
cached.calendar,
563570
calendar,
564571
data.data.user.contributionsCollection.contributionCalendar.totalContributions
565572
);
573+
totalPRs += cached.totalPRs || 0;
574+
totalIssues += cached.totalIssues || 0;
566575
}
567576
// Inject deterministic Lines of Code (LoC) approximation
568577
// Since GitHub's contributionCalendar doesn't provide native LoC metrics,
@@ -604,13 +613,17 @@ async function fetchContributionsUncached(
604613
{
605614
calendar,
606615
repoContributions,
616+
totalPRs,
617+
totalIssues,
607618
},
608619
LONG_CACHE_TTL
609620
);
610621
}
611622
return {
612623
calendar,
613624
repoContributions,
625+
totalPRs,
626+
totalIssues,
614627
};
615628
}
616629

@@ -1277,6 +1290,9 @@ export async function getFullDashboardData(username: string, options: FetchOptio
12771290
peakStreak: streakStats.longestStreak,
12781291
totalContributions: streakStats.totalContributions,
12791292
codingHabit: getDeterministicHabit(profileData.login),
1293+
totalPRs: calendarResult.status === 'fulfilled' ? (calendarResult.value.totalPRs ?? 0) : 0,
1294+
totalIssues:
1295+
calendarResult.status === 'fulfilled' ? (calendarResult.value.totalIssues ?? 0) : 0,
12801296
},
12811297
languages,
12821298
activity: buildActivityMap(allDays),

types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ export interface RepoContribution {
9595
export interface ExtendedContributionData {
9696
calendar: ContributionCalendar;
9797
repoContributions: RepoContribution[];
98+
totalPRs?: number;
99+
totalIssues?: number;
98100
isOfflineFallback?: boolean;
99101
}
100102

0 commit comments

Comments
 (0)