()
| 33 | |
| 34 | useEffect(() => { |
| 35 | const fetchTechStack = async () => { |
| 36 | setIsLoading(true); |
| 37 | setError(null); |
| 38 | |
| 39 | try { |
| 40 | // Fetch repository structure which includes package.json if available |
| 41 | const response = await fetch(`/api/get-repo-structure?repo=${repoFullName}`); |
| 42 | const data = await response.json(); |
| 43 | |
| 44 | if (response.ok) { |
| 45 | setLanguages(data.languages || {}); |
| 46 | |
| 47 | // Try to find package.json in the file tree |
| 48 | const fileTree = data.tree || []; |
| 49 | const packageJsonFile = fileTree.find((file: any) => |
| 50 | file.type === 'file' && file.path === 'package.json' |
| 51 | ); |
| 52 | |
| 53 | if (packageJsonFile) { |
| 54 | // Fetch the package.json content |
| 55 | const contentResponse = await fetch(`/api/get-file-content?repo=${repoFullName}&path=package.json`); |
| 56 | const contentData = await contentResponse.json(); |
| 57 | |
| 58 | if (contentResponse.ok && contentData.content) { |
| 59 | try { |
| 60 | const parsedPackageJson = JSON.parse(contentData.content); |
| 61 | setPackageJson(parsedPackageJson); |
| 62 | |
| 63 | // Extract technologies from package.json |
| 64 | const extractedTech = extractTechnologiesFromPackageJson(parsedPackageJson); |
| 65 | setTechnologies(extractedTech); |
| 66 | } catch (parseError) { |
| 67 | console.error('Error parsing package.json:', parseError); |
| 68 | } |
| 69 | } |
| 70 | } else { |
| 71 | // If no package.json, infer technologies from languages |
| 72 | const inferredTech = inferTechnologiesFromLanguages(data.languages || {}); |
| 73 | setTechnologies(inferredTech); |
| 74 | } |
| 75 | } else { |
| 76 | setError(data.error || 'Failed to fetch repository structure'); |
| 77 | } |
| 78 | } catch (err) { |
| 79 | console.error('Error fetching tech stack:', err); |
| 80 | setError('An error occurred while analyzing the technology stack'); |
| 81 | } finally { |
| 82 | setIsLoading(false); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | if (repoFullName) { |
| 87 | fetchTechStack(); |
no test coverage detected