Fix Gitea repository integration and preview compose display

This commit is contained in:
Jason Parks 2025-03-23 15:35:22 -06:00
parent d5137d5d3a
commit f04c8a36af
3 changed files with 60 additions and 16 deletions

View File

@ -95,6 +95,13 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
const repository = form.watch("repository");
const giteaId = form.watch("giteaId");
const { data: giteaUrl } = api.gitea.getGiteaUrl.useQuery(
{ giteaId },
{
enabled: !!giteaId,
}
);
console.log(repository);
const {
@ -128,21 +135,25 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
useEffect(() => {
if (data) {
console.log(data.giteaRepository);
form.reset({
branch: data.giteaBranch || "",
repository: {
repo: data.giteaRepository || "",
owner: data.giteaOwner || "",
id: null,
giteaPathNamespace: "",
},
composePath: data.composePath,
giteaId: data.giteaId || "",
watchPaths: data.watchPaths || [],
});
// Find the repository in the repositories list to get the correct ID
const currentRepo = repositories?.find(
(repo) => repo.name === data.giteaRepository && repo.owner.username === data.giteaOwner
);
form.reset({
branch: data.giteaBranch || "",
repository: {
repo: data.giteaRepository || "",
owner: data.giteaOwner || "",
id: currentRepo?.id || null,
giteaPathNamespace: currentRepo?.url || "",
},
composePath: data.composePath,
giteaId: data.giteaId || "",
watchPaths: data.watchPaths || [],
});
}
}, [data, form]);
}, [data, form, repositories]);
const onSubmit = async (data: GiteaProvider) => {
await mutateAsync({
@ -224,7 +235,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
<FormLabel>Repository</FormLabel>
{field.value.owner && field.value.repo && (
<Link
href={`https://gitea.com/${field.value.owner}/${field.value.repo}`}
href={`${giteaUrl}/${field.value.owner}/${field.value.repo}`}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1 text-sm text-muted-foreground hover:text-primary"
@ -463,7 +474,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
) as HTMLInputElement;
const path = input.value.trim();
if (path) {
field.onChange([...field.value, path]);
field.onChange([...(field.value || []), path]);
input.value = "";
}
}}

View File

@ -83,6 +83,7 @@ export const ShowConvertedCompose = ({ composeId }: Props) => {
</Button>
</div>
{compose !== null ? (
<pre>
<CodeEditor
value={compose || ""}
@ -91,6 +92,11 @@ export const ShowConvertedCompose = ({ composeId }: Props) => {
height="50rem"
/>
</pre>
) : (
<div className="py-4 text-center text-muted-foreground">
No compose file available. Make sure at least one domain is configured for this project.
</div>
)}
</DialogContent>
</Dialog>
);

View File

@ -216,4 +216,31 @@ export const giteaRouter = createTRPCRouter({
return { success: true };
}),
getGiteaUrl: protectedProcedure
.input(apiFindOneGitea)
.query(async ({ input, ctx }) => {
const { giteaId } = input;
if (!giteaId) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Gitea provider ID is required.",
});
}
const giteaProvider = await findGiteaById(giteaId);
if (
giteaProvider.gitProvider.organizationId !==
ctx.session.activeOrganizationId
) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not allowed to access this Gitea provider",
});
}
// Return the base URL of the Gitea instance
return giteaProvider.giteaUrl;
}),
});