This commit is contained in:
Andras Bacsai
2021-05-16 21:54:44 +02:00
committed by GitHub
parent 23a4ebb74a
commit adcd68c1ab
68 changed files with 2466 additions and 1194 deletions

23
src/lib/api/github.ts Normal file
View File

@@ -0,0 +1,23 @@
import type { Request } from '@sveltejs/kit';
export async function githubAPI(
request: Request,
resource: string,
token?: string,
data?: Record<string, unknown>
) {
const base = 'https://api.github.com';
const res = await fetch(`${base}${resource}`, {
method: request.method,
headers: {
'content-type': 'application/json',
accept: 'application/json',
authorization: token ? `token ${token}` : ''
},
body: data && JSON.stringify(data)
});
return {
status: res.status,
body: await res.json()
};
}