Skip to content

Commit 4fff0d5

Browse files
fixed github integration
1 parent 4d85875 commit 4fff0d5

File tree

5 files changed

+596
-557
lines changed

5 files changed

+596
-557
lines changed

app/api/github/import/route.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,59 @@ export async function POST(request: NextRequest) {
7777
// Convert to File objects for analysis
7878
const fileObjects = files.map(file => {
7979
const blob = new Blob([file.content], { type: 'text/plain' })
80-
return new File([blob], file.name, { type: 'text/plain' })
80+
return new File([blob], file.name)
8181
})
8282

8383
// Analyze the project
8484
const analyzer = new ProjectAnalyzer()
85-
const analysis = await analyzer.analyzeProject(fileObjects)
85+
const result = await analyzer.analyzeProject(fileObjects)
86+
87+
// Enhance the analysis structure with file contents for easier access
88+
const enhancedStructure = {
89+
...result.structure,
90+
files: result.structure.files.map(file => {
91+
const originalFile = files.find(f => f.name === file.name)
92+
return {
93+
...file,
94+
content: originalFile?.content || ''
95+
}
96+
})
97+
}
8698

8799
console.log(`[GitHub Import API ${requestId}] Import completed: ${files.length} files analyzed`)
88100

89101
return NextResponse.json({
90102
success: true,
91103
repository: { owner, repo },
92-
files: files.map(f => ({
93-
name: f.name,
94-
path: f.path,
95-
size: f.content.length,
96-
type: 'file'
97-
})),
98-
analysis,
104+
analysis: {
105+
...result,
106+
structure: enhancedStructure
107+
},
99108
requestId
100109
})
101110

102111
} catch (error) {
103112
console.error(`[GitHub Import API ${requestId}] Error:`, error)
113+
114+
let errorMessage = "Failed to import repository"
115+
let statusCode = 500
116+
117+
if (error instanceof Error) {
118+
if (error.message.includes("404")) {
119+
errorMessage = "Repository not found or access denied"
120+
statusCode = 404
121+
} else if (error.message.includes("403")) {
122+
errorMessage = "Access denied to repository"
123+
statusCode = 403
124+
} else if (error.message.includes("rate limit")) {
125+
errorMessage = "GitHub API rate limit exceeded"
126+
statusCode = 429
127+
}
128+
}
129+
104130
return NextResponse.json(
105-
{ error: "Failed to import repository" },
106-
{ status: 500 }
131+
{ error: errorMessage },
132+
{ status: statusCode }
107133
)
108134
}
109135
}

app/page.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// File: app/page.tsx
21
"use client"
32

43
import type React from "react"
@@ -34,7 +33,32 @@ const TEMPLATE_IDS = {
3433
CODINIT_ENGINEER: "codinit-engineer",
3534
} as const;
3635

37-
// Error types and handling
36+
interface ProjectAnalysis {
37+
structure: {
38+
files: Array<{
39+
name: string
40+
path: string
41+
language: string
42+
size: number
43+
type: string
44+
content?: string // Added content for easier File creation
45+
}>
46+
dependencies: Set<string>
47+
frameworks: Set<string>
48+
patterns: Set<string>
49+
components: Set<string>
50+
types: Set<string>
51+
utilities: Set<string>
52+
architecture: {
53+
type: string
54+
description: string
55+
}
56+
configFiles?: string[] // Added configFiles based on EnhancedChatInput logic
57+
}
58+
analysis: string
59+
recommendations: string[]
60+
}
61+
3862
type ParsedApiError = { code: string; message: string; rawData: any };
3963

4064
const parseApiError = (error: Error | any): ParsedApiError => {
@@ -175,30 +199,6 @@ async function handleSandboxCreation(
175199
return responseData as ExecutionResult;
176200
}
177201

178-
interface ProjectAnalysis {
179-
structure: {
180-
files: Array<{
181-
name: string
182-
path: string
183-
language: string
184-
size: number
185-
type: string
186-
}>
187-
dependencies: Set<string>
188-
frameworks: Set<string>
189-
patterns: Set<string>
190-
components: Set<string>
191-
types: Set<string>
192-
utilities: Set<string>
193-
architecture: {
194-
type: string
195-
description: string
196-
}
197-
}
198-
analysis: string
199-
recommendations: string[]
200-
}
201-
202202
export default function Home() {
203203
const [chatInput, setChatInput] = useLocalStorage("chat", "")
204204
const [files, setFiles] = useState<File[]>([])
@@ -518,6 +518,7 @@ export default function Home() {
518518
template: selectedTemplate,
519519
hasProjectFiles: !!(projectFiles && projectFiles.length > 0),
520520
hasProjectAnalysis: !!projectAnalysis,
521+
isGitHubImport: !!(projectAnalysis && projectAnalysis.structure),
521522
})
522523

523524
try {
@@ -541,6 +542,10 @@ export default function Home() {
541542
model: languageModel.model,
542543
requestId,
543544
hasProjectContext: !!(projectFiles && projectFiles.length > 0),
545+
importSource: projectAnalysis ? "github" : projectFiles ? "upload" : "none",
546+
gitHubRepository: projectAnalysis?.structure?.configFiles?.some(f =>
547+
f.includes('package.json') || f.includes('.git')
548+
) ? "detected" : "none",
544549
})
545550
} catch (error: any) {
546551
console.error("[handleSubmitAuth] Submit error:", error)
@@ -584,6 +589,7 @@ export default function Home() {
584589
messagesCount: submitData.messages.length,
585590
model: submitData.model.id,
586591
hasProjectContext: !!(projectContext.files.length > 0),
592+
hasGitHubAnalysis: !!projectContext.analysis,
587593
})
588594

589595
submit(submitData)

0 commit comments

Comments
 (0)