Skip to content

Commit f58472d

Browse files
Update lib utilities and remove unused modules
1 parent 8080712 commit f58472d

File tree

5 files changed

+100
-106
lines changed

5 files changed

+100
-106
lines changed

lib/cookies.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export function getSidebarWidthFromCookie(cookieString?: string): number {
7171
return DEFAULT_SIDEBAR_WIDTH
7272
}
7373

74-
// Sidebar open/closed state functions
7574
export function getSidebarOpen(): boolean {
7675
if (typeof window === 'undefined') {
7776
return DEFAULT_SIDEBAR_OPEN

lib/github-oauth.ts

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,110 @@ export async function fetchGitHubRepositories(options?: {
123123
type?: 'all' | 'owner' | 'public' | 'private' | 'member'
124124
}): Promise<{ repositories: GitHubRepository[]; total_count: number; has_more: boolean } | null> {
125125
try {
126-
const params = new URLSearchParams()
127-
if (options?.page) params.append('page', options.page.toString())
128-
if (options?.per_page) params.append('per_page', options.per_page.toString())
129-
if (options?.sort) params.append('sort', options.sort)
130-
if (options?.type) params.append('type', options.type)
126+
// First get the current user to know whose repos to fetch
127+
const userResponse = await fetch('/api/github/user')
128+
if (!userResponse.ok) {
129+
throw new Error('Failed to fetch GitHub user')
130+
}
131+
const userData = await userResponse.json()
131132

132-
const response = await fetch(`/api/integrations/github/repos?${params.toString()}`)
133-
134-
if (!response.ok) {
133+
// Get user's repositories
134+
const reposResponse = await fetch(`/api/github/repos?owner=${userData.login}`)
135+
if (!reposResponse.ok) {
135136
throw new Error('Failed to fetch repositories')
136137
}
138+
const userRepos = await reposResponse.json()
139+
140+
// Get user's organizations and their repos if type allows
141+
let orgRepos: any[] = []
142+
if (!options?.type || options.type === 'all' || options.type === 'member') {
143+
const orgsResponse = await fetch('/api/github/orgs')
144+
if (orgsResponse.ok) {
145+
const orgs = await orgsResponse.json()
146+
147+
for (const org of orgs) {
148+
try {
149+
const orgReposResponse = await fetch(`/api/github/repos?owner=${org.login}`)
150+
if (orgReposResponse.ok) {
151+
const repos = await orgReposResponse.json()
152+
orgRepos.push(...repos)
153+
}
154+
} catch (error) {
155+
console.warn(`Failed to fetch repos for org ${org.login}:`, error)
156+
}
157+
}
158+
}
159+
}
160+
161+
// Filter repositories based on type
162+
let allRepos = [...userRepos, ...orgRepos]
163+
if (options?.type === 'owner') {
164+
allRepos = userRepos // Only user's own repos
165+
}
137166

138-
return await response.json()
167+
// Convert to expected format
168+
const repositories: GitHubRepository[] = allRepos.map((repo: any) => ({
169+
id: repo.id || Math.random(),
170+
name: repo.name,
171+
full_name: repo.full_name,
172+
description: repo.description,
173+
html_url: `https://github.com/${repo.full_name}`,
174+
clone_url: repo.clone_url,
175+
ssh_url: `[email protected]:${repo.full_name}.git`,
176+
private: repo.private,
177+
fork: false,
178+
archived: false,
179+
disabled: false,
180+
owner: {
181+
login: repo.full_name.split('/')[0],
182+
avatar_url: userData.avatar_url,
183+
type: 'User'
184+
},
185+
created_at: new Date().toISOString(),
186+
updated_at: repo.updated_at,
187+
pushed_at: repo.updated_at,
188+
language: repo.language,
189+
stargazers_count: 0,
190+
watchers_count: 0,
191+
forks_count: 0,
192+
open_issues_count: 0,
193+
size: 0,
194+
default_branch: 'main',
195+
topics: [],
196+
has_issues: true,
197+
has_projects: true,
198+
has_wiki: true,
199+
has_pages: false,
200+
has_downloads: true,
201+
license: null
202+
}))
203+
204+
// Apply sorting if specified
205+
if (options?.sort) {
206+
repositories.sort((a, b) => {
207+
switch (options.sort) {
208+
case 'full_name':
209+
return a.full_name.localeCompare(b.full_name)
210+
case 'updated':
211+
return new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime()
212+
default:
213+
return 0
214+
}
215+
})
216+
}
217+
218+
// Apply pagination
219+
const page = options?.page || 1
220+
const perPage = options?.per_page || 30
221+
const startIndex = (page - 1) * perPage
222+
const endIndex = startIndex + perPage
223+
const paginatedRepos = repositories.slice(startIndex, endIndex)
224+
225+
return {
226+
repositories: paginatedRepos,
227+
total_count: repositories.length,
228+
has_more: endIndex < repositories.length
229+
}
139230
} catch (error) {
140231
console.error('Error fetching GitHub repositories:', error)
141232
return null

lib/identify.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

lib/schema.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { z } from 'zod'
22

3-
// Log entry types (moved from db/schema.ts for task management)
43
export const logEntrySchema = z.object({
54
id: z.string(),
65
type: z.enum(['info', 'command', 'error', 'success']),
@@ -10,7 +9,6 @@ export const logEntrySchema = z.object({
109

1110
export type LogEntry = z.infer<typeof logEntrySchema>
1211

13-
// Fragment schema (original CodinIT.dev schema)
1412
export const fragmentSchema = z.object({
1513
commentary: z.string().describe(`Describe what you're about to do and the steps you want to take for generating the fragment in great detail.`),
1614
template: z.string().describe('Name of the template used to generate the fragment.'),

lib/user-settings.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ async function safeOperation<T>(
7272
}
7373
}
7474

75-
// =============================================
76-
// USER PROFILE OPERATIONS
77-
// =============================================
7875

7976
export async function getUserProfile(userId: string): Promise<UserProfile | null> {
8077
if (!userId) return null
@@ -280,10 +277,6 @@ export async function updateUserPreferences(userId: string, updates: Partial<Use
280277
)
281278
}
282279

283-
// =============================================
284-
// USER INTEGRATIONS OPERATIONS
285-
// =============================================
286-
287280
export async function getUserIntegrations(userId: string): Promise<UserIntegration[]> {
288281
if (!userId) return []
289282

@@ -365,10 +358,6 @@ export async function disconnectUserIntegration(userId: string, serviceName: str
365358
)
366359
}
367360

368-
// =============================================
369-
// USER SECURITY SETTINGS OPERATIONS
370-
// =============================================
371-
372361
export async function getUserSecuritySettings(userId: string): Promise<UserSecuritySettings | null> {
373362
if (!userId) return null
374363

@@ -460,9 +449,6 @@ export async function updateUserSecuritySettings(userId: string, updates: Partia
460449
)
461450
}
462451

463-
// =============================================
464-
// UTILITY FUNCTIONS
465-
// =============================================
466452

467453
export async function getUserData(userId: string) {
468454
if (!userId) return null

0 commit comments

Comments
 (0)