Public
Script
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { createVal } from "https://esm.town/v/stevekrouse/createVal?v=2";
export const importGists = (async ({ githubToken, valTownKey }: {
githubToken: string;
valTownKey: string;
}) => {
const supportedLanguages = ["JavaScript", "TypeScript"];
let imported = [];
const headers = { "X-GitHub-Api-Version": "2022-11-28" };
const { Octokit } = await import("npm:@octokit/core");
const octokit = new Octokit({ auth: githubToken });
let { data } = await octokit.request("GET /gists", { headers });
for (let i in data) {
let files = Object.values(data[i].files);
let { filename, language } = files[0];
if (!supportedLanguages.includes(language)) {
continue;
}
let gist = await octokit.request("GET /gists/{gist_id}", {
gist_id: data[i].id,
});
let { content } = Object.values(gist.data.files)[0];
createVal({ code: content, valTownKey: valTownKey });
imported.push(filename);
}
return `Imported ${imported.length} vals (${
imported.join(", ")
}) from GitHub Gists.`;
});
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023