import { Button, buttonVariants } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { api } from "@/utils/api"; import { BadgeCheck } from "lucide-react"; import Link from "next/link"; import React, { useEffect, useState } from "react"; import { RemoveGithubApp } from "./remove-github-app"; export const generateName = () => { const n1 = ["Blue", "Green", "Red", "Orange", "Violet", "Indigo", "Yellow"]; const n2 = [ "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Zero", ]; return `Dokploy-${n1[Math.round(Math.random() * (n1.length - 1))]}-${ n2[Math.round(Math.random() * (n2.length - 1))] }`; }; function slugify(text: string) { return text .toLowerCase() .replace(/[\s\^&*()+=!]+/g, "-") .replace(/[\$.,*+~()'"!:@^&]+/g, "") .replace(/-+/g, "-") .replace(/^-+|-+$/g, ""); } export const GithubSetup = () => { const [isOrganization, setIsOrganization] = useState(false); const { data: haveGithubConfigured } = api.admin.haveGithubConfigured.useQuery(); const [manifest, setManifest] = useState(""); const [organizationName, setOrganization] = useState(""); const { data } = api.admin.one.useQuery(); useEffect(() => { const manifest = JSON.stringify( { redirect_url: `${origin}/api/redirect?authId=${data?.authId}`, name: generateName(), url: origin, hook_attributes: { // JUST FOR TESTING url: "https://webhook.site/b6a167c0-ceb5-4f0c-a257-97c0fd163977", // url: `${origin}/api/webhook`, // Aquí especificas la URL del endpoint de tu webhook }, callback_urls: [`${origin}/api/redirect`], // Los URLs de callback para procesos de autenticación public: false, request_oauth_on_install: true, default_permissions: { contents: "read", metadata: "read", emails: "read", pull_requests: "write", }, default_events: ["pull_request", "push"], }, null, 4, ); setManifest(manifest); }, [data?.authId]); return ( Configure Github Setup your github account to access to your repositories. {haveGithubConfigured ? (
Github account configured succesfully.
) : ( <> {data?.githubAppName ? (
Youve successfully created a GitHub app named {data.githubAppName}! The next step is to install this app in your GitHub account.
Install Github App
) : (
To integrate your GitHub account with our services, youll need to create and install a GitHub app. This process is straightforward and only takes a few minutes. Click the button below to get started.
Organization? setIsOrganization(checked)} />
{isOrganization && ( setOrganization(e.target.value)} /> )}

)} )}
); };