Skip to content

Commit 71966aa

Browse files
committed
refactor: simplify dependencies in useQuickWins and enhance user profile return type in GitHubAPIClient
1 parent 9dbedda commit 71966aa

File tree

2 files changed

+72
-19
lines changed

2 files changed

+72
-19
lines changed

src/components/quick-wins/hooks/useQuickWins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function useQuickWins() {
4848
])
4949
}
5050
isInitialized.current = true
51-
}, [loadFromCache, isQuickWinsCacheExpired, goodIssues.length, easyFixes.length, fetchGoodIssues, fetchEasyFixes])
51+
}, [loadFromCache, isQuickWinsCacheExpired, fetchGoodIssues, fetchEasyFixes])
5252

5353
useEffect(() => {
5454
if (goodIssues.length > 0) {

src/lib/api/github-api-client.ts

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type {
22
TrendingRepo,
33
TopContributor
44
} from '@/types/oss-insight'
5+
import type {
6+
GitHubUserDetailed,
7+
GitHubRepositoryDetailed
8+
} from '@/types/github'
59

610
interface GitHubSearchResponse<T> {
711
items: T[]
@@ -558,32 +562,54 @@ async getEasyFixes(): Promise<MappedIssue[]> {
558562

559563
// ============ USER ANALYTICS API METHODS ============
560564

561-
async getUserProfile(username: string): Promise<any> {
565+
async getUserProfile(username: string): Promise<GitHubUserDetailed | null> {
562566
try {
563567
const endpoint = `/users/${username}`
564568
return await this.fetchWithCache(endpoint, true)
565569
} catch (error) {
566570
console.error('Failed to fetch user profile:', error)
567571
// Return fallback profile data
568572
return {
569-
avatar_url: `https://github.com/${username}.png`,
573+
id: 0,
570574
login: username,
571-
type: 'User',
572-
bio: null,
575+
node_id: '',
576+
avatar_url: `https://github.com/${username}.png`,
577+
gravatar_id: '',
578+
url: '',
579+
html_url: `https://github.com/${username}`,
580+
followers_url: '',
581+
following_url: '',
582+
gists_url: '',
583+
starred_url: '',
584+
subscriptions_url: '',
585+
organizations_url: '',
586+
repos_url: '',
587+
events_url: '',
588+
received_events_url: '',
589+
type: 'User' as const,
590+
site_admin: false,
591+
name: undefined,
592+
company: undefined,
593+
blog: undefined,
594+
location: undefined,
595+
email: undefined,
596+
hireable: undefined,
597+
bio: undefined,
598+
twitter_username: undefined,
573599
public_repos: 0,
600+
public_gists: 0,
574601
followers: 0,
575602
following: 0,
576-
location: null,
577-
company: null,
578-
html_url: `https://github.com/${username}`
603+
created_at: new Date().toISOString(),
604+
updated_at: new Date().toISOString()
579605
}
580606
}
581607
}
582608

583-
async getUserRepositories(username: string, limit = 100): Promise<any[]> {
609+
async getUserRepositories(username: string, limit = 100): Promise<GitHubRepositoryDetailed[]> {
584610
try {
585611
const endpoint = `/users/${username}/repos?per_page=${limit}&sort=updated`
586-
const repos = await this.fetchWithCache<any[]>(endpoint, true)
612+
const repos = await this.fetchWithCache<GitHubRepositoryDetailed[]>(endpoint, true)
587613

588614
// Ensure we always return an array
589615
if (Array.isArray(repos)) {
@@ -631,7 +657,7 @@ async getEasyFixes(): Promise<MappedIssue[]> {
631657
}
632658

633659
async getUserAnalytics(username: string): Promise<{
634-
profile: any
660+
profile: GitHubUserDetailed | null
635661
overview: Array<{ name: string; commits: number; stars: number; repos: number }>
636662
languages: Array<{ name: string; value: number }>
637663
behavior: Array<{ day: string; commits: number; prs: number; issues: number }>
@@ -653,7 +679,7 @@ async getEasyFixes(): Promise<MappedIssue[]> {
653679

654680
// Generate real overview data from repos
655681
const overview = Array.isArray(repos) && repos.length > 0
656-
? repos.slice(0, 10).map((repo: any) => ({
682+
? repos.slice(0, 10).map((repo: GitHubRepositoryDetailed) => ({
657683
name: repo?.name?.length > 15 ? repo.name.substring(0, 15) + '...' : (repo?.name || 'Unknown'),
658684
commits: Math.max(1, Math.floor(Math.random() * 50) + 10), // GitHub API doesn't provide commit counts easily
659685
stars: repo?.stargazers_count || 0,
@@ -695,24 +721,51 @@ async getEasyFixes(): Promise<MappedIssue[]> {
695721
keysToDelete.forEach(key => this.cache.delete(key));
696722
}
697723

698-
private getDemoAnalytics(username: string) {
724+
private getDemoAnalytics(username: string): {
725+
profile: GitHubUserDetailed | null
726+
overview: Array<{ name: string; commits: number; stars: number; repos: number }>
727+
languages: Array<{ name: string; value: number }>
728+
behavior: Array<{ day: string; commits: number; prs: number; issues: number }>
729+
} {
699730
const isRealUser = ['torvalds', 'octocat', 'gaearon', 'sindresorhus', 'tj', 'defunkt'].includes(username.toLowerCase());
700731

701732
const baseData = {
702733
profile: {
703-
avatar_url: `https://github.com/${username}.png`, // GitHub always provides avatar for any username
734+
id: 0,
704735
login: username,
705-
type: 'User',
736+
node_id: '',
737+
avatar_url: `https://github.com/${username}.png`, // GitHub always provides avatar for any username
738+
gravatar_id: '',
739+
url: '',
740+
html_url: `https://github.com/${username}`,
741+
followers_url: '',
742+
following_url: '',
743+
gists_url: '',
744+
starred_url: '',
745+
subscriptions_url: '',
746+
organizations_url: '',
747+
repos_url: '',
748+
events_url: '',
749+
received_events_url: '',
750+
type: 'User' as const,
751+
site_admin: false,
752+
name: undefined,
753+
company: isRealUser ? 'Open Source' : 'Demo Company',
754+
blog: undefined,
755+
location: isRealUser ? 'Global' : 'Demo Location',
756+
email: undefined,
757+
hireable: undefined,
706758
bio: isRealUser
707759
? `Real GitHub user ${username} - Limited data due to API constraints`
708760
: `Demo profile for ${username}`,
761+
twitter_username: undefined,
709762
public_repos: isRealUser ? Math.floor(Math.random() * 50) + 20 : 25,
763+
public_gists: 0,
710764
followers: isRealUser ? Math.floor(Math.random() * 5000) + 500 : 150,
711765
following: isRealUser ? Math.floor(Math.random() * 200) + 50 : 75,
712-
location: isRealUser ? 'Global' : 'Demo Location',
713-
company: isRealUser ? 'Open Source' : 'Demo Company',
714-
html_url: `https://github.com/${username}`
715-
},
766+
created_at: new Date().toISOString(),
767+
updated_at: new Date().toISOString()
768+
} satisfies GitHubUserDetailed,
716769
overview: isRealUser ? [
717770
{ name: 'linux', commits: 145, stars: 150000, repos: 1 },
718771
{ name: 'subsurface', commits: 95, stars: 2500, repos: 1 },

0 commit comments

Comments
 (0)