mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: add test connection bitbucket and gitlab
This commit is contained in:
88
apps/dokploy/server/api/services/bitbucket.ts
Normal file
88
apps/dokploy/server/api/services/bitbucket.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { db } from "@/server/db";
|
||||
import {
|
||||
type apiCreateBitbucket,
|
||||
type apiUpdateBitbucket,
|
||||
bitbucket,
|
||||
gitProvider,
|
||||
} from "@/server/db/schema";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export type Bitbucket = typeof bitbucket.$inferSelect;
|
||||
|
||||
export const createBitbucket = async (
|
||||
input: typeof apiCreateBitbucket._type,
|
||||
) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
.insert(gitProvider)
|
||||
.values({
|
||||
providerType: "bitbucket",
|
||||
authId: input.authId,
|
||||
name: input.name,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
|
||||
if (!newGitProvider) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error to create the git provider",
|
||||
});
|
||||
}
|
||||
|
||||
await tx
|
||||
.insert(bitbucket)
|
||||
.values({
|
||||
...input,
|
||||
gitProviderId: newGitProvider?.gitProviderId,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
});
|
||||
};
|
||||
|
||||
export const findBitbucketById = async (bitbucketId: string) => {
|
||||
const bitbucketProviderResult = await db.query.bitbucket.findFirst({
|
||||
where: eq(bitbucket.bitbucketId, bitbucketId),
|
||||
with: {
|
||||
gitProvider: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!bitbucketProviderResult) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Bitbucket Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
return bitbucketProviderResult;
|
||||
};
|
||||
|
||||
export const updateBitbucket = async (
|
||||
bitbucketId: string,
|
||||
input: typeof apiUpdateBitbucket._type,
|
||||
) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const result = await tx
|
||||
.update(bitbucket)
|
||||
.set({
|
||||
...input,
|
||||
})
|
||||
.where(eq(bitbucket.bitbucketId, bitbucketId))
|
||||
.returning();
|
||||
|
||||
if (input.name) {
|
||||
await tx
|
||||
.update(gitProvider)
|
||||
.set({
|
||||
name: input.name,
|
||||
})
|
||||
.where(eq(gitProvider.gitProviderId, input.gitProviderId))
|
||||
.returning();
|
||||
}
|
||||
|
||||
return result[0];
|
||||
});
|
||||
};
|
||||
@@ -1,19 +1,8 @@
|
||||
import { db } from "@/server/db";
|
||||
import {
|
||||
type apiCreateBitbucket,
|
||||
type apiCreateGithub,
|
||||
type apiCreateGitlab,
|
||||
bitbucket,
|
||||
github,
|
||||
gitlab,
|
||||
gitProvider,
|
||||
} from "@/server/db/schema";
|
||||
import { type apiCreateGithub, github, gitProvider } from "@/server/db/schema";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export type Github = typeof github.$inferSelect;
|
||||
|
||||
export type Gitlab = typeof gitlab.$inferSelect;
|
||||
export const createGithub = async (input: typeof apiCreateGithub._type) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
@@ -44,68 +33,6 @@ export const createGithub = async (input: typeof apiCreateGithub._type) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const createGitlab = async (input: typeof apiCreateGitlab._type) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
.insert(gitProvider)
|
||||
.values({
|
||||
providerType: "gitlab",
|
||||
authId: input.authId,
|
||||
name: input.name,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
|
||||
if (!newGitProvider) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error to create the git provider",
|
||||
});
|
||||
}
|
||||
|
||||
await tx
|
||||
.insert(gitlab)
|
||||
.values({
|
||||
...input,
|
||||
gitProviderId: newGitProvider?.gitProviderId,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
});
|
||||
};
|
||||
|
||||
export const createBitbucket = async (
|
||||
input: typeof apiCreateBitbucket._type,
|
||||
) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
.insert(gitProvider)
|
||||
.values({
|
||||
providerType: "bitbucket",
|
||||
authId: input.authId,
|
||||
name: input.name,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
|
||||
if (!newGitProvider) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error to create the git provider",
|
||||
});
|
||||
}
|
||||
|
||||
await tx
|
||||
.insert(bitbucket)
|
||||
.values({
|
||||
...input,
|
||||
gitProviderId: newGitProvider?.gitProviderId,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
});
|
||||
};
|
||||
|
||||
export const removeGitProvider = async (gitProviderId: string) => {
|
||||
const result = await db
|
||||
.delete(gitProvider)
|
||||
@@ -114,71 +41,3 @@ export const removeGitProvider = async (gitProviderId: string) => {
|
||||
|
||||
return result[0];
|
||||
};
|
||||
|
||||
export const findGithubById = async (githubId: string) => {
|
||||
const githubProviderResult = await db.query.github.findFirst({
|
||||
where: eq(github.githubId, githubId),
|
||||
});
|
||||
|
||||
if (!githubProviderResult) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Github Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
return githubProviderResult;
|
||||
};
|
||||
|
||||
export const haveGithubRequirements = (github: Github) => {
|
||||
return !!(
|
||||
github?.githubAppId &&
|
||||
github?.githubPrivateKey &&
|
||||
github?.githubInstallationId
|
||||
);
|
||||
};
|
||||
|
||||
export const findGitlabById = async (gitlabId: string) => {
|
||||
const gitlabProviderResult = await db.query.gitlab.findFirst({
|
||||
where: eq(gitlab.gitlabId, gitlabId),
|
||||
});
|
||||
|
||||
if (!gitlabProviderResult) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Gitlab Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
return gitlabProviderResult;
|
||||
};
|
||||
|
||||
export const updateGitlab = async (
|
||||
gitlabId: string,
|
||||
input: Partial<Gitlab>,
|
||||
) => {
|
||||
const result = await db
|
||||
.update(gitlab)
|
||||
.set({
|
||||
...input,
|
||||
})
|
||||
.where(eq(gitlab.gitlabId, gitlabId))
|
||||
.returning();
|
||||
|
||||
return result[0];
|
||||
};
|
||||
|
||||
export const findBitbucketById = async (bitbucketId: string) => {
|
||||
const bitbucketProviderResult = await db.query.bitbucket.findFirst({
|
||||
where: eq(bitbucket.bitbucketId, bitbucketId),
|
||||
});
|
||||
|
||||
if (!bitbucketProviderResult) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Bitbucket Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
return bitbucketProviderResult;
|
||||
};
|
||||
|
||||
58
apps/dokploy/server/api/services/github.ts
Normal file
58
apps/dokploy/server/api/services/github.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { db } from "@/server/db";
|
||||
import { type apiCreateGithub, github, gitProvider } from "@/server/db/schema";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export type Github = typeof github.$inferSelect;
|
||||
export const createGithub = async (input: typeof apiCreateGithub._type) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
.insert(gitProvider)
|
||||
.values({
|
||||
providerType: "github",
|
||||
authId: input.authId,
|
||||
name: input.name,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
|
||||
if (!newGitProvider) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error to create the git provider",
|
||||
});
|
||||
}
|
||||
|
||||
return await tx
|
||||
.insert(github)
|
||||
.values({
|
||||
...input,
|
||||
gitProviderId: newGitProvider?.gitProviderId,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
});
|
||||
};
|
||||
|
||||
export const findGithubById = async (githubId: string) => {
|
||||
const githubProviderResult = await db.query.github.findFirst({
|
||||
where: eq(github.githubId, githubId),
|
||||
});
|
||||
|
||||
if (!githubProviderResult) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Github Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
return githubProviderResult;
|
||||
};
|
||||
|
||||
export const haveGithubRequirements = (github: Github) => {
|
||||
return !!(
|
||||
github?.githubAppId &&
|
||||
github?.githubPrivateKey &&
|
||||
github?.githubInstallationId
|
||||
);
|
||||
};
|
||||
104
apps/dokploy/server/api/services/gitlab.ts
Normal file
104
apps/dokploy/server/api/services/gitlab.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { db } from "@/server/db";
|
||||
import {
|
||||
type apiCreateGitlab,
|
||||
type apiUpdateGitlab,
|
||||
type bitbucket,
|
||||
type github,
|
||||
gitlab,
|
||||
gitProvider,
|
||||
} from "@/server/db/schema";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export type Github = typeof github.$inferSelect;
|
||||
export type Bitbucket = typeof bitbucket.$inferSelect;
|
||||
export type Gitlab = typeof gitlab.$inferSelect;
|
||||
|
||||
export const createGitlab = async (input: typeof apiCreateGitlab._type) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
.insert(gitProvider)
|
||||
.values({
|
||||
providerType: "gitlab",
|
||||
authId: input.authId,
|
||||
name: input.name,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
|
||||
if (!newGitProvider) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error to create the git provider",
|
||||
});
|
||||
}
|
||||
|
||||
await tx
|
||||
.insert(gitlab)
|
||||
.values({
|
||||
...input,
|
||||
gitProviderId: newGitProvider?.gitProviderId,
|
||||
})
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
});
|
||||
};
|
||||
|
||||
export const findGitlabById = async (gitlabId: string) => {
|
||||
const gitlabProviderResult = await db.query.gitlab.findFirst({
|
||||
where: eq(gitlab.gitlabId, gitlabId),
|
||||
with: {
|
||||
gitProvider: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!gitlabProviderResult) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Gitlab Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
return gitlabProviderResult;
|
||||
};
|
||||
|
||||
export const updateGitlab = async (
|
||||
gitlabId: string,
|
||||
input: typeof apiUpdateGitlab._type,
|
||||
) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const result = await tx
|
||||
.update(gitlab)
|
||||
.set({
|
||||
...input,
|
||||
})
|
||||
.where(eq(gitlab.gitlabId, gitlabId))
|
||||
.returning();
|
||||
|
||||
if (input.name) {
|
||||
await tx
|
||||
.update(gitProvider)
|
||||
.set({
|
||||
name: input.name,
|
||||
})
|
||||
.where(eq(gitProvider.gitProviderId, input.gitProviderId))
|
||||
.returning();
|
||||
}
|
||||
|
||||
return result[0];
|
||||
});
|
||||
};
|
||||
|
||||
export const updateGitlabComplete = async (
|
||||
gitlabId: string,
|
||||
input: Partial<Gitlab>,
|
||||
) => {
|
||||
return await db
|
||||
.update(gitlab)
|
||||
.set({
|
||||
...input,
|
||||
})
|
||||
.where(eq(gitlab.gitlabId, gitlabId))
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
};
|
||||
Reference in New Issue
Block a user