Skip to content

Commit 972e986

Browse files
authored
refactor(github): handle null GitHub names safely (JhaSourav07#483)
## Description Fixes JhaSourav07#388 This PR addresses the issue by handling cases where a GitHub user has a null or empty string name. - Extracts `displayName` helper function to encapsulate fallback logic. - Uses proper TypeScript type guards (`typeof profile.name === 'string'`) and `trim()` to handle valid names, empty strings, and null names gracefully. - Replaces inline `||` fallback behavior with the helper usage. - Fallback behavior (to `profile.login`) and other behaviors remain unchanged without any regressions. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="751" height="467" alt="2026-05-25_23-28-18" src="https://github.com/user-attachments/assets/92f51b80-802a-4ecd-b66e-551cd7d21fb1" /> ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 9918dc2 + 8d1bf1d commit 972e986

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)