Skip to content

Commit 8d1bf1d

Browse files
committed
refactor(github): handle null GitHub names safely
1 parent 9918dc2 commit 8d1bf1d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/github.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ export function validateGitHubUsername(username: string): boolean {
122122
return /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i.test(username);
123123
}
124124

125+
export function displayName(profile: GitHubUserProfile): string {
126+
if (typeof profile.name === 'string' && profile.name.trim() !== '') {
127+
return profile.name;
128+
}
129+
return profile.login;
130+
}
131+
125132
export async function fetchGitHubContributions(
126133
username: string,
127134
options: FetchOptions = {}
@@ -355,7 +362,7 @@ export async function getFullDashboardData(username: string, options: FetchOptio
355362
// 1. Profile Mapping
356363
const profile = {
357364
username: profileData.login,
358-
name: profileData.name || profileData.login,
365+
name: displayName(profileData),
359366
avatarUrl: profileData.avatar_url,
360367
isPro: profileData.plan?.name === 'pro',
361368
bio: profileData.bio || 'No bio available',

0 commit comments

Comments
 (0)