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:
86
apps/dokploy/server/api/routers/gitlab.ts
Normal file
86
apps/dokploy/server/api/routers/gitlab.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
|
||||
import {
|
||||
apiCreateGitlab,
|
||||
apiFindGitlabBranches,
|
||||
apiFindOneGitlab,
|
||||
apiGitlabTestConnection,
|
||||
apiUpdateGitlab,
|
||||
} from "@/server/db/schema";
|
||||
|
||||
import {
|
||||
haveGitlabRequirements,
|
||||
getGitlabRepositories,
|
||||
getGitlabBranches,
|
||||
testGitlabConnection,
|
||||
} from "@/server/utils/providers/gitlab";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { createGitlab, findGitlabById, updateGitlab } from "../services/gitlab";
|
||||
import { db } from "@/server/db";
|
||||
|
||||
export const gitlabRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
.input(apiCreateGitlab)
|
||||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
return await createGitlab(input);
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error to create this gitlab provider",
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
}),
|
||||
one: protectedProcedure.input(apiFindOneGitlab).query(async ({ input }) => {
|
||||
return await findGitlabById(input.gitlabId);
|
||||
}),
|
||||
gitlabProviders: protectedProcedure.query(async () => {
|
||||
const result = await db.query.gitlab.findMany({
|
||||
with: {
|
||||
gitProvider: true,
|
||||
},
|
||||
});
|
||||
const filtered = result
|
||||
.filter((provider) => haveGitlabRequirements(provider))
|
||||
.map((provider) => {
|
||||
return {
|
||||
gitlabId: provider.gitlabId,
|
||||
gitProvider: {
|
||||
...provider.gitProvider,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return filtered;
|
||||
}),
|
||||
getGitlabRepositories: protectedProcedure
|
||||
.input(apiFindOneGitlab)
|
||||
.query(async ({ input }) => {
|
||||
return await getGitlabRepositories(input.gitlabId);
|
||||
}),
|
||||
|
||||
getGitlabBranches: protectedProcedure
|
||||
.input(apiFindGitlabBranches)
|
||||
.query(async ({ input }) => {
|
||||
return await getGitlabBranches(input);
|
||||
}),
|
||||
testConnection: protectedProcedure
|
||||
.input(apiGitlabTestConnection)
|
||||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
const result = await testGitlabConnection(input);
|
||||
|
||||
return `Found ${result} repositories`;
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: error instanceof Error ? error?.message : `Error: ${error}`,
|
||||
});
|
||||
}
|
||||
}),
|
||||
update: protectedProcedure
|
||||
.input(apiUpdateGitlab)
|
||||
.mutation(async ({ input }) => {
|
||||
return await updateGitlab(input.gitlabId, input);
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user