| 22 | } |
| 23 | |
| 24 | function fetchGitlabArchive(project: string, branch: string, token?: string): Promise<{ |
| 25 | statusCode: number; |
| 26 | headers: Record<string, string | string[] | undefined>; |
| 27 | body: Buffer; |
| 28 | }> { |
| 29 | const gitlabPath = `/api/v4/projects/${encodeURIComponent(project)}/repository/archive.zip?sha=${encodeURIComponent(branch)}`; |
| 30 | const headers: Record<string, string> = { |
| 31 | "User-Agent": "CodeGraphContext-Website/1.0", |
| 32 | Accept: "application/zip, application/octet-stream, */*", |
| 33 | }; |
| 34 | if (token) { |
| 35 | headers["PRIVATE-TOKEN"] = token; |
| 36 | } |
| 37 | |
| 38 | return new Promise((resolve, reject) => { |
| 39 | const req = https.request( |
| 40 | { |
| 41 | hostname: "gitlab.com", |
| 42 | path: gitlabPath, |
| 43 | method: "GET", |
| 44 | headers, |
| 45 | }, |
| 46 | (res) => { |
| 47 | const chunks: Buffer[] = []; |
| 48 | res.on("data", (chunk) => chunks.push(chunk)); |
| 49 | res.on("end", () => { |
| 50 | resolve({ |
| 51 | statusCode: res.statusCode || 500, |
| 52 | headers: res.headers, |
| 53 | body: Buffer.concat(chunks), |
| 54 | }); |
| 55 | }); |
| 56 | } |
| 57 | ); |
| 58 | req.on("error", reject); |
| 59 | req.end(); |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | export default async function handler(req: any, res: any) { |
| 64 | if (req.method !== "GET" && req.method !== "HEAD") { |