mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Refactor Gitea integration: remove giteaProjectId references and update related schemas. Add new fields for gitea repository details in application tests and components.
This commit is contained in:
parent
fe967239b4
commit
55328468d1
@ -27,6 +27,11 @@ if (typeof window === "undefined") {
|
||||
const baseApp: ApplicationNested = {
|
||||
applicationId: "",
|
||||
herokuVersion: "",
|
||||
giteaBranch: "",
|
||||
giteaBuildPath: "",
|
||||
giteaId: "",
|
||||
giteaOwner: "",
|
||||
giteaRepository: "",
|
||||
cleanCache: false,
|
||||
watchPaths: [],
|
||||
applicationStatus: "done",
|
||||
|
@ -7,6 +7,11 @@ import { expect, test } from "vitest";
|
||||
const baseApp: ApplicationNested = {
|
||||
applicationId: "",
|
||||
herokuVersion: "",
|
||||
giteaRepository: "",
|
||||
giteaOwner: "",
|
||||
giteaBranch: "",
|
||||
giteaBuildPath: "",
|
||||
giteaId: "",
|
||||
cleanCache: false,
|
||||
applicationStatus: "done",
|
||||
appName: "",
|
||||
|
@ -67,7 +67,6 @@ const GiteaProviderSchema = z.object({
|
||||
.object({
|
||||
repo: z.string().min(1, "Repo is required"),
|
||||
owner: z.string().min(1, "Owner is required"),
|
||||
id: z.number().nullable().optional(),
|
||||
})
|
||||
.required(),
|
||||
branch: z.string().min(1, "Branch is required"),
|
||||
@ -94,7 +93,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
repository: {
|
||||
owner: "",
|
||||
repo: "",
|
||||
id: null,
|
||||
},
|
||||
giteaId: "",
|
||||
branch: "",
|
||||
@ -127,7 +125,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
{
|
||||
owner: repository?.owner,
|
||||
repositoryName: repository?.repo,
|
||||
id: repository?.id ?? 0, // Use nullish coalescing to provide 0 as a fallback
|
||||
giteaId: giteaId,
|
||||
},
|
||||
{
|
||||
@ -142,7 +139,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
repository: {
|
||||
repo: data.giteaRepository || "",
|
||||
owner: data.giteaOwner || "",
|
||||
id: data.giteaProjectId || null, // Handle null case explicitly
|
||||
},
|
||||
buildPath: data.giteaBuildPath || "/",
|
||||
giteaId: data.giteaId || "",
|
||||
@ -159,7 +155,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
giteaBuildPath: data.buildPath,
|
||||
giteaId: data.giteaId,
|
||||
applicationId,
|
||||
giteaProjectId: data.repository.id || null, // Handle null case explicitly
|
||||
watchPaths: data.watchPaths,
|
||||
})
|
||||
.then(async () => {
|
||||
@ -192,7 +187,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
form.setValue("repository", {
|
||||
owner: "",
|
||||
repo: "",
|
||||
id: null,
|
||||
});
|
||||
form.setValue("branch", "");
|
||||
}}
|
||||
@ -277,7 +271,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
form.setValue("repository", {
|
||||
owner: repo.owner.username as string,
|
||||
repo: repo.name,
|
||||
id: repo.id,
|
||||
});
|
||||
form.setValue("branch", "");
|
||||
}}
|
||||
|
@ -39,7 +39,7 @@ import {
|
||||
} from "@/components/ui/tooltip";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { api } from "@/utils/api";
|
||||
import type { Branch, Repository } from "@/utils/gitea-utils";
|
||||
import type { Repository } from "@/utils/gitea-utils";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { CheckIcon, ChevronsUpDown, Plus, X } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
@ -54,7 +54,6 @@ const GiteaProviderSchema = z.object({
|
||||
.object({
|
||||
repo: z.string().min(1, "Repo is required"),
|
||||
owner: z.string().min(1, "Owner is required"),
|
||||
id: z.number().nullable(),
|
||||
})
|
||||
.required(),
|
||||
branch: z.string().min(1, "Branch is required"),
|
||||
@ -80,7 +79,6 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
repository: {
|
||||
owner: "",
|
||||
repo: "",
|
||||
id: null,
|
||||
},
|
||||
giteaId: "",
|
||||
branch: "",
|
||||
@ -116,11 +114,10 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
data: branches,
|
||||
fetchStatus,
|
||||
status,
|
||||
} = api.gitea.getGiteaBranches.useQuery<Branch[]>(
|
||||
} = api.gitea.getGiteaBranches.useQuery(
|
||||
{
|
||||
owner: repository?.owner,
|
||||
repositoryName: repository?.repo,
|
||||
id: repository?.id || 0,
|
||||
giteaId: giteaId,
|
||||
},
|
||||
{
|
||||
@ -130,55 +127,18 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
console.log("Setting form data from API:", data);
|
||||
|
||||
// Only reset form on initial load, not after user interactions
|
||||
if (!form.formState.isDirty && !form.formState.dirtyFields.giteaId) {
|
||||
console.log("Initial form reset from API data");
|
||||
form.reset({
|
||||
branch: data.giteaBranch || "",
|
||||
repository: {
|
||||
repo: data.giteaRepository || "",
|
||||
owner: data.giteaOwner || "",
|
||||
id: null,
|
||||
},
|
||||
composePath: data.composePath || "./docker-compose.yml",
|
||||
giteaId: data.giteaId || "",
|
||||
watchPaths: data.watchPaths || [],
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
"Skipping form reset because form has been modified by user",
|
||||
);
|
||||
}
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
// Add this separate effect to update repository ID if needed
|
||||
useEffect(() => {
|
||||
const values = form.getValues();
|
||||
// If we have a repository selected but no ID, try to find it
|
||||
if (
|
||||
values.repository.owner &&
|
||||
values.repository.repo &&
|
||||
!values.repository.id &&
|
||||
repositories?.length
|
||||
) {
|
||||
const matchingRepo = repositories.find(
|
||||
(repo) =>
|
||||
repo.name === values.repository.repo &&
|
||||
repo.owner.username === values.repository.owner,
|
||||
);
|
||||
|
||||
if (matchingRepo) {
|
||||
console.log("Found matching repository ID:", matchingRepo.id);
|
||||
form.setValue("repository", {
|
||||
...values.repository,
|
||||
id: matchingRepo.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [repositories]);
|
||||
}, [form.reset, data, form]);
|
||||
|
||||
const onSubmit = async (data: GiteaProvider) => {
|
||||
await mutateAsync({
|
||||
@ -219,18 +179,12 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
<FormLabel>Gitea Account</FormLabel>
|
||||
<Select
|
||||
onValueChange={(value) => {
|
||||
console.log("Select changed to:", value);
|
||||
field.onChange(value);
|
||||
form.setValue(
|
||||
"repository",
|
||||
{
|
||||
form.setValue("repository", {
|
||||
owner: "",
|
||||
repo: "",
|
||||
id: null,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
form.setValue("branch", "", { shouldValidate: false });
|
||||
});
|
||||
form.setValue("branch", "");
|
||||
}}
|
||||
defaultValue={field.value}
|
||||
value={field.value}
|
||||
@ -315,14 +269,9 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
key={repo.url}
|
||||
value={repo.name}
|
||||
onSelect={() => {
|
||||
console.log(
|
||||
"Repository selected:",
|
||||
repo.name,
|
||||
);
|
||||
form.setValue("repository", {
|
||||
owner: repo.owner.username,
|
||||
repo: repo.name,
|
||||
id: repo.id,
|
||||
});
|
||||
form.setValue("branch", "");
|
||||
}}
|
||||
|
1
apps/dokploy/drizzle/0080_sleepy_sinister_six.sql
Normal file
1
apps/dokploy/drizzle/0080_sleepy_sinister_six.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE "application" DROP COLUMN "giteaProjectId";
|
5348
apps/dokploy/drizzle/meta/0080_snapshot.json
Normal file
5348
apps/dokploy/drizzle/meta/0080_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -561,6 +561,13 @@
|
||||
"when": 1742281690186,
|
||||
"tag": "0079_bizarre_wendell_rand",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 80,
|
||||
"version": "7",
|
||||
"when": 1743280866402,
|
||||
"tag": "0080_sleepy_sinister_six",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
@ -422,7 +422,6 @@ export const applicationRouter = createTRPCRouter({
|
||||
sourceType: "gitea",
|
||||
applicationStatus: "idle",
|
||||
giteaId: input.giteaId,
|
||||
giteaProjectId: input.giteaProjectId,
|
||||
watchPaths: input.watchPaths,
|
||||
});
|
||||
|
||||
|
@ -143,7 +143,6 @@ export const giteaRouter = createTRPCRouter({
|
||||
giteaId,
|
||||
owner,
|
||||
repo: repositoryName,
|
||||
id: 0,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching Gitea branches:", error);
|
||||
|
@ -158,7 +158,6 @@ export const applications = pgTable("application", {
|
||||
gitlabBuildPath: text("gitlabBuildPath").default("/"),
|
||||
gitlabPathNamespace: text("gitlabPathNamespace"),
|
||||
// Gitea
|
||||
giteaProjectId: integer("giteaProjectId"),
|
||||
giteaRepository: text("giteaRepository"),
|
||||
giteaOwner: text("giteaOwner"),
|
||||
giteaBranch: text("giteaBranch"),
|
||||
@ -508,7 +507,6 @@ export const apiSaveGiteaProvider = createSchema
|
||||
giteaOwner: true,
|
||||
giteaRepository: true,
|
||||
giteaId: true,
|
||||
giteaProjectId: true,
|
||||
watchPaths: true,
|
||||
})
|
||||
.required();
|
||||
|
@ -65,7 +65,6 @@ export const apiGiteaTestConnection = createSchema
|
||||
export type ApiGiteaTestConnection = z.infer<typeof apiGiteaTestConnection>;
|
||||
|
||||
export const apiFindGiteaBranches = z.object({
|
||||
id: z.number().optional(),
|
||||
owner: z.string().min(1),
|
||||
repositoryName: z.string().min(1),
|
||||
giteaId: z.string().optional(),
|
||||
|
@ -413,7 +413,6 @@ export const getGiteaRepositories = async (giteaId?: string) => {
|
||||
};
|
||||
|
||||
export const getGiteaBranches = async (input: {
|
||||
id?: number;
|
||||
giteaId?: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
@ -448,5 +447,11 @@ export const getGiteaBranches = async (input: {
|
||||
commit: {
|
||||
id: branch.commit.id,
|
||||
},
|
||||
}));
|
||||
})) as {
|
||||
id: string;
|
||||
name: string;
|
||||
commit: {
|
||||
id: string;
|
||||
};
|
||||
}[];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user