-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial github api call scaffolding, and logstream for stre…
…aming logs to the frontend
- Loading branch information
Showing
10 changed files
with
79 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export async function createLogStream( | ||
func: (logStream: ReadableStreamDefaultController<string>) => void | ||
): Promise<Response> { | ||
const logStream = new ReadableStream({ | ||
async start(logStream) { | ||
await func(logStream); | ||
} | ||
}); | ||
|
||
return new Response(logStream, { | ||
headers: { | ||
"Content-Type": "text/event-stream" | ||
} | ||
}); | ||
} | ||
|
||
export async function readLogStream(res: Response, onNewValue: (value: string) => void) { | ||
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader(); | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const { value, done } = await reader.read(); | ||
if (done) break; | ||
onNewValue(value); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createLogStream } from "$lib/ts/misc/logStream.js"; | ||
|
||
export async function POST({ request, cookies }): Promise<Response> { | ||
return await createLogStream(async (logStream) => { | ||
const token = cookies.get("github_oauth_token"); | ||
const { login, name } = await request.json(); | ||
|
||
logStream.enqueue("Creating repo: " + login + "/" + name); | ||
const res = await fetch(`https://api.github.com/repos/blue-build/template/generate`, { | ||
method: "post", | ||
headers: { Authorization: `Bearer ${token}` }, | ||
body: JSON.stringify({ | ||
owner: login, | ||
name: name | ||
}) | ||
}); | ||
const repo = await res.json(); | ||
if (!res.ok) { | ||
logStream.enqueue("Repo creation failed: " + JSON.stringify(repo)); | ||
} else { | ||
logStream.enqueue("Repo created successfully!"); | ||
} | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters