refactor: simplify naming schema

This commit is contained in:
Mauricio Siu
2024-09-01 19:34:25 -06:00
parent 879311c332
commit 32ebd9b3b9
20 changed files with 393 additions and 211 deletions

View File

@@ -1,6 +1,6 @@
import { findAdmin } from "@/server/api/services/admin";
import { db } from "@/server/db";
import { applications, compose, githubProvider } from "@/server/db/schema";
import { applications, compose } from "@/server/db/schema";
import type { DeploymentJob } from "@/server/queues/deployments-queue";
import { myQueue } from "@/server/queues/queueSetup";
import { Webhooks } from "@octokit/webhooks";
@@ -22,13 +22,13 @@ export default async function handler(
const signature = req.headers["x-hub-signature-256"];
const github = req.body;
if(!github?.installation.id) {
if (!github?.installation.id) {
res.status(400).json({ message: "Github Installation not found" });
return;
}
const githubResult = await db.query.githubProvider.findFirst({
where: eq(githubProvider.githubInstallationId, github.installation.id),
const githubResult = await db.query.github.findFirst({
where: eq(github.githubInstallationId, github.installation.id),
});
if (!githubResult) {

View File

@@ -1,6 +1,6 @@
import { createGithubProvider } from "@/server/api/services/git-provider";
import { createGithub } from "@/server/api/services/git-provider";
import { db } from "@/server/db";
import { githubProvider } from "@/server/db/schema";
import { github } from "@/server/db/schema";
import { eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
import { Octokit } from "octokit";
@@ -34,7 +34,7 @@ export default async function handler(
},
);
await createGithubProvider({
await createGithub({
name: data.name,
githubAppName: data.html_url,
githubAppId: data.id,
@@ -46,11 +46,11 @@ export default async function handler(
});
} else if (action === "gh_setup") {
await db
.update(githubProvider)
.update(github)
.set({
githubInstallationId: installation_id,
})
.where(eq(githubProvider.githubId, value as string))
.where(eq(github.githubId, value as string))
.returning();
}

View File

@@ -1,6 +1,6 @@
import {
getGitlabProvider,
updateGitlabProvider,
findGitlabById,
updateGitlab,
} from "@/server/api/services/git-provider";
import type { NextApiRequest, NextApiResponse } from "next";
@@ -14,7 +14,7 @@ export default async function handler(
return res.status(400).json({ error: "Missing or invalid code" });
}
const gitlab = await getGitlabProvider(gitlabId as string);
const gitlab = await findGitlabById(gitlabId as string);
const response = await fetch("https://gitlab.com/oauth/token", {
method: "POST",
@@ -37,7 +37,7 @@ export default async function handler(
}
const expiresAt = Math.floor(Date.now() / 1000) + result.expires_in;
await updateGitlabProvider(gitlab.gitlabId, {
await updateGitlab(gitlab.gitlabId, {
accessToken: result.access_token,
refreshToken: result.refresh_token,
expiresAt,