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 = {
|
const baseApp: ApplicationNested = {
|
||||||
applicationId: "",
|
applicationId: "",
|
||||||
herokuVersion: "",
|
herokuVersion: "",
|
||||||
|
giteaBranch: "",
|
||||||
|
giteaBuildPath: "",
|
||||||
|
giteaId: "",
|
||||||
|
giteaOwner: "",
|
||||||
|
giteaRepository: "",
|
||||||
cleanCache: false,
|
cleanCache: false,
|
||||||
watchPaths: [],
|
watchPaths: [],
|
||||||
applicationStatus: "done",
|
applicationStatus: "done",
|
||||||
|
@ -7,6 +7,11 @@ import { expect, test } from "vitest";
|
|||||||
const baseApp: ApplicationNested = {
|
const baseApp: ApplicationNested = {
|
||||||
applicationId: "",
|
applicationId: "",
|
||||||
herokuVersion: "",
|
herokuVersion: "",
|
||||||
|
giteaRepository: "",
|
||||||
|
giteaOwner: "",
|
||||||
|
giteaBranch: "",
|
||||||
|
giteaBuildPath: "",
|
||||||
|
giteaId: "",
|
||||||
cleanCache: false,
|
cleanCache: false,
|
||||||
applicationStatus: "done",
|
applicationStatus: "done",
|
||||||
appName: "",
|
appName: "",
|
||||||
|
@ -67,7 +67,6 @@ const GiteaProviderSchema = z.object({
|
|||||||
.object({
|
.object({
|
||||||
repo: z.string().min(1, "Repo is required"),
|
repo: z.string().min(1, "Repo is required"),
|
||||||
owner: z.string().min(1, "Owner is required"),
|
owner: z.string().min(1, "Owner is required"),
|
||||||
id: z.number().nullable().optional(),
|
|
||||||
})
|
})
|
||||||
.required(),
|
.required(),
|
||||||
branch: z.string().min(1, "Branch is required"),
|
branch: z.string().min(1, "Branch is required"),
|
||||||
@ -94,7 +93,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
|||||||
repository: {
|
repository: {
|
||||||
owner: "",
|
owner: "",
|
||||||
repo: "",
|
repo: "",
|
||||||
id: null,
|
|
||||||
},
|
},
|
||||||
giteaId: "",
|
giteaId: "",
|
||||||
branch: "",
|
branch: "",
|
||||||
@ -127,7 +125,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
|||||||
{
|
{
|
||||||
owner: repository?.owner,
|
owner: repository?.owner,
|
||||||
repositoryName: repository?.repo,
|
repositoryName: repository?.repo,
|
||||||
id: repository?.id ?? 0, // Use nullish coalescing to provide 0 as a fallback
|
|
||||||
giteaId: giteaId,
|
giteaId: giteaId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -142,7 +139,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
|||||||
repository: {
|
repository: {
|
||||||
repo: data.giteaRepository || "",
|
repo: data.giteaRepository || "",
|
||||||
owner: data.giteaOwner || "",
|
owner: data.giteaOwner || "",
|
||||||
id: data.giteaProjectId || null, // Handle null case explicitly
|
|
||||||
},
|
},
|
||||||
buildPath: data.giteaBuildPath || "/",
|
buildPath: data.giteaBuildPath || "/",
|
||||||
giteaId: data.giteaId || "",
|
giteaId: data.giteaId || "",
|
||||||
@ -159,7 +155,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
|||||||
giteaBuildPath: data.buildPath,
|
giteaBuildPath: data.buildPath,
|
||||||
giteaId: data.giteaId,
|
giteaId: data.giteaId,
|
||||||
applicationId,
|
applicationId,
|
||||||
giteaProjectId: data.repository.id || null, // Handle null case explicitly
|
|
||||||
watchPaths: data.watchPaths,
|
watchPaths: data.watchPaths,
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
@ -192,7 +187,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
|||||||
form.setValue("repository", {
|
form.setValue("repository", {
|
||||||
owner: "",
|
owner: "",
|
||||||
repo: "",
|
repo: "",
|
||||||
id: null,
|
|
||||||
});
|
});
|
||||||
form.setValue("branch", "");
|
form.setValue("branch", "");
|
||||||
}}
|
}}
|
||||||
@ -277,7 +271,6 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
|||||||
form.setValue("repository", {
|
form.setValue("repository", {
|
||||||
owner: repo.owner.username as string,
|
owner: repo.owner.username as string,
|
||||||
repo: repo.name,
|
repo: repo.name,
|
||||||
id: repo.id,
|
|
||||||
});
|
});
|
||||||
form.setValue("branch", "");
|
form.setValue("branch", "");
|
||||||
}}
|
}}
|
||||||
|
@ -39,7 +39,7 @@ import {
|
|||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { api } from "@/utils/api";
|
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 { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { CheckIcon, ChevronsUpDown, Plus, X } from "lucide-react";
|
import { CheckIcon, ChevronsUpDown, Plus, X } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@ -54,7 +54,6 @@ const GiteaProviderSchema = z.object({
|
|||||||
.object({
|
.object({
|
||||||
repo: z.string().min(1, "Repo is required"),
|
repo: z.string().min(1, "Repo is required"),
|
||||||
owner: z.string().min(1, "Owner is required"),
|
owner: z.string().min(1, "Owner is required"),
|
||||||
id: z.number().nullable(),
|
|
||||||
})
|
})
|
||||||
.required(),
|
.required(),
|
||||||
branch: z.string().min(1, "Branch is required"),
|
branch: z.string().min(1, "Branch is required"),
|
||||||
@ -80,7 +79,6 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
|||||||
repository: {
|
repository: {
|
||||||
owner: "",
|
owner: "",
|
||||||
repo: "",
|
repo: "",
|
||||||
id: null,
|
|
||||||
},
|
},
|
||||||
giteaId: "",
|
giteaId: "",
|
||||||
branch: "",
|
branch: "",
|
||||||
@ -116,11 +114,10 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
|||||||
data: branches,
|
data: branches,
|
||||||
fetchStatus,
|
fetchStatus,
|
||||||
status,
|
status,
|
||||||
} = api.gitea.getGiteaBranches.useQuery<Branch[]>(
|
} = api.gitea.getGiteaBranches.useQuery(
|
||||||
{
|
{
|
||||||
owner: repository?.owner,
|
owner: repository?.owner,
|
||||||
repositoryName: repository?.repo,
|
repositoryName: repository?.repo,
|
||||||
id: repository?.id || 0,
|
|
||||||
giteaId: giteaId,
|
giteaId: giteaId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -130,55 +127,18 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
console.log("Setting form data from API:", data);
|
form.reset({
|
||||||
|
branch: data.giteaBranch || "",
|
||||||
// Only reset form on initial load, not after user interactions
|
repository: {
|
||||||
if (!form.formState.isDirty && !form.formState.dirtyFields.giteaId) {
|
repo: data.giteaRepository || "",
|
||||||
console.log("Initial form reset from API data");
|
owner: data.giteaOwner || "",
|
||||||
form.reset({
|
},
|
||||||
branch: data.giteaBranch || "",
|
composePath: data.composePath || "./docker-compose.yml",
|
||||||
repository: {
|
giteaId: data.giteaId || "",
|
||||||
repo: data.giteaRepository || "",
|
watchPaths: data.watchPaths || [],
|
||||||
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]);
|
}, [form.reset, data, form]);
|
||||||
|
|
||||||
// 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]);
|
|
||||||
|
|
||||||
const onSubmit = async (data: GiteaProvider) => {
|
const onSubmit = async (data: GiteaProvider) => {
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
@ -219,18 +179,12 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
|||||||
<FormLabel>Gitea Account</FormLabel>
|
<FormLabel>Gitea Account</FormLabel>
|
||||||
<Select
|
<Select
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
console.log("Select changed to:", value);
|
|
||||||
field.onChange(value);
|
field.onChange(value);
|
||||||
form.setValue(
|
form.setValue("repository", {
|
||||||
"repository",
|
owner: "",
|
||||||
{
|
repo: "",
|
||||||
owner: "",
|
});
|
||||||
repo: "",
|
form.setValue("branch", "");
|
||||||
id: null,
|
|
||||||
},
|
|
||||||
{ shouldValidate: false },
|
|
||||||
);
|
|
||||||
form.setValue("branch", "", { shouldValidate: false });
|
|
||||||
}}
|
}}
|
||||||
defaultValue={field.value}
|
defaultValue={field.value}
|
||||||
value={field.value}
|
value={field.value}
|
||||||
@ -315,14 +269,9 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
|||||||
key={repo.url}
|
key={repo.url}
|
||||||
value={repo.name}
|
value={repo.name}
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
console.log(
|
|
||||||
"Repository selected:",
|
|
||||||
repo.name,
|
|
||||||
);
|
|
||||||
form.setValue("repository", {
|
form.setValue("repository", {
|
||||||
owner: repo.owner.username,
|
owner: repo.owner.username,
|
||||||
repo: repo.name,
|
repo: repo.name,
|
||||||
id: repo.id,
|
|
||||||
});
|
});
|
||||||
form.setValue("branch", "");
|
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,
|
"when": 1742281690186,
|
||||||
"tag": "0079_bizarre_wendell_rand",
|
"tag": "0079_bizarre_wendell_rand",
|
||||||
"breakpoints": true
|
"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",
|
sourceType: "gitea",
|
||||||
applicationStatus: "idle",
|
applicationStatus: "idle",
|
||||||
giteaId: input.giteaId,
|
giteaId: input.giteaId,
|
||||||
giteaProjectId: input.giteaProjectId,
|
|
||||||
watchPaths: input.watchPaths,
|
watchPaths: input.watchPaths,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -143,7 +143,6 @@ export const giteaRouter = createTRPCRouter({
|
|||||||
giteaId,
|
giteaId,
|
||||||
owner,
|
owner,
|
||||||
repo: repositoryName,
|
repo: repositoryName,
|
||||||
id: 0,
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching Gitea branches:", error);
|
console.error("Error fetching Gitea branches:", error);
|
||||||
|
@ -158,7 +158,6 @@ export const applications = pgTable("application", {
|
|||||||
gitlabBuildPath: text("gitlabBuildPath").default("/"),
|
gitlabBuildPath: text("gitlabBuildPath").default("/"),
|
||||||
gitlabPathNamespace: text("gitlabPathNamespace"),
|
gitlabPathNamespace: text("gitlabPathNamespace"),
|
||||||
// Gitea
|
// Gitea
|
||||||
giteaProjectId: integer("giteaProjectId"),
|
|
||||||
giteaRepository: text("giteaRepository"),
|
giteaRepository: text("giteaRepository"),
|
||||||
giteaOwner: text("giteaOwner"),
|
giteaOwner: text("giteaOwner"),
|
||||||
giteaBranch: text("giteaBranch"),
|
giteaBranch: text("giteaBranch"),
|
||||||
@ -508,7 +507,6 @@ export const apiSaveGiteaProvider = createSchema
|
|||||||
giteaOwner: true,
|
giteaOwner: true,
|
||||||
giteaRepository: true,
|
giteaRepository: true,
|
||||||
giteaId: true,
|
giteaId: true,
|
||||||
giteaProjectId: true,
|
|
||||||
watchPaths: true,
|
watchPaths: true,
|
||||||
})
|
})
|
||||||
.required();
|
.required();
|
||||||
|
@ -65,7 +65,6 @@ export const apiGiteaTestConnection = createSchema
|
|||||||
export type ApiGiteaTestConnection = z.infer<typeof apiGiteaTestConnection>;
|
export type ApiGiteaTestConnection = z.infer<typeof apiGiteaTestConnection>;
|
||||||
|
|
||||||
export const apiFindGiteaBranches = z.object({
|
export const apiFindGiteaBranches = z.object({
|
||||||
id: z.number().optional(),
|
|
||||||
owner: z.string().min(1),
|
owner: z.string().min(1),
|
||||||
repositoryName: z.string().min(1),
|
repositoryName: z.string().min(1),
|
||||||
giteaId: z.string().optional(),
|
giteaId: z.string().optional(),
|
||||||
|
@ -413,7 +413,6 @@ export const getGiteaRepositories = async (giteaId?: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getGiteaBranches = async (input: {
|
export const getGiteaBranches = async (input: {
|
||||||
id?: number;
|
|
||||||
giteaId?: string;
|
giteaId?: string;
|
||||||
owner: string;
|
owner: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
@ -448,5 +447,11 @@ export const getGiteaBranches = async (input: {
|
|||||||
commit: {
|
commit: {
|
||||||
id: branch.commit.id,
|
id: branch.commit.id,
|
||||||
},
|
},
|
||||||
}));
|
})) as {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
commit: {
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
}[];
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user