mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Added watchlist paths for Gitea and some minor typescript fixes.
This commit is contained in:
parent
997e755b6f
commit
56d8defebe
@ -29,16 +29,22 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { api } from "@/utils/api";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { CheckIcon, ChevronsUpDown } from "lucide-react";
|
||||
import { CheckIcon, ChevronsUpDown, HelpCircle, Plus, X } from "lucide-react";
|
||||
import { useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { toast } from "sonner";
|
||||
import { z } from "zod";
|
||||
|
||||
// Define types for repository and branch objects
|
||||
interface GiteaRepository {
|
||||
name: string;
|
||||
url: string;
|
||||
@ -63,6 +69,7 @@ const GiteaProviderSchema = z.object({
|
||||
owner: z.string().min(1, "Owner is required"),
|
||||
giteaPathNamespace: z.string().min(1),
|
||||
id: z.number().nullable(),
|
||||
watchPaths: z.array(z.string()).default([]),
|
||||
})
|
||||
.required(),
|
||||
branch: z.string().min(1, "Branch is required"),
|
||||
@ -90,6 +97,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
repo: "",
|
||||
giteaPathNamespace: "",
|
||||
id: null,
|
||||
watchPaths: [],
|
||||
},
|
||||
giteaId: "",
|
||||
branch: "",
|
||||
@ -138,6 +146,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
owner: data.giteaOwner || "",
|
||||
giteaPathNamespace: data.giteaPathNamespace || "",
|
||||
id: data.giteaProjectId,
|
||||
watchPaths: data.watchPaths || [],
|
||||
},
|
||||
buildPath: data.giteaBuildPath || "/",
|
||||
giteaId: data.giteaId || "",
|
||||
@ -155,6 +164,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
applicationId,
|
||||
giteaProjectId: data.repository.id,
|
||||
giteaPathNamespace: data.repository.giteaPathNamespace,
|
||||
watchPaths: data.repository.watchPaths,
|
||||
})
|
||||
.then(async () => {
|
||||
toast.success("Service Provider Saved");
|
||||
@ -188,6 +198,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
repo: "",
|
||||
id: null,
|
||||
giteaPathNamespace: "",
|
||||
watchPaths: [],
|
||||
});
|
||||
form.setValue("branch", "");
|
||||
}}
|
||||
@ -274,6 +285,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
repo: repo.name,
|
||||
id: repo.id,
|
||||
giteaPathNamespace: repo.name,
|
||||
watchPaths: [],
|
||||
});
|
||||
form.setValue("branch", "");
|
||||
}}
|
||||
@ -399,6 +411,85 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="repository.watchPaths"
|
||||
render={({ field }) => (
|
||||
<FormItem className="md:col-span-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<FormLabel>Watch Paths</FormLabel>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<HelpCircle className="size-4 text-muted-foreground hover:text-foreground transition-colors cursor-pointer" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>
|
||||
Add paths to watch for changes. When files in these
|
||||
paths change, a new deployment will be triggered.
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 mb-2">
|
||||
{field.value && field.value.map((path: string, index: number) => (
|
||||
<Badge
|
||||
key={index}
|
||||
variant="secondary"
|
||||
className="flex items-center gap-1"
|
||||
>
|
||||
{path}
|
||||
<X
|
||||
className="size-3 cursor-pointer hover:text-destructive"
|
||||
onClick={() => {
|
||||
const newPaths = [...field.value];
|
||||
newPaths.splice(index, 1);
|
||||
field.onChange(newPaths);
|
||||
}}
|
||||
/>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="Enter a path to watch (e.g., src/*, dist/*)"
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
const input = e.currentTarget;
|
||||
const path = input.value.trim();
|
||||
if (path) {
|
||||
field.onChange([...field.value, path]);
|
||||
input.value = "";
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => {
|
||||
const input = document.querySelector(
|
||||
'input[placeholder*="Enter a path"]',
|
||||
) as HTMLInputElement;
|
||||
const path = input.value.trim();
|
||||
if (path) {
|
||||
field.onChange([...field.value, path]);
|
||||
input.value = "";
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Plus className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex w-full justify-end">
|
||||
<Button
|
||||
|
@ -8,11 +8,11 @@ import {
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { api } from "@/utils/api";
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
import { Ban, CheckCircle2, RefreshCcw, Rocket, Terminal } from "lucide-react";
|
||||
import { useRouter } from "next/router";
|
||||
import { toast } from "sonner";
|
||||
import { DockerTerminalModal } from "../../settings/web-server/docker-terminal-modal";
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
|
||||
interface Props {
|
||||
composeId: string;
|
||||
|
@ -94,10 +94,11 @@ interface Props {
|
||||
}
|
||||
|
||||
export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
const { data: giteaProviders } = api.gitea.giteaProviders.useQuery<GiteaProviderType[]>();
|
||||
const { data: giteaProviders } = api.gitea.giteaProviders.useQuery();
|
||||
const { data, refetch } = api.compose.one.useQuery({ composeId });
|
||||
|
||||
const { mutateAsync, isLoading: isSavingGiteaProvider } = api.compose.update.useMutation();
|
||||
const { mutateAsync, isLoading: isSavingGiteaProvider } =
|
||||
api.compose.update.useMutation();
|
||||
|
||||
const form = useForm<GiteaProvider>({
|
||||
defaultValues: {
|
||||
@ -118,16 +119,24 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
const repository = form.watch("repository");
|
||||
const giteaId = form.watch("giteaId");
|
||||
|
||||
const { data: repositories, isLoading: isLoadingRepositories, error } = api.gitea.getGiteaRepositories.useQuery<Repository[]>(
|
||||
const {
|
||||
data: repositories,
|
||||
isLoading: isLoadingRepositories,
|
||||
error,
|
||||
} = api.gitea.getGiteaRepositories.useQuery<Repository[]>(
|
||||
{
|
||||
giteaId,
|
||||
},
|
||||
{
|
||||
enabled: !!giteaId,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const { data: branches, fetchStatus, status } = api.gitea.getGiteaBranches.useQuery<Branch[]>(
|
||||
const {
|
||||
data: branches,
|
||||
fetchStatus,
|
||||
status,
|
||||
} = api.gitea.getGiteaBranches.useQuery<Branch[]>(
|
||||
{
|
||||
owner: repository?.owner,
|
||||
repositoryName: repository?.repo,
|
||||
@ -136,7 +145,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
},
|
||||
{
|
||||
enabled: !!repository?.owner && !!repository?.repo && !!giteaId,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@ -154,7 +163,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
watchPaths: data.watchPaths || [],
|
||||
});
|
||||
}
|
||||
}, [form.reset, data, form]);
|
||||
}, [data, form]);
|
||||
|
||||
const onSubmit = async (data: GiteaProvider) => {
|
||||
await mutateAsync({
|
||||
@ -185,6 +194,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
className="grid w-full gap-4 py-3"
|
||||
>
|
||||
{error && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
||||
|
||||
<div className="grid md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
@ -203,7 +213,6 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
});
|
||||
form.setValue("branch", "");
|
||||
}}
|
||||
defaultValue={field.value}
|
||||
value={field.value}
|
||||
>
|
||||
<FormControl>
|
||||
@ -217,7 +226,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
key={giteaProvider.giteaId}
|
||||
value={giteaProvider.giteaId}
|
||||
>
|
||||
{giteaProvider.name}
|
||||
{giteaProvider.gitProvider.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@ -226,6 +235,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="repository"
|
||||
@ -252,38 +262,41 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"w-full justify-between !bg-input",
|
||||
!field.value && "text-muted-foreground"
|
||||
!field.value && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{isLoadingRepositories
|
||||
? "Loading...."
|
||||
: field.value.owner
|
||||
? repositories?.find(
|
||||
(repo: Repository) => repo.name === field.value.repo
|
||||
(repo) => repo.name === field.value.repo,
|
||||
)?.name
|
||||
: "Select repository"}
|
||||
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="p-0" align="start">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search repository..." className="h-9" />
|
||||
<CommandInput
|
||||
placeholder="Search repository..."
|
||||
className="h-9"
|
||||
/>
|
||||
{isLoadingRepositories && (
|
||||
<span className="py-6 text-center text-sm">Loading Repositories....</span>
|
||||
<span className="py-6 text-center text-sm">
|
||||
Loading Repositories....
|
||||
</span>
|
||||
)}
|
||||
<CommandEmpty>No repositories found.</CommandEmpty>
|
||||
<ScrollArea className="h-96">
|
||||
<CommandGroup>
|
||||
{repositories?.map((repo: Repository) => {
|
||||
return (
|
||||
{repositories?.map((repo) => (
|
||||
<CommandItem
|
||||
value={repo.name}
|
||||
key={repo.url}
|
||||
value={repo.name}
|
||||
onSelect={() => {
|
||||
form.setValue("repository", {
|
||||
owner: repo.owner.username as string,
|
||||
owner: repo.owner.username,
|
||||
repo: repo.name,
|
||||
id: repo.id,
|
||||
giteaPathNamespace: repo.url,
|
||||
@ -300,12 +313,13 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"ml-auto h-4 w-4",
|
||||
repo.name === field.value.repo ? "opacity-100" : "opacity-0"
|
||||
repo.name === field.value.repo
|
||||
? "opacity-100"
|
||||
: "opacity-0",
|
||||
)}
|
||||
/>
|
||||
</CommandItem>
|
||||
);
|
||||
})}
|
||||
))}
|
||||
</CommandGroup>
|
||||
</ScrollArea>
|
||||
</Command>
|
||||
@ -319,6 +333,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="branch"
|
||||
@ -332,13 +347,15 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"w-full justify-between !bg-input",
|
||||
!field.value && "text-muted-foreground"
|
||||
!field.value && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{status === "loading" && fetchStatus === "fetching"
|
||||
? "Loading...."
|
||||
: field.value
|
||||
? branches?.find((branch: Branch) => branch.name === field.value)?.name
|
||||
? branches?.find(
|
||||
(branch) => branch.name === field.value,
|
||||
)?.name
|
||||
: "Select branch"}
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
@ -346,15 +363,20 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="p-0" align="start">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search branches..." className="h-9" />
|
||||
<CommandInput
|
||||
placeholder="Search branches..."
|
||||
className="h-9"
|
||||
/>
|
||||
<CommandEmpty>No branches found.</CommandEmpty>
|
||||
<ScrollArea className="h-96">
|
||||
<CommandGroup>
|
||||
{branches?.map((branch: Branch) => (
|
||||
{branches?.map((branch) => (
|
||||
<CommandItem
|
||||
key={branch.name}
|
||||
value={branch.name}
|
||||
onSelect={() => form.setValue("branch", branch.name)}
|
||||
onSelect={() =>
|
||||
form.setValue("branch", branch.name)
|
||||
}
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
{branch.name}
|
||||
@ -362,7 +384,9 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"ml-auto h-4 w-4",
|
||||
branch.name === field.value ? "opacity-100" : "opacity-0"
|
||||
branch.name === field.value
|
||||
? "opacity-100"
|
||||
: "opacity-0",
|
||||
)}
|
||||
/>
|
||||
</CommandItem>
|
||||
@ -380,6 +404,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="composePath"
|
||||
@ -393,6 +418,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="watchPaths"
|
||||
@ -453,7 +479,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
const input = document.querySelector(
|
||||
'input[placeholder="Enter a path to watch (e.g., src/*, dist/*)"]'
|
||||
'input[placeholder="Enter a path to watch (e.g., src/*, dist/*)"]',
|
||||
) as HTMLInputElement;
|
||||
const value = input.value.trim();
|
||||
if (value) {
|
||||
@ -472,6 +498,7 @@ export const SaveGiteaProviderCompose = ({ composeId }: Props) => {
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full"
|
||||
|
@ -1,26 +1,25 @@
|
||||
import {
|
||||
BitbucketIcon,
|
||||
GitIcon,
|
||||
GiteaIcon,
|
||||
GithubIcon,
|
||||
GitlabIcon,
|
||||
GiteaIcon,
|
||||
GitIcon,
|
||||
} from "@/components/icons/data-tools-icons";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { api } from "@/utils/api";
|
||||
import { CodeIcon, GitBranch } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { ComposeFileEditor } from "../compose-file-editor";
|
||||
import { ShowConvertedCompose } from "../show-converted-compose";
|
||||
import { SaveBitbucketProviderCompose } from "./save-bitbucket-provider-compose";
|
||||
import { SaveGitProviderCompose } from "./save-git-provider-compose";
|
||||
import { SaveGiteaProviderCompose } from "./save-gitea-provider-compose";
|
||||
import { SaveGithubProviderCompose } from "./save-github-provider-compose";
|
||||
import { SaveGitlabProviderCompose } from "./save-gitlab-provider-compose";
|
||||
import { SaveGiteaProviderCompose } from "./save-gitea-provider-compose";
|
||||
|
||||
|
||||
type TabState = "github" | "git" | "raw" | "gitlab" | "bitbucket" | "gitea";
|
||||
type TabState = "github" | "git" | "raw" | "gitlab" | "bitbucket" | "gitea"; // Adding gitea to the TabState
|
||||
interface Props {
|
||||
composeId: string;
|
||||
}
|
||||
@ -29,11 +28,40 @@ import { SaveGiteaProviderCompose } from "./save-gitea-provider-compose";
|
||||
const { data: githubProviders } = api.github.githubProviders.useQuery();
|
||||
const { data: gitlabProviders } = api.gitlab.gitlabProviders.useQuery();
|
||||
const { data: bitbucketProviders } = api.bitbucket.bitbucketProviders.useQuery();
|
||||
const { data: giteaProviders } = api.gitea.giteaProviders.useQuery();
|
||||
const { data: giteaProviders } = api.gitea.giteaProviders.useQuery(); // Fetching Gitea providers
|
||||
|
||||
const { data: compose } = api.compose.one.useQuery({ composeId });
|
||||
const [tab, setSab] = useState<TabState>(compose?.sourceType || "github");
|
||||
|
||||
// Ensure we fall back to empty arrays if the data is undefined
|
||||
const safeGithubProviders = githubProviders || [];
|
||||
const safeGitlabProviders = gitlabProviders || [];
|
||||
const safeBitbucketProviders = bitbucketProviders || [];
|
||||
const safeGiteaProviders = giteaProviders || [];
|
||||
|
||||
const renderProviderContent = (providers: any[], providerType: string, ProviderComponent: React.ComponentType<any>) => {
|
||||
if (providers.length > 0) {
|
||||
return <ProviderComponent composeId={composeId} />;
|
||||
} else {
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-3 min-h-[15vh] justify-center">
|
||||
{providerType === "github" && <GithubIcon className="size-8 text-muted-foreground" />}
|
||||
{providerType === "gitlab" && <GitlabIcon className="size-8 text-muted-foreground" />}
|
||||
{providerType === "bitbucket" && <BitbucketIcon className="size-8 text-muted-foreground" />}
|
||||
{providerType === "gitea" && <GiteaIcon className="size-8 text-muted-foreground" />}
|
||||
<span className="text-base text-muted-foreground">
|
||||
To deploy using {providerType.charAt(0).toUpperCase() + providerType.slice(1)}, you need to configure your account first.
|
||||
Please, go to{" "}
|
||||
<Link href="/dashboard/settings/git-providers" className="text-foreground">
|
||||
Settings
|
||||
</Link>{" "}
|
||||
to do so.
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="group relative w-full bg-transparent">
|
||||
<CardHeader>
|
||||
@ -82,11 +110,10 @@ import { SaveGiteaProviderCompose } from "./save-gitea-provider-compose";
|
||||
Bitbucket
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="gitea"
|
||||
value="gitea" // Added Gitea tab
|
||||
className="rounded-none border-b-2 gap-2 border-b-transparent data-[state=active]:border-b-2 data-[state=active]:border-b-border"
|
||||
>
|
||||
<GiteaIcon className="size-4 text-current fill-current" /> {/* Add Gitea Icon */}
|
||||
Gitea
|
||||
<GiteaIcon className="size-4 text-current fill-current" /> Gitea
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="git"
|
||||
@ -104,39 +131,26 @@ import { SaveGiteaProviderCompose } from "./save-gitea-provider-compose";
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</div>
|
||||
|
||||
<TabsContent value="github" className="w-full p-2">
|
||||
{githubProviders && githubProviders?.length > 0 ? (
|
||||
<SaveGithubProviderCompose composeId={composeId} />
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-3 min-h-[15vh] justify-center">
|
||||
<GithubIcon className="size-8 text-muted-foreground" />
|
||||
<span className="text-base text-muted-foreground">
|
||||
To deploy using GitHub, you need to configure your account first. Please, go to{" "}
|
||||
<Link href="/dashboard/settings/git-providers" className="text-foreground">
|
||||
Settings
|
||||
</Link>{" "}
|
||||
to do so.
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{renderProviderContent(safeGithubProviders, "github", SaveGithubProviderCompose)}
|
||||
</TabsContent>
|
||||
<TabsContent value="gitea" className="w-full p-2"> {/* Added Gitea tab */}
|
||||
{giteaProviders && giteaProviders?.length > 0 ? (
|
||||
<SaveGiteaProviderCompose composeId={composeId} />
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-3 min-h-[15vh] justify-center">
|
||||
<GiteaIcon className="size-8 text-muted-foreground" />
|
||||
<span className="text-base text-muted-foreground">
|
||||
To deploy using Gitea, you need to configure your account first. Please, go to{" "}
|
||||
<Link href="/dashboard/settings/git-providers" className="text-foreground">
|
||||
Settings
|
||||
</Link>{" "}
|
||||
to do so.
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<TabsContent value="gitea" className="w-full p-2">
|
||||
{renderProviderContent(safeGiteaProviders, "gitea", SaveGiteaProviderCompose)}
|
||||
</TabsContent>
|
||||
<TabsContent value="gitlab" className="w-full p-2">
|
||||
{renderProviderContent(safeGitlabProviders, "gitlab", SaveGitlabProviderCompose)}
|
||||
</TabsContent>
|
||||
<TabsContent value="bitbucket" className="w-full p-2">
|
||||
{renderProviderContent(safeBitbucketProviders, "bitbucket", SaveBitbucketProviderCompose)}
|
||||
</TabsContent>
|
||||
<TabsContent value="git" className="w-full p-2">
|
||||
<SaveGitProviderCompose composeId={composeId} />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="raw" className="w-full p-2 flex flex-col gap-4">
|
||||
<ComposeFileEditor composeId={composeId} />
|
||||
</TabsContent>
|
||||
{/* Other tabs remain unchanged */}
|
||||
</Tabs>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { AlertBlock } from "@/components/shared/alert-block";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
@ -12,7 +13,6 @@ import { ExternalLink, PlusIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { AddManager } from "./manager/add-manager";
|
||||
import { AddWorker } from "./workers/add-worker";
|
||||
import { AlertBlock } from "@/components/shared/alert-block";
|
||||
|
||||
interface Props {
|
||||
serverId?: string;
|
||||
|
@ -45,7 +45,7 @@ const Schema = z.object({
|
||||
redirectUri: z.string().min(1, {
|
||||
message: "Redirect URI is required",
|
||||
}),
|
||||
organizationName: z.string().optional(), // Added organizationName to the schema
|
||||
organizationName: z.string().optional(),
|
||||
});
|
||||
|
||||
type Schema = z.infer<typeof Schema>;
|
||||
@ -54,8 +54,8 @@ export const AddGiteaProvider = () => {
|
||||
const utils = api.useUtils();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const url = useUrl();
|
||||
const { mutateAsync, error, isError } = api.gitea.create.useMutation(); // Updated API call for Gitea
|
||||
const webhookUrl = `${url}/api/providers/gitea/callback`; // Updated webhook URL for Gitea
|
||||
const { mutateAsync, error, isError } = api.gitea.create.useMutation();
|
||||
const webhookUrl = `${url}/api/providers/gitea/callback`;
|
||||
|
||||
const form = useForm<Schema>({
|
||||
defaultValues: {
|
||||
@ -86,7 +86,7 @@ export const AddGiteaProvider = () => {
|
||||
clientSecret: data.clientSecret || "",
|
||||
name: data.name || "",
|
||||
redirectUri: data.redirectUri || "",
|
||||
giteaUrl: data.giteaUrl || "https://gitea.com", // Use Gitea URL
|
||||
giteaUrl: data.giteaUrl || "https://gitea.com",
|
||||
})
|
||||
.then(async () => {
|
||||
await utils.gitProvider.getAll.invalidate();
|
||||
@ -177,7 +177,7 @@ export const AddGiteaProvider = () => {
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="giteaUrl" // Ensure consistent name for Gitea URL
|
||||
name="giteaUrl"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Gitea URL</FormLabel>
|
||||
@ -240,7 +240,7 @@ export const AddGiteaProvider = () => {
|
||||
/>
|
||||
|
||||
<Button isLoading={form.formState.isSubmitting}>
|
||||
Configure Gitea App {/* Ensured consistency with Gitea */}
|
||||
Configure Gitea App
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
@ -161,7 +161,11 @@ export const ManageTraefikPorts = ({ children, serverId }: Props) => {
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
field.onChange(value === "" ? undefined : Number(value));
|
||||
field.onChange(
|
||||
value === ""
|
||||
? undefined
|
||||
: Number(value),
|
||||
);
|
||||
}}
|
||||
value={field.value || ""}
|
||||
className="w-full dark:bg-black"
|
||||
@ -189,7 +193,11 @@ export const ManageTraefikPorts = ({ children, serverId }: Props) => {
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
field.onChange(value === "" ? undefined : Number(value));
|
||||
field.onChange(
|
||||
value === ""
|
||||
? undefined
|
||||
: Number(value),
|
||||
);
|
||||
}}
|
||||
value={field.value || ""}
|
||||
className="w-full dark:bg-black"
|
||||
|
@ -424,6 +424,7 @@ export const applicationRouter = createTRPCRouter({
|
||||
giteaId: input.giteaId,
|
||||
giteaProjectId: input.giteaProjectId,
|
||||
giteaPathNamespace: input.giteaPathNamespace,
|
||||
watchPaths: input.watchPaths,
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -21,12 +21,11 @@ import {
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
// Gitea Router
|
||||
export const giteaRouter = createTRPCRouter({
|
||||
// Create a new Gitea provider
|
||||
create: protectedProcedure
|
||||
.input(apiCreateGitea)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
.mutation(async ({ input, ctx }: { input: typeof apiCreateGitea._input; ctx: any }) => {
|
||||
try {
|
||||
return await createGitea(input, ctx.session.activeOrganizationId);
|
||||
} catch (error) {
|
||||
@ -41,11 +40,10 @@ export const giteaRouter = createTRPCRouter({
|
||||
// Fetch a specific Gitea provider by ID
|
||||
one: protectedProcedure
|
||||
.input(apiFindOneGitea)
|
||||
.query(async ({ input, ctx }) => {
|
||||
.query(async ({ input, ctx }: { input: typeof apiFindOneGitea._input; ctx: any }) => {
|
||||
const giteaProvider = await findGiteaById(input.giteaId);
|
||||
if (
|
||||
giteaProvider.gitProvider.organizationId !==
|
||||
ctx.session.activeOrganizationId
|
||||
giteaProvider.gitProvider.organizationId !== ctx.session.activeOrganizationId
|
||||
) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
@ -56,7 +54,7 @@ export const giteaRouter = createTRPCRouter({
|
||||
}),
|
||||
|
||||
// Fetch all Gitea providers for the active organization
|
||||
giteaProviders: protectedProcedure.query(async ({ ctx }) => {
|
||||
giteaProviders: protectedProcedure.query(async ({ ctx }: { ctx: any }) => {
|
||||
let result = await db.query.gitea.findMany({
|
||||
with: {
|
||||
gitProvider: true,
|
||||
@ -66,8 +64,7 @@ export const giteaRouter = createTRPCRouter({
|
||||
// Filter by organization ID
|
||||
result = result.filter(
|
||||
(provider) =>
|
||||
provider.gitProvider.organizationId ===
|
||||
ctx.session.activeOrganizationId,
|
||||
provider.gitProvider.organizationId === ctx.session.activeOrganizationId,
|
||||
);
|
||||
|
||||
// Filter providers that meet the requirements
|
||||
@ -88,7 +85,7 @@ export const giteaRouter = createTRPCRouter({
|
||||
// Fetch repositories from Gitea provider
|
||||
getGiteaRepositories: protectedProcedure
|
||||
.input(apiFindOneGitea)
|
||||
.query(async ({ input, ctx }) => {
|
||||
.query(async ({ input, ctx }: { input: typeof apiFindOneGitea._input; ctx: any }) => {
|
||||
const { giteaId } = input;
|
||||
|
||||
if (!giteaId) {
|
||||
@ -100,8 +97,7 @@ export const giteaRouter = createTRPCRouter({
|
||||
|
||||
const giteaProvider = await findGiteaById(giteaId);
|
||||
if (
|
||||
giteaProvider.gitProvider.organizationId !==
|
||||
ctx.session.activeOrganizationId
|
||||
giteaProvider.gitProvider.organizationId !== ctx.session.activeOrganizationId
|
||||
) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
@ -110,8 +106,6 @@ export const giteaRouter = createTRPCRouter({
|
||||
}
|
||||
|
||||
try {
|
||||
// Call the service layer function to get repositories
|
||||
console.log("Calling getGiteaRepositories with giteaId:", giteaId);
|
||||
return await getGiteaRepositories(giteaId);
|
||||
} catch (error) {
|
||||
console.error("Error fetching Gitea repositories:", error);
|
||||
@ -125,21 +119,19 @@ export const giteaRouter = createTRPCRouter({
|
||||
// Fetch branches of a specific Gitea repository
|
||||
getGiteaBranches: protectedProcedure
|
||||
.input(apiFindGiteaBranches)
|
||||
.query(async ({ input, ctx }) => {
|
||||
.query(async ({ input, ctx }: { input: typeof apiFindGiteaBranches._input; ctx: any }) => {
|
||||
const { giteaId, owner, repositoryName } = input;
|
||||
|
||||
if (!giteaId || !owner || !repositoryName) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message:
|
||||
"Gitea provider ID, owner, and repository name are required.",
|
||||
message: "Gitea provider ID, owner, and repository name are required.",
|
||||
});
|
||||
}
|
||||
|
||||
const giteaProvider = await findGiteaById(giteaId);
|
||||
if (
|
||||
giteaProvider.gitProvider.organizationId !==
|
||||
ctx.session.activeOrganizationId
|
||||
giteaProvider.gitProvider.organizationId !== ctx.session.activeOrganizationId
|
||||
) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
@ -148,13 +140,6 @@ export const giteaRouter = createTRPCRouter({
|
||||
}
|
||||
|
||||
try {
|
||||
// Call the service layer function with the required parameters
|
||||
console.log("Calling getGiteaBranches with:", {
|
||||
giteaId,
|
||||
owner,
|
||||
repo: repositoryName,
|
||||
});
|
||||
|
||||
return await getGiteaBranches({
|
||||
giteaId,
|
||||
owner,
|
||||
@ -173,15 +158,13 @@ export const giteaRouter = createTRPCRouter({
|
||||
// Test connection to Gitea provider
|
||||
testConnection: protectedProcedure
|
||||
.input(apiGiteaTestConnection)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
// Ensure giteaId is always a non-empty string
|
||||
.mutation(async ({ input, ctx }: { input: typeof apiGiteaTestConnection._input; ctx: any }) => {
|
||||
const giteaId = input.giteaId ?? "";
|
||||
|
||||
try {
|
||||
const giteaProvider = await findGiteaById(giteaId);
|
||||
if (
|
||||
giteaProvider.gitProvider.organizationId !==
|
||||
ctx.session.activeOrganizationId
|
||||
giteaProvider.gitProvider.organizationId !== ctx.session.activeOrganizationId
|
||||
) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
@ -206,11 +189,10 @@ export const giteaRouter = createTRPCRouter({
|
||||
// Update an existing Gitea provider
|
||||
update: protectedProcedure
|
||||
.input(apiUpdateGitea)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
.mutation(async ({ input, ctx }: { input: typeof apiUpdateGitea._input; ctx: any }) => {
|
||||
const giteaProvider = await findGiteaById(input.giteaId);
|
||||
if (
|
||||
giteaProvider.gitProvider.organizationId !==
|
||||
ctx.session.activeOrganizationId
|
||||
giteaProvider.gitProvider.organizationId !== ctx.session.activeOrganizationId
|
||||
) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
@ -237,4 +219,4 @@ export const giteaRouter = createTRPCRouter({
|
||||
|
||||
return { success: true };
|
||||
}),
|
||||
});
|
||||
});
|
@ -511,6 +511,7 @@ export const apiSaveGiteaProvider = createSchema
|
||||
giteaId: true,
|
||||
giteaProjectId: true,
|
||||
giteaPathNamespace: true,
|
||||
watchPaths: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
|
@ -23,7 +23,7 @@ export const createGitea = async (
|
||||
name: input.name,
|
||||
})
|
||||
.returning()
|
||||
.then((response: typeof gitProvider.$inferSelect[]) => response[0]);
|
||||
.then((response: (typeof gitProvider.$inferSelect)[]) => response[0]);
|
||||
|
||||
if (!newGitProvider) {
|
||||
throw new TRPCError({
|
||||
@ -39,7 +39,7 @@ export const createGitea = async (
|
||||
gitProviderId: newGitProvider?.gitProviderId,
|
||||
})
|
||||
.returning()
|
||||
.then((response: typeof gitea.$inferSelect[]) => response[0]);
|
||||
.then((response: (typeof gitea.$inferSelect)[]) => response[0]);
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user