Get the octocat as ASCII art
by hugo697 ยท 10/25/2023
1
type Github = {
2
token: string;
3
};
4
/**
5
* Get Octocat
6
* Get the octocat as ASCII art
7
*/
8
export async function main(auth: Github, s: string | undefined) {
9
const url = new URL(`https://api.github.com/octocat`);
10
for (const [k, v] of [["s", s]]) {
11
if (v !== undefined && v !== "") {
12
url.searchParams.append(k, v);
13
}
14
15
const response = await fetch(url, {
16
method: "GET",
17
headers: {
18
Authorization: "Bearer " + auth.token,
19
},
20
body: undefined,
21
});
22
if (!response.ok) {
23
const text = await response.text();
24
throw new Error(`${response.status} ${text}`);
25
26
return await response.text();
27
28