Skip to content

Commit 1981061

Browse files
committed
update contributions block
1 parent eef6294 commit 1981061

File tree

8 files changed

+55
-13
lines changed

8 files changed

+55
-13
lines changed

app/profile/[login]/profile-summary.gql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ query User($login: String!) {
5757
contributions {
5858
year
5959
prsCount
60+
mergedPrsCount
61+
linesAdded
62+
linesRemoved
6063
repository {
6164
...RepositoryFields
6265
}

app/profile/[login]/repositories/components/contribution-repository-card.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,45 @@ import { RepositoryCard } from './repository-card';
88
type RepositoryCardProps = {
99
repository?: Repository | null;
1010
prsCount?: number | null;
11+
mergedPrsCount?: number | null;
12+
linesAdded?: number | null;
13+
linesRemoved?: number | null;
1114
login: string;
1215
};
1316

14-
export const ContributionRepositoryCard: FC<RepositoryCardProps> = ({ repository, prsCount, login }) => {
17+
const PR_FETCH_LIMIT = 20;
18+
19+
export const ContributionRepositoryCard: FC<RepositoryCardProps> = ({
20+
repository,
21+
prsCount,
22+
mergedPrsCount,
23+
linesAdded,
24+
linesRemoved,
25+
login,
26+
}) => {
1527
if (!repository) {
1628
return null;
1729
}
1830

31+
// total PRs count is greater than PR_FETCH_LIMIT
32+
// and merged PRs count is greater than half of PR_FETCH_LIMIT
33+
const badgeLabel =
34+
(prsCount ?? 0) > PR_FETCH_LIMIT && (mergedPrsCount ?? 0) >= PR_FETCH_LIMIT / 2
35+
? `~${prsCount} PRs`
36+
: `${mergedPrsCount} PR${(mergedPrsCount ?? 0) > 1 ? 's' : ''}`;
37+
1938
return (
2039
<RepositoryCard
2140
type="contribution"
2241
repository={repository}
23-
meta={<Badge variant="secondary">{`${prsCount} contributions`}</Badge>}
42+
meta={
43+
<Badge variant="secondary">
44+
{badgeLabel} <span className="text-positive">+{linesAdded}</span>
45+
<span className="text-negative">-{linesRemoved}</span>
46+
</Badge>
47+
}
2448
login={login}
25-
className="md:border-0 md:border-b-1 last:md:border-b-0 rounded-none md:pl-0"
49+
className="md:border-0 md:border-b-1 last:md:border-b-0 p-4 pl-0 md:pl-0 md:rounded-none"
2650
/>
2751
);
2852
};

app/profile/[login]/repositories/components/repository-card.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Link from 'next/link';
44
import { FC, ReactNode } from 'react';
55

66
import { Badge } from '@/components/ui/badge';
7+
import { cn } from '@/lib/utils';
78
import { Repository } from '@/types/generated/graphql';
89

910
import { ProfileCard, ProfileCardContent, ProfileCardHeader } from '../../components/profile-card';
@@ -29,7 +30,7 @@ export const RepositoryCard: FC<RepositoryCardProps> = ({
2930

3031
const { name, url, pushedAt, createdAt, stargazerCount, forkCount, releasesCount, isArchived } = repository;
3132

32-
const titleUrl = type === 'repository' ? url : `${url}/pulls?q=is%3Apr+author%3A${login}`;
33+
const titleUrl = type === 'repository' ? url : `${url}/pulls?q=is%3Apr+is%3Amerged+author%3A${login}`;
3334

3435
const getMeta = () => {
3536
if (meta) {
@@ -44,7 +45,9 @@ export const RepositoryCard: FC<RepositoryCardProps> = ({
4445
};
4546

4647
return (
47-
<ProfileCard className={className}>
48+
<ProfileCard
49+
className={cn('border-b-1 last:border-b-0 md:last:border-b rounded-none md:rounded-xl pb-4', className)}
50+
>
4851
<ProfileCardHeader meta={getMeta()}>
4952
<Link href={titleUrl} target="_blank" rel="noopener noreferrer" className="whitespace-nowrap">
5053
{name}

app/profile/[login]/repositories/components/user-contriutions-list.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const UserContriutionsList: FC<UserContriutionsListProps> = ({ contributi
2020

2121
return (
2222
<>
23-
<h2 className="text-xl font-semibold">Contributions</h2>
23+
<h2 className="text-xl font-semibold mt-6">Contributions</h2>
2424
<Timeline>
2525
{sortedContributions.map((contribution) => (
2626
<TimelineItem key={contribution.year}>
@@ -33,6 +33,9 @@ export const UserContriutionsList: FC<UserContriutionsListProps> = ({ contributi
3333
key={item.repository?.githubId}
3434
repository={item.repository}
3535
prsCount={item.prsCount}
36+
mergedPrsCount={item.mergedPrsCount}
37+
linesAdded={item.linesAdded}
38+
linesRemoved={item.linesRemoved}
3639
login={login}
3740
/>
3841
))}

app/profile/[login]/repositories/components/user-repositories-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const UserRepositoriesList: FC<UserRepositoriesListProps> = ({ login, rep
2020
<>
2121
<h2 className="text-xl font-semibold">Repositories</h2>
2222
<div className="flex flex-col gap-6">
23-
<div className="flex flex-col md:flex-row flex-wrap gap-6">
23+
<div className="flex flex-col md:flex-row flex-wrap gap-4 md:gap-6">
2424
{repositories?.map((repo) => (
2525
<RepositoryCard key={repo.githubId} repository={repo} login={login} />
2626
))}

app/profile/[login]/utils/contrib-group-and-sort.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ export const groupAndSortContributions = (contributions: Contribution[]) => {
1414
.map(([year, data]) => ({
1515
year: Number(year),
1616
data: data.sort((a, b) => {
17-
// Primary: prsCount DESC, Secondary: stargazersCount DESC
18-
if (b.prsCount !== a.prsCount) return b.prsCount - a.prsCount;
17+
// Primary: mergedPrsCount DESC, Secondary: stargazersCount DESC
18+
if (b.mergedPrsCount !== a.mergedPrsCount) {
19+
return b.mergedPrsCount - a.mergedPrsCount;
20+
}
21+
1922
return (b.repository?.stargazerCount ?? 0) - (a.repository?.stargazerCount ?? 0);
2023
}),
2124
}))

types/generated/graphql.ts

Lines changed: 6 additions & 3 deletions
Large diffs are not rendered by default.

types/generated/schema.graphql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
type Contribution {
2-
prsCount: Int!
2+
linesAdded: Int
3+
linesRemoved: Int
4+
mergedPrsCount: Int
5+
prsCount: Int
36
repoId: String
47
repository: Repository
58
year: Int!

0 commit comments

Comments
 (0)