feat(gitea): add Gitea repository support

This commit is contained in:
Jason Parks
2025-03-17 15:17:35 -06:00
parent cf28640188
commit 9a11d0db97
101 changed files with 3272 additions and 2075 deletions

View File

@@ -6,8 +6,8 @@ import { generateObject } from "ai";
import { desc, eq } from "drizzle-orm";
import { z } from "zod";
import { IS_CLOUD } from "../constants";
import { findServerById } from "./server";
import { findOrganizationById } from "./admin";
import { findServerById } from "./server";
export const getAiSettingsByOrganizationId = async (organizationId: string) => {
const aiSettings = await db.query.ai.findMany({

View File

@@ -26,6 +26,10 @@ import {
cloneGitRepository,
getCustomGitCloneCommand,
} from "@dokploy/server/utils/providers/git";
import {
cloneGiteaRepository,
getGiteaCloneCommand,
} from "@dokploy/server/utils/providers/gitea";
import {
cloneGithubRepository,
getGithubCloneCommand,
@@ -34,10 +38,6 @@ import {
cloneGitlabRepository,
getGitlabCloneCommand,
} from "@dokploy/server/utils/providers/gitlab";
import {
cloneGiteaRepository,
getGiteaCloneCommand,
} from "@dokploy/server/utils/providers/gitea";
import { createTraefikConfig } from "@dokploy/server/utils/traefik/application";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
@@ -318,10 +318,7 @@ export const deployRemoteApplication = async ({
deployment.logPath,
);
} else if (application.sourceType === "gitea") {
command += await getGiteaCloneCommand(
application,
deployment.logPath,
);
command += await getGiteaCloneCommand(application, deployment.logPath);
} else if (application.sourceType === "git") {
command += await getCustomGitCloneCommand(
application,

View File

@@ -29,6 +29,10 @@ import {
cloneGitRepository,
getCustomGitCloneCommand,
} from "@dokploy/server/utils/providers/git";
import {
cloneGiteaRepository,
getGiteaCloneCommand,
} from "@dokploy/server/utils/providers/gitea";
import {
cloneGithubRepository,
getGithubCloneCommand,
@@ -37,10 +41,6 @@ import {
cloneGitlabRepository,
getGitlabCloneCommand,
} from "@dokploy/server/utils/providers/gitlab";
import {
cloneGiteaRepository,
getGiteaCloneCommand,
} from "@dokploy/server/utils/providers/gitea";
import {
createComposeFile,
getCreateComposeFileCommand,
@@ -237,7 +237,7 @@ export const deployCompose = async ({
await cloneGiteaRepository(compose, deployment.logPath, true);
} else if (compose.sourceType === "raw") {
await createComposeFile(compose, deployment.logPath);
}
}
await buildCompose(compose, deployment.logPath);
await updateDeploymentStatus(deployment.deploymentId, "done");
await updateCompose(composeId, {
@@ -360,9 +360,9 @@ export const deployRemoteCompose = async ({
command += getCreateComposeFileCommand(compose, deployment.logPath);
} else if (compose.sourceType === "gitea") {
command += await getGiteaCloneCommand(
compose,
deployment.logPath,
true
compose,
deployment.logPath,
true,
);
}

View File

@@ -1,104 +1,100 @@
import { db } from "@dokploy/server/db";
import {
type apiCreateGitea,
gitProvider,
gitea,
type apiCreateGitea,
gitProvider,
gitea,
} 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,
input: typeof apiCreateGitea._type,
organizationId: string,
) => {
return await db.transaction(async (tx) => {
// Insert new Git provider (Gitea)
const newGitProvider = await tx
.insert(gitProvider)
.values({
providerType: "gitea", // Set providerType to 'gitea'
organizationId: organizationId,
name: input.name,
})
.returning()
.then((response) => response[0]);
return await db.transaction(async (tx) => {
// Insert new Git provider (Gitea)
const newGitProvider = await tx
.insert(gitProvider)
.values({
providerType: "gitea", // Set providerType to 'gitea'
organizationId: organizationId,
name: input.name,
})
.returning()
.then((response) => response[0]);
if (!newGitProvider) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error creating the Git provider",
});
}
if (!newGitProvider) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error creating the Git provider",
});
}
// Insert the Gitea data into the `gitea` table
await tx
.insert(gitea)
.values({
...input,
gitProviderId: newGitProvider?.gitProviderId,
})
.returning()
.then((response) => response[0]);
});
// Insert the Gitea data into the `gitea` table
await tx
.insert(gitea)
.values({
...input,
gitProviderId: newGitProvider?.gitProviderId,
})
.returning()
.then((response) => response[0]);
});
};
export const findGiteaById = async (giteaId: string) => {
try {
const giteaProviderResult = await db.query.gitea.findFirst({
where: eq(gitea.giteaId, giteaId),
with: {
gitProvider: true,
},
});
if (!giteaProviderResult) {
console.error('No Gitea Provider found:', { giteaId });
throw new TRPCError({
code: "NOT_FOUND",
message: "Gitea Provider not found",
});
}
return giteaProviderResult;
} catch (error) {
console.error('Error finding Gitea Provider:', error);
throw error;
}
try {
const giteaProviderResult = await db.query.gitea.findFirst({
where: eq(gitea.giteaId, giteaId),
with: {
gitProvider: true,
},
});
if (!giteaProviderResult) {
console.error("No Gitea Provider found:", { giteaId });
throw new TRPCError({
code: "NOT_FOUND",
message: "Gitea Provider not found",
});
}
return giteaProviderResult;
} catch (error) {
console.error("Error finding Gitea Provider:", error);
throw error;
}
};
export const updateGitea = async (
giteaId: string,
input: Partial<Gitea>,
) => {
console.log('Updating Gitea Provider:', {
giteaId,
updateData: {
accessTokenPresent: !!input.accessToken,
refreshTokenPresent: !!input.refreshToken,
expiresAt: input.expiresAt,
}
});
export const updateGitea = async (giteaId: string, input: Partial<Gitea>) => {
console.log("Updating Gitea Provider:", {
giteaId,
updateData: {
accessTokenPresent: !!input.accessToken,
refreshTokenPresent: !!input.refreshToken,
expiresAt: input.expiresAt,
},
});
try {
const updateResult = await db
.update(gitea)
.set(input)
.where(eq(gitea.giteaId, giteaId))
.returning();
try {
const updateResult = await db
.update(gitea)
.set(input)
.where(eq(gitea.giteaId, giteaId))
.returning();
// Explicitly type the result and handle potential undefined
const result = updateResult[0] as Gitea | undefined;
// Explicitly type the result and handle potential undefined
const result = updateResult[0] as Gitea | undefined;
if (!result) {
console.error('No rows were updated', { giteaId, input });
throw new Error(`Failed to update Gitea provider with ID ${giteaId}`);
}
if (!result) {
console.error("No rows were updated", { giteaId, input });
throw new Error(`Failed to update Gitea provider with ID ${giteaId}`);
}
return result;
} catch (error) {
console.error('Error updating Gitea provider:', error);
throw error;
}
};
return result;
} catch (error) {
console.error("Error updating Gitea provider:", error);
throw error;
}
};