From 8d371f36745202167be542b4c59c4de12b292969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Roumezin?= Date: Fri, 15 Nov 2024 17:37:08 +0000 Subject: [PATCH] WIP Github lib --- app/lib/github.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/lib/github.ts diff --git a/app/lib/github.ts b/app/lib/github.ts new file mode 100644 index 0000000..2e0286c --- /dev/null +++ b/app/lib/github.ts @@ -0,0 +1,43 @@ +import https from 'https' +import { Readable } from 'stream' + +export default class GithubLib { + public static async getBranchHead(remoteurl, branch) { + const remote = new URL(remoteurl) + remote.pathname = '/info/refs?service=git-upload-pack' + } + + private static getReaderFromHTTP(url: URL): Promise { + return new Promise((resolve, reject) => { + https.get(url, (res) => { + if (res.statusCode !== 200) { + reject(new Error(`Request Failed. Status Code: ${res.statusCode}`)) + res.resume() // Consume response data to free up memory + return + } + + const reader = new Readable({ + read() { + res.on('data', (chunk) => { + this.push(chunk) // Push chunks of data to the reader + }) + + res.on('end', () => { + this.push(null) // Signal the end of the stream + }) + } + }) + + resolve(reader) + }) + }) + } + + private static parsePktLines(reader: Readable) { + while (1) { + const lenraw = reader.read(4) // Read the length of the pkt-line + // Convert the length to a number + const len = parseInt(lenraw.toString('utf8'), 16) + } + } +} \ No newline at end of file