diff --git a/apps/dokploy/components/dashboard/settings/git/show-git-providers.tsx b/apps/dokploy/components/dashboard/settings/git/show-git-providers.tsx index a67a3682..95244d5a 100644 --- a/apps/dokploy/components/dashboard/settings/git/show-git-providers.tsx +++ b/apps/dokploy/components/dashboard/settings/git/show-git-providers.tsx @@ -44,100 +44,102 @@ export const ShowGitProviders = () => { - {data?.map((gitProvider, index) => { - const isGithub = gitProvider.providerType === "github"; - const isGitlab = gitProvider.providerType === "gitlab"; - const haveGithubRequirements = - gitProvider.providerType === "github" && - gitProvider.github?.githubPrivateKey && - gitProvider.github?.githubAppId && - gitProvider.github?.githubInstallationId; +
+ {data?.map((gitProvider, index) => { + const isGithub = gitProvider.providerType === "github"; + const isGitlab = gitProvider.providerType === "gitlab"; + const haveGithubRequirements = + gitProvider.providerType === "github" && + gitProvider.github?.githubPrivateKey && + gitProvider.github?.githubAppId && + gitProvider.github?.githubInstallationId; - const haveGitlabRequirements = - gitProvider.gitlab?.accessToken && gitProvider.gitlab?.refreshToken; - return ( -
- -
- {gitProvider.providerType === "github" && ( - - )} - {gitProvider.providerType === "gitlab" && ( - - )} - {gitProvider.providerType === "bitbucket" && ( - - )} -
-

- {gitProvider.providerType === "github" - ? "GitHub" - : gitProvider.providerType === "gitlab" - ? "GitLab" - : "Bitbucket"} -

-

- {gitProvider.name} -

+ const haveGitlabRequirements = + gitProvider.gitlab?.accessToken && gitProvider.gitlab?.refreshToken; + return ( +
+ +
+ {gitProvider.providerType === "github" && ( + + )} + {gitProvider.providerType === "gitlab" && ( + + )} + {gitProvider.providerType === "bitbucket" && ( + + )} +
+

+ {gitProvider.providerType === "github" + ? "GitHub" + : gitProvider.providerType === "gitlab" + ? "GitLab" + : "Bitbucket"} +

+

+ {gitProvider.name} +

+
-
-
- {!haveGithubRequirements && isGithub && ( -
- - Install Github App - -
- )} +
+ {!haveGithubRequirements && isGithub && ( +
+ + Install Github App + +
+ )} - {haveGithubRequirements && isGithub && ( -
- - Manage Github App - -
- )} + {haveGithubRequirements && isGithub && ( +
+ + Manage Github App + +
+ )} - {!haveGitlabRequirements && isGitlab && ( -
- - Install Gitlab App - -
- )} + {!haveGitlabRequirements && isGitlab && ( +
+ + Install Gitlab App + +
+ )} - -
- -
- ); - })} + +
+ +
+ ); + })} +
); }; diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index 832e34cc..1c22b9c0 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -1,6 +1,6 @@ import { findAdmin } from "@/server/api/services/admin"; import { db } from "@/server/db"; -import { applications, compose } from "@/server/db/schema"; +import { applications, compose, githubProvider } from "@/server/db/schema"; import type { DeploymentJob } from "@/server/queues/deployments-queue"; import { myQueue } from "@/server/queues/queueSetup"; import { Webhooks } from "@octokit/webhooks"; @@ -19,18 +19,26 @@ export default async function handler( return; } - if (!admin.githubWebhookSecret) { - res.status(200).json({ message: "Github Webhook Secret not set" }); + const signature = req.headers["x-hub-signature-256"]; + const github = req.body; + + const githubResult = await db.query.githubProvider.findFirst({ + where: eq(githubProvider.githubInstallationId, github.installation.id), + }); + + if (!githubResult) { + res.status(400).json({ message: "Github Installation not found" }); return; } + if (!githubResult.githubWebhookSecret) { + res.status(400).json({ message: "Github Webhook Secret not set" }); + return; + } const webhooks = new Webhooks({ - secret: admin.githubWebhookSecret, + secret: githubResult.githubWebhookSecret, }); - const signature = req.headers["x-hub-signature-256"]; - const github = req.body; - const verified = await webhooks.verify( JSON.stringify(github), signature as string,