From 766b166bf25a751af87eb421924d55df8aa91a37 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:48:47 -0600 Subject: [PATCH] refactor: simplify database colums --- .../generic/save-bitbucket-provider.tsx | 23 +++++++++---------- .../general/generic/save-github-provider.tsx | 22 +++++++++--------- .../general/generic/save-gitlab-provider.tsx | 22 +++++++++--------- .../settings/git/show-git-providers.tsx | 19 ++++++++------- .../dokploy/server/api/routers/application.ts | 6 ++--- .../server/api/routers/git-provider.ts | 10 ++++---- apps/dokploy/server/db/schema/admin.ts | 2 +- .../server/utils/providers/bitbucket.ts | 16 +++++-------- apps/dokploy/server/utils/providers/github.ts | 12 +++++----- apps/dokploy/server/utils/providers/gitlab.ts | 14 +++++------ 10 files changed, 70 insertions(+), 76 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx index 88f56778d..fe6f7d66e 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx @@ -47,7 +47,7 @@ const BitbucketProviderSchema = z.object({ }) .required(), branch: z.string().min(1, "Branch is required"), - bitbucketProviderId: z.string().min(1, "Bitbucket Provider is required"), + bitbucketId: z.string().min(1, "Bitbucket Provider is required"), }); type BitbucketProvider = z.infer; @@ -71,14 +71,14 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => { owner: "", repo: "", }, - bitbucketProviderId: "", + bitbucketId: "", branch: "", }, resolver: zodResolver(BitbucketProviderSchema), }); const repository = form.watch("repository"); - const bitbucketProviderId = form.watch("bitbucketProviderId"); + const bitbucketId = form.watch("bitbucketId"); const { data: repositories, @@ -86,7 +86,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => { error, isError, } = api.gitProvider.getBitbucketRepositories.useQuery({ - bitbucketProviderId, + bitbucketId, }); const { @@ -97,11 +97,10 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => { { owner: repository?.owner, repo: repository?.repo, - bitbucketProviderId, + bitbucketId, }, { - enabled: - !!repository?.owner && !!repository?.repo && !!bitbucketProviderId, + enabled: !!repository?.owner && !!repository?.repo && !!bitbucketId, }, ); @@ -114,7 +113,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => { owner: data.bitbucketOwner || "", }, buildPath: data.bitbucketBuildPath || "/", - bitbucketProviderId: data.bitbucketProviderId || "", + bitbucketId: data.bitbucketId || "", }); } }, [form.reset, data, form]); @@ -125,7 +124,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => { bitbucketRepository: data.repository.repo, bitbucketOwner: data.repository.owner, bitbucketBuildPath: data.buildPath, - bitbucketProviderId: data.bitbucketProviderId, + bitbucketId: data.bitbucketId, applicationId, }) .then(async () => { @@ -150,7 +149,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
( Bitbucket Account @@ -174,8 +173,8 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => { {bitbucketProviders?.map((bitbucketProvider) => ( {bitbucketProvider.gitProvider.name} diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx index 6eebad040..739db5073 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx @@ -46,7 +46,7 @@ const GithubProviderSchema = z.object({ }) .required(), branch: z.string().min(1, "Branch is required"), - githubProviderId: z.string().min(1, "Github Provider is required"), + githubId: z.string().min(1, "Github Provider is required"), }); type GithubProvider = z.infer; @@ -69,18 +69,18 @@ export const SaveGithubProvider = ({ applicationId }: Props) => { owner: "", repo: "", }, - githubProviderId: "", + githubId: "", branch: "", }, resolver: zodResolver(GithubProviderSchema), }); const repository = form.watch("repository"); - const githubProviderId = form.watch("githubProviderId"); + const githubId = form.watch("githubId"); const { data: repositories, isLoading: isLoadingRepositories } = api.gitProvider.getRepositories.useQuery({ - githubProviderId, + githubId, }); const { @@ -91,10 +91,10 @@ export const SaveGithubProvider = ({ applicationId }: Props) => { { owner: repository?.owner, repo: repository?.repo, - githubProviderId, + githubId, }, { - enabled: !!repository?.owner && !!repository?.repo && !!githubProviderId, + enabled: !!repository?.owner && !!repository?.repo && !!githubId, }, ); @@ -107,7 +107,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => { owner: data.owner || "", }, buildPath: data.buildPath || "/", - githubProviderId: data.githubProviderId || "", + githubId: data.githubId || "", }); } }, [form.reset, data, form]); @@ -119,7 +119,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => { applicationId, owner: data.repository.owner, buildPath: data.buildPath, - githubProviderId: data.githubProviderId, + githubId: data.githubId, }) .then(async () => { toast.success("Service Provided Saved"); @@ -140,7 +140,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
( Github Account @@ -164,8 +164,8 @@ export const SaveGithubProvider = ({ applicationId }: Props) => { {githubProviders?.map((githubProvider) => ( {githubProvider.gitProvider.name} diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx index 481c201ea..185976a88 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx @@ -47,7 +47,7 @@ const GitlabProviderSchema = z.object({ }) .required(), branch: z.string().min(1, "Branch is required"), - gitlabProviderId: z.string().min(1, "Gitlab Provider is required"), + gitlabId: z.string().min(1, "Gitlab Provider is required"), }); type GitlabProvider = z.infer; @@ -70,21 +70,21 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => { owner: "", repo: "", }, - gitlabProviderId: "", + gitlabId: "", branch: "", }, resolver: zodResolver(GitlabProviderSchema), }); const repository = form.watch("repository"); - const gitlabProviderId = form.watch("gitlabProviderId"); + const gitlabId = form.watch("gitlabId"); const { data: repositories, isLoading: isLoadingRepositories, error, } = api.gitProvider.getGitlabRepositories.useQuery({ - gitlabProviderId, + gitlabId, }); const { @@ -95,10 +95,10 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => { { owner: repository?.owner, repo: repository?.repo, - gitlabProviderId: gitlabProviderId, + gitlabId: gitlabId, }, { - enabled: !!repository?.owner && !!repository?.repo && !!gitlabProviderId, + enabled: !!repository?.owner && !!repository?.repo && !!gitlabId, }, ); @@ -111,7 +111,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => { owner: data.gitlabOwner || "", }, buildPath: data.gitlabBuildPath || "/", - gitlabProviderId: data.gitlabProviderId || "", + gitlabId: data.gitlabId || "", }); } }, [form.reset, data, form]); @@ -122,7 +122,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => { gitlabRepository: data.repository.repo, gitlabOwner: data.repository.owner, gitlabBuildPath: data.buildPath, - gitlabProviderId: data.gitlabProviderId, + gitlabId: data.gitlabId, applicationId, }) .then(async () => { @@ -145,7 +145,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
( Gitlab Account @@ -169,8 +169,8 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => { {gitlabProviders?.map((gitlabProvider) => ( {gitlabProvider.gitProvider.name} 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 c7c131eca..a67a3682c 100644 --- a/apps/dokploy/components/dashboard/settings/git/show-git-providers.tsx +++ b/apps/dokploy/components/dashboard/settings/git/show-git-providers.tsx @@ -1,5 +1,5 @@ import { buttonVariants } from "@/components/ui/button"; -import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card"; +import { Card, CardContent } from "@/components/ui/card"; import { AddGitlabProvider } from "./add-gitlab-provider"; import { BitbucketIcon, @@ -49,13 +49,12 @@ export const ShowGitProviders = () => { const isGitlab = gitProvider.providerType === "gitlab"; const haveGithubRequirements = gitProvider.providerType === "github" && - gitProvider.githubProvider?.githubPrivateKey && - gitProvider.githubProvider?.githubAppId && - gitProvider.githubProvider?.githubInstallationId; + gitProvider.github?.githubPrivateKey && + gitProvider.github?.githubAppId && + gitProvider.github?.githubInstallationId; const haveGitlabRequirements = - gitProvider.gitlabProvider?.accessToken && - gitProvider.gitlabProvider?.refreshToken; + gitProvider.gitlab?.accessToken && gitProvider.gitlab?.refreshToken; return (
{ {!haveGithubRequirements && isGithub && (
Install Github App @@ -100,7 +99,7 @@ export const ShowGitProviders = () => { {haveGithubRequirements && isGithub && (
{
{ @@ -141,7 +141,7 @@ export const gitProvider = createTRPCRouter({ z.object({ owner: z.string(), repo: z.string(), - gitlabProviderId: z.string().optional(), + gitlabId: z.string().optional(), }), ) .query(async ({ input }) => { @@ -150,7 +150,7 @@ export const gitProvider = createTRPCRouter({ getBitbucketRepositories: protectedProcedure .input( z.object({ - bitbucketProviderId: z.string().optional(), + bitbucketId: z.string().optional(), }), ) .query(async ({ input }) => { @@ -161,7 +161,7 @@ export const gitProvider = createTRPCRouter({ z.object({ owner: z.string(), repo: z.string(), - bitbucketProviderId: z.string().optional(), + bitbucketId: z.string().optional(), }), ) .query(async ({ input }) => { @@ -170,7 +170,7 @@ export const gitProvider = createTRPCRouter({ getRepositories: protectedProcedure .input( z.object({ - githubProviderId: z.string().optional(), + githubId: z.string().optional(), }), ) .query(async ({ input }) => { diff --git a/apps/dokploy/server/db/schema/admin.ts b/apps/dokploy/server/db/schema/admin.ts index 6783ff437..567df2e2f 100644 --- a/apps/dokploy/server/db/schema/admin.ts +++ b/apps/dokploy/server/db/schema/admin.ts @@ -71,7 +71,7 @@ export const apiTraefikConfig = z.object({ export const apiGetBranches = z.object({ repo: z.string().min(1), owner: z.string().min(1), - githubProviderId: z.string().optional(), + githubId: z.string().optional(), }); export const apiModifyTraefikConfig = z.object({ path: z.string().min(1), diff --git a/apps/dokploy/server/utils/providers/bitbucket.ts b/apps/dokploy/server/utils/providers/bitbucket.ts index 824e7fc5c..e3f804aa8 100644 --- a/apps/dokploy/server/utils/providers/bitbucket.ts +++ b/apps/dokploy/server/utils/providers/bitbucket.ts @@ -111,18 +111,16 @@ export const cloneRawBitbucketRepository = async ( }; interface GetBitbucketRepositories { - bitbucketProviderId?: string; + bitbucketId?: string; } export const getBitbucketRepositories = async ( input: GetBitbucketRepositories, ) => { - if (!input.bitbucketProviderId) { + if (!input.bitbucketId) { return []; } - const bitbucketProvider = await getBitbucketProvider( - input.bitbucketProviderId, - ); + const bitbucketProvider = await getBitbucketProvider(input.bitbucketId); const url = `https://api.bitbucket.org/2.0/repositories/${bitbucketProvider.bitbucketUsername}`; @@ -168,16 +166,14 @@ export const getBitbucketRepositories = async ( interface GetBitbucketBranches { owner: string; repo: string; - bitbucketProviderId?: string; + bitbucketId?: string; } export const getBitbucketBranches = async (input: GetBitbucketBranches) => { - if (!input.bitbucketProviderId) { + if (!input.bitbucketId) { return []; } - const bitbucketProvider = await getBitbucketProvider( - input.bitbucketProviderId, - ); + const bitbucketProvider = await getBitbucketProvider(input.bitbucketId); const { owner, repo } = input; const url = `https://api.bitbucket.org/2.0/repositories/${owner}/${repo}/refs/branches`; diff --git a/apps/dokploy/server/utils/providers/github.ts b/apps/dokploy/server/utils/providers/github.ts index 63392aa9b..75254d5ca 100644 --- a/apps/dokploy/server/utils/providers/github.ts +++ b/apps/dokploy/server/utils/providers/github.ts @@ -176,15 +176,15 @@ export const cloneRawGithubRepository = async ( }; interface GetGithubRepositories { - githubProviderId?: string; + githubId?: string; } export const getGithubRepositories = async (input: GetGithubRepositories) => { - if (!input.githubProviderId) { + if (!input.githubId) { return []; } - const githubProvider = await getGithubProvider(input.githubProviderId); + const githubProvider = await getGithubProvider(input.githubId); const octokit = new Octokit({ authStrategy: createAppAuth, @@ -207,14 +207,14 @@ export const getGithubRepositories = async (input: GetGithubRepositories) => { interface GetGithubBranches { owner: string; repo: string; - githubProviderId?: string; + githubId?: string; } export const getGithubBranches = async (input: GetGithubBranches) => { - if (!input.githubProviderId) { + if (!input.githubId) { return []; } - const githubProvider = await getGithubProvider(input.githubProviderId); + const githubProvider = await getGithubProvider(input.githubId); const octokit = new Octokit({ authStrategy: createAppAuth, diff --git a/apps/dokploy/server/utils/providers/gitlab.ts b/apps/dokploy/server/utils/providers/gitlab.ts index e0f0db4ec..7fb40f6f4 100644 --- a/apps/dokploy/server/utils/providers/gitlab.ts +++ b/apps/dokploy/server/utils/providers/gitlab.ts @@ -152,17 +152,17 @@ export const cloneGitlabRepository = async ( }; interface GetGitlabRepositories { - gitlabProviderId?: string; + gitlabId?: string; } export const getGitlabRepositories = async (input: GetGitlabRepositories) => { - if (!input.gitlabProviderId) { + if (!input.gitlabId) { return []; } - await refreshGitlabToken(input.gitlabProviderId); + await refreshGitlabToken(input.gitlabId); - const gitlabProvider = await getGitlabProvider(input.gitlabProviderId); + const gitlabProvider = await getGitlabProvider(input.gitlabId); const response = await fetch( `https://gitlab.com/api/v4/projects?membership=true&owned=true&page=${0}&per_page=${100}`, { @@ -192,15 +192,15 @@ export const getGitlabRepositories = async (input: GetGitlabRepositories) => { interface GetGitlabBranches { owner: string; repo: string; - gitlabProviderId?: string; + gitlabId?: string; } export const getGitlabBranches = async (input: GetGitlabBranches) => { - if (!input.gitlabProviderId) { + if (!input.gitlabId) { return []; } - const gitlabProvider = await getGitlabProvider(input.gitlabProviderId); + const gitlabProvider = await getGitlabProvider(input.gitlabId); const projectResponse = await fetch( `https://gitlab.com/api/v4/projects?search=${input.repo}&owned=true&page=1&per_page=100`,