taevas.xyz/netlify/functions/github.ts
Taevas b4af91405d Start handling bad requests on client-side rather than Netlify-side (#4)
Too much can go wrong on the side of Netlify, so it should throw on purpose if anything goes bad so the client can `catch` that
2024-05-01 02:11:36 +02:00

28 lines
1,013 B
TypeScript

import {type Handler} from "@netlify/functions";
import {Octokit} from "@octokit/rest";
import {type GithubInfo} from "../../src/components/Info/Git.js";
const handler: Handler = async () => {
const octokit = new Octokit({auth: process.env.API_GITHUB});
const github = await octokit.rest.activity.listEventsForAuthenticatedUser({username: "TTTaevas"});
const publicPush = github.data.find((e) => e.type === "PushEvent" && e.public);
const privatePush = github.data.find((e) => e.type === "PushEvent" && !e.public);
const info: GithubInfo = {
public: publicPush ? {
repo: publicPush.repo.name,
date: publicPush.created_at ? publicPush.created_at.substring(0, publicPush.created_at.indexOf("T")) : "",
} : undefined,
private: privatePush ? {
date: privatePush.created_at ? privatePush.created_at.substring(0, privatePush.created_at.indexOf("T")) : "",
} : undefined,
};
return {
statusCode: 200,
body: JSON.stringify(info),
};
};
export {handler};