This commit is contained in:
Mauricio Siu 2024-09-01 14:52:34 -06:00
parent f05c811bdc
commit 2ec364ed68
2 changed files with 0 additions and 76 deletions

View File

@ -1,57 +0,0 @@
import { db } from "@/server/db";
import { admins } from "@/server/db/schema";
import { eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
import { Octokit } from "octokit";
type Query = {
code: string;
state: string;
installation_id: string;
setup_action: string;
};
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const { code, state, installation_id, setup_action }: Query =
req.query as Query;
if (!code) {
return res.status(400).json({ error: "Missing code parameter" });
}
const [action, authId] = state?.split(":");
if (action === "gh_init") {
const octokit = new Octokit({});
const { data } = await octokit.request(
"POST /app-manifests/{code}/conversions",
{
code: code as string,
},
);
const result = await db
.update(admins)
.set({
githubAppId: data.id,
githubAppName: data.html_url,
githubClientId: data.client_id,
githubClientSecret: data.client_secret,
githubWebhookSecret: data.webhook_secret,
githubPrivateKey: data.pem,
})
.where(eq(admins.authId, authId as string))
.returning();
} else if (action === "gh_setup") {
await db
.update(admins)
.set({
githubInstallationId: installation_id,
})
.where(eq(admins.authId, authId as string))
.returning();
}
res.redirect(307, "/dashboard/settings/server");
}

View File

@ -1,19 +0,0 @@
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method === "POST") {
const xGitHubEvent = req.headers["x-github-event"];
if (xGitHubEvent === "ping") {
res.redirect(307, "/dashboard/settings");
} else {
res.redirect(307, "/dashboard/settings");
}
} else {
res.setHeader("Allow", ["POST"]);
return res.status(405).end(`Method ${req.method} not allowed`);
}
}