Skip to content

Commit 2938eb1

Browse files
authored
Merge pull request #59 from ArjinAlbay/main
refactor: Unused functions and comments were deleted
2 parents aaad86d + 5574de7 commit 2938eb1

File tree

8 files changed

+97
-1278
lines changed

8 files changed

+97
-1278
lines changed

src/app/dashboard/page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import { useSearchStore, useActionItemsStore } from '@/stores'
1919
import { ThemeToggle } from '@/components/theme/ThemeToggle'
2020
import RefreshButton from "@/components/Refresh/RefreshButton";
2121

22+
const VALID_PRIORITIES = ['urgent', 'high', 'medium', 'low'] as const;
2223
function mapActionItemToGitHubIssue(item: any): GitHubIssue {
24+
if (!item) {
25+
throw new Error('Invalid item provided to mapActionItemToGitHubIssue');
26+
}
2327
return {
2428
id: item.id,
2529
title: item.title,
@@ -29,14 +33,14 @@ function mapActionItemToGitHubIssue(item: any): GitHubIssue {
2933
labels: (item.labels || []).map((name: string) => ({ name, color: '999999' })),
3034
created_at: item.createdAt || '',
3135
updated_at: item.updatedAt || '',
32-
difficulty: item.difficulty || 'medium', // Don't assume all items are 'easy'
36+
difficulty: item.difficulty || 'medium',
3337
language: item.language || 'unknown',
3438
stars: 0,
3539
author: { login: item.author || '', avatar_url: '' },
3640
comments: 0,
3741
state: 'open',
3842
assignee: null,
39-
priority: ['urgent', 'high', 'medium', 'low'].includes(item.priority) ? item.priority : 'low',
43+
priority: VALID_PRIORITIES.includes(item.priority) ? item.priority : 'low',
4044
}
4145
}
4246

@@ -53,7 +57,7 @@ interface ActionItem {
5357
}
5458

5559
export default function DashboardPage() {
56-
const { isLoading, orgData, isAuthenticated } = useRequireAuth()
60+
const { isLoading, orgData } = useRequireAuth()
5761
const { setSearchModalOpen } = useSearchStore()
5862
const {
5963
assignedItems,

src/components/layout/Sidebar.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use client'
22

3-
import { useEffect } from 'react'
43
import Link from 'next/link'
5-
import { usePathname, useSearchParams } from 'next/navigation'
4+
import { usePathname, useSearchParams } from 'next/navigation'
65
import { Button } from '@/components/ui/button'
7-
8-
96
import { useSidebarState, useAuthStore, useStoreHydration, useActionItemsStore } from '@/stores'
107
import { ChevronRight, Clock, LogOut, MessageSquare, Sparkles, Star, Target, Zap, } from 'lucide-react'
118
import { Badge } from '../ui/badge'
@@ -20,10 +17,10 @@ export function Sidebar() {
2017

2118
// Auth state
2219
const hasHydrated = useStoreHydration()
23-
const { isConnected, orgData, logout } = useAuthStore()
20+
const { isConnected, logout } = useAuthStore()
2421

2522
// Action items state
26-
const { getCountByType, getTotalCount, loading, refreshData } = useActionItemsStore()
23+
const { getCountByType, getTotalCount, loading } = useActionItemsStore()
2724

2825
// Get current tab from URL params
2926
const currentTab = searchParams.get('tab') || 'assigned'
@@ -39,15 +36,11 @@ export function Sidebar() {
3936
return getBadgeCount(type)
4037
}
4138

42-
const router = useRouter()
4339

44-
// Hangi bölümün açık olduğunu kontrol etmek için
40+
4541
const isQuickWinsTab = currentTab === 'quick-wins' || currentTab === 'good-first-issues' || currentTab === 'easy-fixes'
4642
const isActionRequiredTab = !isQuickWinsTab && isDashboardPage
4743

48-
const navigationItems = [
49-
{ href: '/dashboard', label: 'Dashboard', icon: Flame }
50-
]
5144

5245
const handleLogout = () => {
5346
logout()

src/components/quick-wins/QuickWinsTable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
ChevronRight,
3535
ChevronsLeft,
3636
ChevronsRight,
37-
Search,
3837
Filter,
3938
RefreshCw,
4039
AlertCircle

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

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,48 @@ class GitHubAPIClient {
7373
}
7474

7575
const trimmedToken = token.trim()
76+
77+
78+
if (process.env.NODE_ENV === 'development') {
79+
console.log('🔍 Token validation debug:', {
80+
tokenLength: trimmedToken.length,
81+
tokenPrefix: trimmedToken.substring(0, 10) + '...',
82+
tokenPattern: trimmedToken.substring(0, 4)
83+
})
84+
}
7685

7786

7887
const isClassicToken = /^ghp_[A-Za-z0-9]{36}$/.test(trimmedToken)
7988
const isFineGrainedToken = /^github_pat_[A-Za-z0-9_]{82}$/.test(trimmedToken)
8089
const isGitHubAppToken = /^ghs_[A-Za-z0-9]{36}$/.test(trimmedToken)
81-
8290
const isLegacyToken = /^[a-f0-9]{40}$/.test(trimmedToken)
91+
92+
93+
const isOAuthToken = /^gho_[A-Za-z0-9_-]{16,}$/.test(trimmedToken) ||
94+
(!isClassicToken && !isFineGrainedToken && !isGitHubAppToken && !isLegacyToken &&
95+
/^[A-Za-z0-9_-]{20,255}$/.test(trimmedToken))
96+
97+
if (process.env.NODE_ENV === 'development') {
98+
console.log('🔍 Token type checks:', {
99+
isClassicToken,
100+
isFineGrainedToken,
101+
isGitHubAppToken,
102+
isLegacyToken,
103+
isOAuthToken
104+
})
105+
}
83106

84-
if (!isClassicToken && !isFineGrainedToken && !isGitHubAppToken && !isLegacyToken) {
107+
if (!isClassicToken && !isFineGrainedToken && !isGitHubAppToken && !isLegacyToken && !isOAuthToken) {
85108
throw new Error(
86109
'Invalid GitHub token format. Expected:\n' +
87110
'- Classic token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (40 chars)\n' +
88111
'- Fine-grained token: github_pat_xxxxxxxxxx... (94 chars)\n' +
89112
'- GitHub App token: ghs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (40 chars)\n' +
113+
'- OAuth token: 20-255 character alphanumeric string\n' +
90114
'- Legacy token: 40 character hexadecimal string'
91115
)
92116
}
93117

94-
// Additional length validation
95118
if (trimmedToken.length < 40) {
96119
throw new Error('GitHub token is too short. Minimum length is 40 characters.')
97120
}
@@ -103,16 +126,12 @@ class GitHubAPIClient {
103126
this.githubToken = trimmedToken
104127
}
105128

106-
/**
107-
* Check if a valid GitHub token is currently set
108-
*/
129+
109130
hasValidToken(): boolean {
110-
return this.githubToken.length >= 40
131+
return this.githubToken.length >= 20
111132
}
112133

113-
/**
114-
* Clear the current GitHub token
115-
*/
134+
116135
clearToken(): void {
117136
this.githubToken = ''
118137
}
@@ -131,7 +150,6 @@ class GitHubAPIClient {
131150
'User-Agent': 'GitHubMon/1.0'
132151
}
133152

134-
// Add GitHub token if available for authenticated requests
135153
if (useGithub && this.githubToken) {
136154
headers['Authorization'] = `token ${this.githubToken}`
137155
}
@@ -143,32 +161,27 @@ class GitHubAPIClient {
143161
if (response.status === 403) {
144162
console.warn('GitHub API rate limit exceeded')
145163
}
146-
// Return fallback data on error
147164
return this.getFallbackData(endpoint) as T
148165
}
149166

150167
const data = await response.json()
151168

152-
// GitHub API response
153169
this.cache.set(cacheKey, { data, timestamp: Date.now() })
154170
return data
155171

156172
} catch (error) {
157173
console.error(`API request failed for ${endpoint}:`, error)
158174

159-
// Return cached data if available
160175
if (cached) {
161176
console.log('Returning stale cached data due to error')
162177
return cached.data as T
163178
}
164179

165-
// Fallback to mock data
166180
return this.getFallbackData(endpoint) as T
167181
}
168182
}
169183

170184
private getFallbackData(endpoint: string): unknown {
171-
// Return mock trending repositories if the real API fails
172185
if (endpoint.includes('search/repositories')) {
173186
return {
174187
items: [
@@ -406,6 +419,60 @@ async getAssignedItems(username?: string): Promise<unknown[]> {
406419
}
407420
}
408421

422+
async getGoodFirstIssues(): Promise<unknown[]> {
423+
try {
424+
const endpoint = `/search/issues?q=label:"good first issue"+state:open+type:issue&sort=updated&order=desc&per_page=50`
425+
const response = await this.fetchWithCache<GitHubSearchResponse<GitHubIssueResponse>>(endpoint, true)
426+
427+
return response.items?.map((item: GitHubIssueResponse) => ({
428+
id: item.id,
429+
title: item.title,
430+
repo: item.repository_url
431+
? item.repository_url.split('/').slice(-2).join('/')
432+
: 'unknown/unknown',
433+
type: 'issue',
434+
priority: this.calculatePriority(item),
435+
url: item.html_url,
436+
createdAt: item.created_at,
437+
updatedAt: item.updated_at,
438+
author: item.user?.login,
439+
labels: item.labels?.map((l: { name: string }) => l.name) || [],
440+
daysOld: Math.floor((Date.now() - new Date(item.created_at).getTime()) / (1000 * 60 * 60 * 24))
441+
})) || []
442+
} catch (error) {
443+
console.error('Failed to fetch good first issues:', error)
444+
return []
445+
}
446+
}
447+
448+
async getEasyFixes(): Promise<unknown[]> {
449+
try {
450+
const labels = ['easy', 'easy fix', 'beginner', 'starter', 'help wanted']
451+
const labelQuery = labels.map(label => `label:"${label}"`).join(' OR ')
452+
const endpoint = `/search/issues?q=(${labelQuery})+state:open+type:issue&sort=updated&order=desc&per_page=50`
453+
const response = await this.fetchWithCache<GitHubSearchResponse<GitHubIssueResponse>>(endpoint, true)
454+
455+
return response.items?.map((item: GitHubIssueResponse) => ({
456+
id: item.id,
457+
title: item.title,
458+
repo: item.repository_url
459+
? item.repository_url.split('/').slice(-2).join('/')
460+
: 'unknown/unknown',
461+
type: 'issue',
462+
priority: this.calculatePriority(item),
463+
url: item.html_url,
464+
createdAt: item.created_at,
465+
updatedAt: item.updated_at,
466+
author: item.user?.login,
467+
labels: item.labels?.map((l: { name: string }) => l.name) || [],
468+
daysOld: Math.floor((Date.now() - new Date(item.created_at).getTime()) / (1000 * 60 * 60 * 24))
469+
})) || []
470+
} catch (error) {
471+
console.error('Failed to fetch easy fixes:', error)
472+
return []
473+
}
474+
}
475+
409476
private calculatePriority(item: GitHubIssueResponse): 'low' | 'medium' | 'high' | 'urgent' {
410477
const labels = item.labels?.map((l: { name: string }) => l.name.toLowerCase()) || []
411478
const commentCount = item.comments || 0

src/lib/api/github.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import { GitHubIssue } from '@/types/quickWins';
22

33
const GITHUB_API_URL = 'https://api.github.com';
44

5-
// İsteğe bağlı: Token'ı .env veya config dosyasından alınabilir
6-
// Eğer .env yoksa buraya kendi token'ınızı yazabilirsiniz
7-
// Token artık parametre ile alınacak, default olarak boş
8-
9-
10-
11-
// Basit bir in-memory cache
12-
const CACHE_DURATION = 1000 * 60 * 60 * 12; // 12 saat (günde 2 defa güncellenir)
5+
const CACHE_DURATION = 1000 * 60 * 60 * 12;
136
const issuesCache: Record<string, { timestamp: number; data: GitHubIssue[] }> = {};
147

158
async function fetchIssuesFromGitHub({

0 commit comments

Comments
 (0)