Helps with eventually adding other pages Also makes it clear it's the backend that decides what data to send to the frontend
34 linhas
1,1 KiB
TypeScript
34 linhas
1,1 KiB
TypeScript
import {Octokit} from "@octokit/rest";
|
|
import type { Handler } from "../..";
|
|
|
|
export interface Info {
|
|
public?: {
|
|
repo: string;
|
|
date: string;
|
|
};
|
|
private?: {
|
|
date: string;
|
|
};
|
|
}
|
|
|
|
const username = "TTTaevas";
|
|
|
|
export const github: Handler = async () => {
|
|
const octokit = new Octokit({auth: process.env["API_GITHUB"]});
|
|
const github = await octokit.rest.activity.listEventsForAuthenticatedUser({username});
|
|
|
|
const publicPush = github.data.find((e) => (e.type === "PushEvent" || e.type === "PullRequestEvent") && e.public);
|
|
const privatePush = github.data.find((e) => (e.type === "PushEvent" || e.type === "PullRequestEvent") && !e.public);
|
|
|
|
const info: Info = {
|
|
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 Response.json(info, {status: 200});
|
|
};
|