Skip to content

Commit e5dacac

Browse files
authored
🐛 Allow null github or gitlab in contributor list (#542)
1 parent 2f1097e commit e5dacac

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/app/contributors/page.tsx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ type HacktoberfestData = [
2020
github: {
2121
handle: string;
2222
nbContributions: number;
23-
};
23+
} | null;
2424
gitlab: {
2525
handle: string;
2626
nbContributions: number;
27-
};
27+
} | null;
2828
},
2929
][];
3030

@@ -44,18 +44,31 @@ async function getHacktoberfestData(): Promise<HacktoberfestData> {
4444
}
4545

4646
function transformToContributors(data: HacktoberfestData): Contributor[] {
47-
return data.map(([id, contributor]) => ({
48-
id,
49-
name: contributor.name,
50-
avatarUrl: `https://github.com/${contributor.github.handle}.png?size=40`,
51-
imageHint: 'avatar person',
52-
prCount: contributor.github.nbContributions,
53-
mrCount: contributor.gitlab.nbContributions,
54-
totalContributions:
55-
contributor.github.nbContributions + contributor.gitlab.nbContributions,
56-
githubHandle: contributor.github.handle,
57-
gitlabHandle: contributor.gitlab.handle,
58-
}));
47+
return data.map(([id, contributor]) => {
48+
const prCount = contributor.github?.nbContributions ?? 0;
49+
const mrCount = contributor.gitlab?.nbContributions ?? 0;
50+
const githubHandle = contributor.github?.handle;
51+
const gitlabHandle = contributor.gitlab?.handle;
52+
53+
// Use GitHub avatar if available, otherwise use GitLab avatar, or fallback to a default
54+
const avatarUrl = githubHandle
55+
? `https://github.com/${githubHandle}.png?size=40`
56+
: gitlabHandle
57+
? `https://gitlab.com/${gitlabHandle}/avatar?size=40`
58+
: null;
59+
60+
return {
61+
id,
62+
name: contributor.name,
63+
avatarUrl,
64+
imageHint: 'avatar person',
65+
prCount,
66+
mrCount,
67+
totalContributions: prCount + mrCount,
68+
githubHandle,
69+
gitlabHandle,
70+
};
71+
});
5972
}
6073

6174
const getContributors = async (): Promise<Contributor[]> => {

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type Resource = {
3333
export type Contributor = {
3434
id: string;
3535
name: string;
36-
avatarUrl: string;
36+
avatarUrl: string | null;
3737
imageHint: string;
3838
prCount: number;
3939
mrCount: number;

0 commit comments

Comments
 (0)