import { formatDate } from "date-fns"; import { ExternalLinkIcon, GitBranch, ImportIcon, Loader2, Trash2, } from "lucide-react"; import Link from "next/link"; import { toast } from "sonner"; import { BitbucketIcon, GiteaIcon, GithubIcon, GitlabIcon, } from "@/components/icons/data-tools-icons"; import { DialogAction } from "@/components/shared/dialog-action"; import { Badge } from "@/components/ui/badge"; import { Button, buttonVariants } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { api } from "@/utils/api"; import { useUrl } from "@/utils/hooks/use-url"; import { AddBitbucketProvider } from "./bitbucket/add-bitbucket-provider"; import { EditBitbucketProvider } from "./bitbucket/edit-bitbucket-provider"; import { AddGiteaProvider } from "./gitea/add-gitea-provider"; import { EditGiteaProvider } from "./gitea/edit-gitea-provider"; import { AddGithubProvider } from "./github/add-github-provider"; import { EditGithubProvider } from "./github/edit-github-provider"; import { AddGitlabProvider } from "./gitlab/add-gitlab-provider"; import { EditGitlabProvider } from "./gitlab/edit-gitlab-provider"; export const ShowGitProviders = () => { const { data, isLoading, refetch } = api.gitProvider.getAll.useQuery(); const { mutateAsync, isLoading: isRemoving } = api.gitProvider.remove.useMutation(); const url = useUrl(); const getGitlabUrl = ( clientId: string, gitlabId: string, gitlabUrl: string, ) => { const redirectUri = `${url}/api/providers/gitlab/callback?gitlabId=${gitlabId}`; const scope = "api read_user read_repository"; const authUrl = `${gitlabUrl}/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${encodeURIComponent(scope)}`; return authUrl; }; return (
Git Providers Connect your Git provider for authentication. {isLoading ? (
Loading...
) : ( <> {data?.length === 0 ? (
Create your first Git Provider
) : (
Available Providers
{data?.map((gitProvider, _index) => { const isGithub = gitProvider.providerType === "github"; const isGitlab = gitProvider.providerType === "gitlab"; const isBitbucket = gitProvider.providerType === "bitbucket"; const isGitea = gitProvider.providerType === "gitea"; const haveGithubRequirements = isGithub && gitProvider.github?.githubPrivateKey && gitProvider.github?.githubAppId && gitProvider.github?.githubInstallationId; const haveGitlabRequirements = isGitlab && gitProvider.gitlab?.accessToken && gitProvider.gitlab?.refreshToken; return (
{isGithub && ( )} {isGitlab && ( )} {isBitbucket && ( )} {isGitea && }
{gitProvider.name} {formatDate( gitProvider.createdAt, "yyyy-MM-dd hh:mm:ss a", )}
{isBitbucket && gitProvider.bitbucket?.appPassword && !gitProvider.bitbucket?.apiToken ? ( Deprecated ) : null} {!haveGithubRequirements && isGithub && (
Action Required
)} {haveGithubRequirements && isGithub && (
)} {!haveGitlabRequirements && isGitlab && (
Action Required
)} {isGithub && haveGithubRequirements && ( )} {isGitlab && ( )} {isBitbucket && ( )} {isGitea && ( )} { await mutateAsync({ gitProviderId: gitProvider.gitProviderId, }) .then(() => { toast.success( "Git Provider deleted successfully", ); refetch(); }) .catch(() => { toast.error( "Error deleting Git Provider", ); }); }} >
); })}
{/* */}
)} )}
); };