Refactor Gitea integration and update related components

This commit is contained in:
Jason Parks
2025-03-19 11:31:08 -06:00
parent 9a11d0db97
commit d7ef201adb
4 changed files with 612 additions and 151 deletions

View File

@@ -6,23 +6,24 @@ import {
} from "@dokploy/server/db/schema";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
export type Gitea = typeof gitea.$inferSelect;
export const createGitea = async (
input: typeof apiCreateGitea._type,
organizationId: string,
) => {
// @ts-ignore - Complex transaction type - Added because proper typing in Drizzle in not sufficient
return await db.transaction(async (tx) => {
// Insert new Git provider (Gitea)
const newGitProvider = await tx
.insert(gitProvider)
.values({
providerType: "gitea", // Set providerType to 'gitea'
providerType: "gitea",
organizationId: organizationId,
name: input.name,
})
.returning()
.then((response) => response[0]);
.then((response: typeof gitProvider.$inferSelect[]) => response[0]);
if (!newGitProvider) {
throw new TRPCError({
@@ -31,7 +32,6 @@ export const createGitea = async (
});
}
// Insert the Gitea data into the `gitea` table
await tx
.insert(gitea)
.values({
@@ -39,7 +39,7 @@ export const createGitea = async (
gitProviderId: newGitProvider?.gitProviderId,
})
.returning()
.then((response) => response[0]);
.then((response: typeof gitea.$inferSelect[]) => response[0]);
});
};
@@ -84,7 +84,6 @@ export const updateGitea = async (giteaId: string, input: Partial<Gitea>) => {
.where(eq(gitea.giteaId, giteaId))
.returning();
// Explicitly type the result and handle potential undefined
const result = updateResult[0] as Gitea | undefined;
if (!result) {
@@ -97,4 +96,4 @@ export const updateGitea = async (giteaId: string, input: Partial<Gitea>) => {
console.error("Error updating Gitea provider:", error);
throw error;
}
};
};

View File

@@ -1,5 +1,5 @@
import { createWriteStream } from "node:fs";
import fs from "node:fs/promises";
import * as fs from "node:fs/promises";
import { join } from "node:path";
import { paths } from "@dokploy/server/constants";
import { findGiteaById, updateGitea } from "@dokploy/server/services/gitea";