Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(web): gitlab integration settings and workflow ui

zaralX059b4eb8204e
diff --git a/apps/web/src/components/icons/gitlab-icon.tsx b/apps/web/src/components/icons/gitlab-icon.tsx
new file mode 100644
index 000000000..2faa337ac
--- /dev/null
+++ b/apps/web/src/components/icons/gitlab-icon.tsx
@@ -0,0 +1,16 @@
+import type { SVGProps } from "react";
+
+// lucide-react dropped its brand icons in v1, so the GitLab tanuki lives here.
+export function GitlabIcon(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ viewBox="0 0 24 24"
+ fill="currentColor"
+ aria-hidden="true"
+ focusable="false"
+ {...props}
+ >
+ <path d="m23.6 9.593-.033-.086L20.32 1.13a.85.85 0 0 1 .001-.002.85.85 0 0 0-1.616.086l-2.19 6.7H7.485l-2.19-6.7A.85.85 0 0 0 3.68 1.13L.433 9.507.4 9.593a5.96 5.96 0 0 0 1.977 6.886l.01.01.03.021 4.882 3.657 2.416 1.828 1.47 1.11a1 1 0 0 0 1.21 0l1.47-1.11 2.416-1.828 4.912-3.68.012-.01A5.96 5.96 0 0 0 23.6 9.593" />
+ </svg>
+ );
+}
diff --git a/apps/web/src/components/project/gitlab-integration-settings.tsx b/apps/web/src/components/project/gitlab-integration-settings.tsx
new file mode 100644
index 000000000..83403ab77
--- /dev/null
+++ b/apps/web/src/components/project/gitlab-integration-settings.tsx
@@ -0,0 +1,908 @@
+import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
+import {
+ AlertTriangle,
+ CheckCircle,
+ ExternalLink,
+ GitBranch,
+ Import,
+ Link,
+ RefreshCw,
+ Unlink,
+ XCircle,
+} from "lucide-react";
+import React from "react";
+import { useForm } from "react-hook-form";
+import { useTranslation } from "react-i18next";
+import { z } from "zod/v4";
+import { GitlabProjectBrowserModal } from "@/components/project/gitlab-project-browser-modal";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/components/ui/form";
+import { Input } from "@/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { Separator } from "@/components/ui/separator";
+import { Switch } from "@/components/ui/switch";
+import type { VerifyGitlabAccessResponse } from "@/fetchers/gitlab-integration/verify-gitlab-access";
+import {
+ useCreateGitlabIntegration,
+ useDeleteGitlabIntegration,
+ useVerifyGitlabAccess,
+} from "@/hooks/mutations/gitlab-integration/use-create-gitlab-integration";
+import useImportGitlabIssues from "@/hooks/mutations/gitlab-integration/use-import-gitlab-issues";
+import { useUpdateGitlabIntegration } from "@/hooks/mutations/gitlab-integration/use-update-gitlab-integration";
+import useGetGitlabIntegration from "@/hooks/queries/gitlab-integration/use-get-gitlab-integration";
+import { cn } from "@/lib/cn";
+import { toast } from "@/lib/toast";
+
+const GITLAB_CLOUD_URL = "https://gitlab.com";
+
+type GitlabTokenType = "private" | "bearer";
+
+type GitlabIntegrationFormValues = {
+ baseUrl: string;
+ accessToken: string;
+ tokenType: GitlabTokenType;
+ projectPath: string;
+};
+
+type GitlabVerificationSnapshot = {
+ baseUrl: string;
+ accessToken: string;
+ tokenType: GitlabTokenType;
+ projectPath: string;
+};
+
+type GitlabVerificationState = {
+ result: VerifyGitlabAccessResponse;
+ verified: GitlabVerificationSnapshot;
+};
+
+function createVerificationSnapshot(
+ values: GitlabIntegrationFormValues,
+): GitlabVerificationSnapshot {
+ return {
+ baseUrl: values.baseUrl.trim(),
+ accessToken: values.accessToken.trim(),
+ tokenType: values.tokenType,
+ projectPath: values.projectPath.trim().replace(/^\/+|\/+$/g, ""),
+ };
+}
+
+function snapshotsMatch(
+ a: GitlabVerificationSnapshot,
+ b: GitlabVerificationSnapshot,
+): boolean {
+ return (
+ a.baseUrl === b.baseUrl &&
+ a.accessToken === b.accessToken &&
+ a.tokenType === b.tokenType &&
+ a.projectPath === b.projectPath
+ );
+}
+
+export function GitlabIntegrationSettings({
+ projectId,
+}: {
+ projectId: string;
+}) {
+ const { t } = useTranslation();
+
+ const gitlabIntegrationSchema = React.useMemo(
+ () =>
+ z.object({
+ baseUrl: z
+ .string()
+ .min(1, t("settings:gitlabIntegration.validation.baseUrlRequired"))
+ .refine((s) => {
+ try {
+ new URL(s);
+ return true;
+ } catch {
+ return false;
+ }
+ }, t("settings:gitlabIntegration.validation.baseUrlInvalid")),
+ accessToken: z.string(),
+ tokenType: z.enum(["private", "bearer"]),
+ projectPath: z
+ .string()
+ .min(1, t("settings:gitlabIntegration.validation.pathRequired"))
+ .refine(
+ (s) => /^[a-zA-Z0-9._-]+(?:\/[a-zA-Z0-9._-]+)+$/.test(s.trim()),
+ t("settings:gitlabIntegration.validation.pathInvalid"),
+ ),
+ }),
+ [t],
+ );
+
+ const {
+ data: integration,
+ isLoading,
+ error: integrationError,
+ refetch: refetchIntegration,
+ } = useGetGitlabIntegration(projectId);
+ const { mutateAsync: createIntegration, isPending: isCreating } =
+ useCreateGitlabIntegration();
+ const { mutateAsync: deleteIntegration, isPending: isDeleting } =
+ useDeleteGitlabIntegration();
+ const { mutateAsync: verifyAccess, isPending: isVerifying } =
+ useVerifyGitlabAccess();
+ const { mutateAsync: importIssues, isPending: isImporting } =
+ useImportGitlabIssues();
+ const { mutateAsync: updateGitlabSettings, isPending: isUpdatingSettings } =
+ useUpdateGitlabIntegration();
+
+ const [verificationResult, setVerificationResult] =
+ React.useState<GitlabVerificationState | null>(null);
+ const [showProjectBrowser, setShowProjectBrowser] = React.useState(false);
+ const [showWebhookSecret, setShowWebhookSecret] = React.useState(false);
+
+ const form = useForm<GitlabIntegrationFormValues>({
+ resolver: standardSchemaResolver(gitlabIntegrationSchema),
+ defaultValues: {
+ baseUrl: GITLAB_CLOUD_URL,
+ accessToken: "",
+ tokenType: "private",
+ projectPath: "",
+ },
+ });
+
+ const resetIntegrationForm = React.useCallback(() => {
+ if (!integration?.baseUrl) {
+ return;
+ }
+
+ form.reset({
+ baseUrl: integration.baseUrl,
+ accessToken: "",
+ tokenType: integration.tokenType,
+ projectPath: integration.projectPath,
+ });
+ // Clear verify state when the form reloads so import cannot run against
+ // stale credentials.
+ setVerificationResult(null);
+ setShowWebhookSecret(false);
+ }, [
+ form.reset,
+ integration?.baseUrl,
+ integration?.projectPath,
+ integration?.tokenType,
+ ]);
+
+ React.useEffect(() => {
+ resetIntegrationForm();
+ }, [resetIntegrationForm]);
+
+ const runVerify = React.useCallback(
+ async (data: GitlabIntegrationFormValues, showToast = true) => {
+ const token = data.accessToken.trim();
+ if (!token && integration) {
+ return;
+ }
+ if (!token && !integration) {
+ if (showToast) {
+ toast.error(
+ t("settings:gitlabIntegration.toast.tokenRequiredVerify"),
+ );
+ }
+ setVerificationResult(null);
+ return;
+ }
+ try {
+ const snapshot = createVerificationSnapshot(data);
+ const result = await verifyAccess({
+ projectId,
+ baseUrl: snapshot.baseUrl,
+ accessToken: snapshot.accessToken,
+ tokenType: snapshot.tokenType,
+ projectPath: snapshot.projectPath,
+ });
+ setVerificationResult({
+ result,
+ verified: snapshot,
+ });
+ if (showToast) {
+ if (result.isInstalled && result.hasRequiredPermissions) {
+ toast.success(t("settings:gitlabIntegration.toast.verifyOk"));
+ } else if (result.failureReason === "redirected") {
+ toast.error(t("settings:gitlabIntegration.toast.redirected"));
+ } else if (result.failureReason === "not_a_gitlab_instance") {
+ toast.error(
+ t("settings:gitlabIntegration.toast.notGitlabInstance"),
+ );
+ } else if (result.failureReason === "project_not_found") {
+ toast.error(t("settings:gitlabIntegration.toast.projectNotFound"));
+ } else {
+ toast.warning(t("settings:gitlabIntegration.toast.verifyWarning"));
+ }
+ }
+ } catch (error) {
+ if (showToast) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : t("settings:gitlabIntegration.toast.verifyError"),
+ );
+ }
+ setVerificationResult(null);
+ }
+ },
+ [verifyAccess, integration, projectId, t],
+ );
+
+ const baseUrl = form.watch("baseUrl");
+ const accessToken = form.watch("accessToken");
+ const tokenType = form.watch("tokenType");
+ const projectPath = form.watch("projectPath");
+ const currentVerificationSnapshot = React.useMemo(
+ () =>
+ createVerificationSnapshot({
+ baseUrl,
+ accessToken,
+ tokenType,
+ projectPath,
+ }),
+ [baseUrl, accessToken, tokenType, projectPath],
+ );
+
+ React.useEffect(() => {
+ setVerificationResult((current) => {
+ if (!current) {
+ return current;
+ }
+ return snapshotsMatch(current.verified, currentVerificationSnapshot)
+ ? current
+ : null;
+ });
+ }, [currentVerificationSnapshot]);
+
+ React.useEffect(() => {
+ if (!baseUrl || !projectPath || !form.formState.isValid) {
+ return;
+ }
+ if (!accessToken.trim()) {
+ return;
+ }
+ const timeoutId = window.setTimeout(() => {
+ runVerify({ baseUrl, accessToken, tokenType, projectPath }, false);
+ }, 400);
+
+ return () => {
+ window.clearTimeout(timeoutId);
+ };
+ }, [
+ baseUrl,
+ projectPath,
+ accessToken,
+ tokenType,
+ form.formState.isValid,
+ runVerify,
+ ]);
+
+ const onSubmit = async (data: GitlabIntegrationFormValues) => {
+ try {
+ if (!data.accessToken.trim() && !integration) {
+ toast.error(t("settings:gitlabIntegration.toast.tokenRequired"));
+ return;
+ }
+
+ const snapshot = createVerificationSnapshot(data);
+ const hasMatchingVerification =
+ verificationResult?.result.isInstalled &&
+ verificationResult.result.hasRequiredPermissions &&
+ snapshotsMatch(verificationResult.verified, snapshot);
+
+ if (data.accessToken.trim() && !hasMatchingVerification) {
+ const verification = await verifyAccess({
+ projectId,
+ baseUrl: snapshot.baseUrl,
+ accessToken: snapshot.accessToken,
+ tokenType: snapshot.tokenType,
+ projectPath: snapshot.projectPath,
+ });
+
+ if (!verification.isInstalled || !verification.hasRequiredPermissions) {
+ toast.error(t("settings:gitlabIntegration.toast.verifyFirst"));
+ return;
+ }
+ }
+
+ await createIntegration({
+ projectId,
+ data: {
+ baseUrl: snapshot.baseUrl,
+ ...(snapshot.accessToken
+ ? { accessToken: snapshot.accessToken }
+ : {}),
+ tokenType: snapshot.tokenType,
+ projectPath: snapshot.projectPath,
+ },
+ });
+ form.setValue("accessToken", "");
+ toast.success(t("settings:gitlabIntegration.toast.updated"));
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : t("settings:gitlabIntegration.toast.updateError"),
+ );
+ }
+ };
+
+ const handleDelete = async () => {
+ try {
+ await deleteIntegration(projectId);
+ form.reset({
+ baseUrl: GITLAB_CLOUD_URL,
+ accessToken: "",
+ tokenType: "private",
+ projectPath: "",
+ });
+ setVerificationResult(null);
+ toast.success(t("settings:gitlabIntegration.toast.removed"));
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : t("settings:gitlabIntegration.toast.removeError"),
+ );
+ }
+ };
+
+ const handleImportIssues = async () => {
+ try {
+ await importIssues(projectId);
+ toast.success(t("settings:gitlabIntegration.toast.issuesImported"));
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : t("settings:gitlabIntegration.toast.importError"),
+ );
+ }
+ };
+
+ const handleProjectSelect = (selectedPath: string) => {
+ form.setValue("projectPath", selectedPath, {
+ shouldValidate: true,
+ shouldDirty: true,
+ shouldTouch: true,
+ });
+ setShowProjectBrowser(false);
+ setVerificationResult(null);
+ };
+
+ const handleCopyWebhookSecret = React.useCallback(async () => {
+ if (!integration?.webhookSecret) {
+ return;
+ }
+
+ try {
+ await navigator.clipboard.writeText(integration.webhookSecret);
+ toast.success(t("settings:gitlabIntegration.toast.secretCopied"));
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : t("settings:gitlabIntegration.toast.unableToCopySecret"),
+ );
+ }
+ }, [integration?.webhookSecret, t]);
+
+ if (isLoading) {
+ return (
+ <div className="space-y-4">
+ <div className="h-10 bg-muted rounded animate-pulse w-full" />
+ </div>
+ );
+ }
+
+ if (integrationError) {
+ return (
+ <div className="space-y-4 border border-destructive/25 rounded-md p-4 bg-sidebar">
+ <div className="flex items-start justify-between gap-4">
+ <div className="space-y-1">
+ <p className="text-sm font-medium text-destructive">
+ {t("common:error.title")}
+ </p>
+ <p className="text-sm text-muted-foreground">
+ {integrationError instanceof Error
+ ? integrationError.message
+ : t("settings:gitlabIntegration.toast.updateError")}
+ </p>
+ </div>
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => refetchIntegration()}
+ >
+ {t("settings:gitlabIntegration.retry")}
+ </Button>
+ </div>
+ </div>
+ );
+ }
+
+ const isConnected = !!integration && integration.isActive;
+ // Import stays disabled until the user verifies again after changing
+ // connection details, so it cannot run with an unverified token.
+ const hasVerifiedCurrentValues =
+ verificationResult?.result.isInstalled &&
+ verificationResult.result.hasRequiredPermissions &&
+ snapshotsMatch(verificationResult.verified, currentVerificationSnapshot);
+ const canImport = isConnected && Boolean(hasVerifiedCurrentValues);
+
+ const gitlabProjectUrl = integration?.baseUrl
+ ? `${integration.baseUrl.replace(/\/$/, "")}/${integration.projectPath}`
+ : null;
+
+ return (
+ <div className="space-y-4">
+ <div className="space-y-4 border border-border rounded-md p-4 bg-sidebar">
+ <div className="flex items-center justify-between">
+ <div className="space-y-0.5">
+ <p className="text-sm font-medium">
+ {t("settings:gitlabIntegration.connectionStatus")}
+ </p>
+ {isConnected ? (
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.connectedActive")}
+ </p>
+ ) : (
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.notConnectedHint")}
+ </p>
+ )}
+ </div>
+ {isConnected ? (
+ <Badge variant="secondary" className="gap-1">
+ <CheckCircle className="w-3 h-3" />
+ {t("settings:gitlabIntegration.badgeConnected")}
+ </Badge>
+ ) : (
+ <Badge variant="outline" className="gap-1">
+ <XCircle className="w-3 h-3" />
+ {t("settings:gitlabIntegration.badgeNotConnected")}
+ </Badge>
+ )}
+ </div>
+
+ {isConnected && integration && (
+ <>
+ <Separator />
+ <div className="flex items-center justify-between">
+ <div className="space-y-0.5">
+ <p className="text-sm font-medium">
+ {t("settings:gitlabIntegration.project")}
+ </p>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.projectHint")}
+ </p>
+ </div>
+ <div className="flex items-center gap-2 text-sm">
+ <span className="font-medium">{integration.projectPath}</span>
+ {gitlabProjectUrl && (
+ <a
+ href={gitlabProjectUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ aria-label={t("settings:gitlabIntegration.openInGitlab", {
+ project: integration.projectPath,
+ })}
+ className="text-primary hover:text-primary/80 transition-colors"
+ >
+ <ExternalLink className="w-3 h-3" />
+ </a>
+ )}
+ </div>
+ </div>
+
+ <Separator />
+ <div className="flex items-center justify-between gap-4">
+ <div className="min-w-0 flex-1 space-y-0.5">
+ <p className="text-sm font-medium">
+ {t("settings:gitlabIntegration.commentTaskLinkTitle")}
+ </p>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.commentTaskLinkHint")}
+ </p>
+ </div>
+ <Switch
+ checked={integration.commentTaskLinkOnGitlabIssue ?? true}
+ onCheckedChange={async (checked) => {
+ try {
+ await updateGitlabSettings({
+ projectId,
+ json: { commentTaskLinkOnGitlabIssue: checked },
+ });
+ toast.success(
+ checked
+ ? t("settings:gitlabIntegration.toast.commentOnEnabled")
+ : t(
+ "settings:gitlabIntegration.toast.commentOnDisabled",
+ ),
+ );
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : t(
+ "settings:gitlabIntegration.toast.settingsUpdateError",
+ ),
+ );
+ }
+ }}
+ disabled={isUpdatingSettings}
+ />
+ </div>
+
+ {integration.webhookUrl && (
+ <>
+ <Separator />
+ <div className="space-y-2 text-xs">
+ <p className="font-medium text-sm">
+ {t("settings:gitlabIntegration.webhookTitle")}
+ </p>
+ <p className="text-muted-foreground">
+ {t("settings:gitlabIntegration.webhookHint")}
+ </p>
+ <code className="block break-all rounded bg-muted px-2 py-1 text-[11px]">
+ {integration.webhookUrl}
+ </code>
+ <p className="text-muted-foreground mt-2">
+ {t("settings:gitlabIntegration.webhookSecretLabel")}
+ </p>
+ <div className="flex items-start gap-2">
+ <code className="block flex-1 break-all rounded bg-muted px-2 py-1 text-[11px]">
+ {showWebhookSecret
+ ? integration.webhookSecret
+ : "••••••••••••••••••••••••••••••••"}
+ </code>
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() =>
+ setShowWebhookSecret((current) => !current)
+ }
+ >
+ {showWebhookSecret
+ ? t("settings:gitlabIntegration.webhookHide")
+ : t("settings:gitlabIntegration.webhookShow")}
+ </Button>
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={handleCopyWebhookSecret}
+ >
+ {t("settings:gitlabIntegration.webhookCopy")}
+ </Button>
+ </div>
+ </div>
+ </>
+ )}
+ </>
+ )}
+ </div>
+
+ <div className="space-y-4 border border-border rounded-md p-4 bg-sidebar">
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
+ <FormField
+ control={form.control}
+ name="baseUrl"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center justify-between gap-4">
+ <div className="space-y-0.5">
+ <FormLabel className="text-sm font-medium">
+ {t("settings:gitlabIntegration.baseUrlLabel")}
+ </FormLabel>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.baseUrlHint")}
+ </p>
+ </div>
+ <FormControl>
+ <Input
+ className="w-72"
+ placeholder={GITLAB_CLOUD_URL}
+ {...field}
+ disabled={isCreating || isDeleting}
+ />
+ </FormControl>
+ </div>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <Separator />
+
+ <FormField
+ control={form.control}
+ name="tokenType"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center justify-between gap-4">
+ <div className="space-y-0.5">
+ <FormLabel className="text-sm font-medium">
+ {t("settings:gitlabIntegration.tokenTypeLabel")}
+ </FormLabel>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.tokenTypeHint")}
+ </p>
+ </div>
+ <Select
+ value={field.value}
+ onValueChange={(value) =>
+ field.onChange(value as GitlabTokenType)
+ }
+ >
+ <SelectTrigger className="w-72">
+ <SelectValue>
+ {field.value === "bearer"
+ ? t("settings:gitlabIntegration.tokenTypeBearer")
+ : t("settings:gitlabIntegration.tokenTypePrivate")}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="private">
+ {t("settings:gitlabIntegration.tokenTypePrivate")}
+ </SelectItem>
+ <SelectItem value="bearer">
+ {t("settings:gitlabIntegration.tokenTypeBearer")}
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ </div>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <Separator />
+
+ <FormField
+ control={form.control}
+ name="accessToken"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center justify-between gap-4">
+ <div className="space-y-0.5">
+ <FormLabel className="text-sm font-medium">
+ {t("settings:gitlabIntegration.tokenLabel")}
+ </FormLabel>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.tokenHint")}
+ {integration?.maskedAccessToken
+ ? ` (${t("settings:gitlabIntegration.currentToken")}: ${integration.maskedAccessToken})`
+ : null}
+ </p>
+ </div>
+ <FormControl>
+ <Input
+ className="w-72"
+ type="password"
+ autoComplete="off"
+ placeholder={
+ integration
+ ? t(
+ "settings:gitlabIntegration.tokenPlaceholderUpdate",
+ )
+ : t("settings:gitlabIntegration.tokenPlaceholder")
+ }
+ {...field}
+ disabled={isCreating || isDeleting}
+ />
+ </FormControl>
+ </div>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <Separator />
+
+ <FormField
+ control={form.control}
+ name="projectPath"
+ render={({ field }) => (
+ <FormItem>
+ <div className="flex items-center justify-between gap-4">
+ <div className="space-y-0.5">
+ <FormLabel className="text-sm font-medium">
+ {t("settings:gitlabIntegration.projectPathLabel")}
+ </FormLabel>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.projectPathHint")}
+ </p>
+ </div>
+ <FormControl>
+ <Input
+ className="w-72"
+ placeholder="group/subgroup/project"
+ {...field}
+ disabled={isCreating || isDeleting}
+ />
+ </FormControl>
+ </div>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <Separator />
+
+ <div className="flex items-center justify-between">
+ <div className="space-y-0.5">
+ <p className="text-sm font-medium">
+ {t("settings:gitlabIntegration.actionsTitle")}
+ </p>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.actionsHint")}
+ </p>
+ </div>
+ <div className="flex flex-wrap gap-2">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => setShowProjectBrowser(true)}
+ className="gap-2"
+ disabled={!baseUrl || !accessToken.trim()}
+ >
+ <GitBranch className="size-3" />
+ {t("settings:gitlabIntegration.browse")}
+ </Button>
+
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => runVerify(form.getValues())}
+ disabled={
+ isVerifying ||
+ !form.formState.isValid ||
+ (!accessToken.trim() && !integration)
+ }
+ className="gap-2"
+ >
+ <RefreshCw
+ className={cn("size-3", isVerifying && "animate-spin")}
+ />
+ {t("settings:gitlabIntegration.verify")}
+ </Button>
+
+ <Button
+ type="submit"
+ size="sm"
+ disabled={
+ isCreating ||
+ isDeleting ||
+ !form.formState.isValid ||
+ (verificationResult ? !hasVerifiedCurrentValues : false)
+ }
+ className="gap-2"
+ >
+ <Link className="size-3" />
+ {isConnected
+ ? t("settings:gitlabIntegration.update")
+ : t("settings:gitlabIntegration.connect")}
+ </Button>
+
+ {isConnected && (
+ <Button
+ type="button"
+ variant="destructive"
+ size="sm"
+ onClick={handleDelete}
+ disabled={isCreating || isDeleting}
+ className="gap-2"
+ >
+ <Unlink className="size-3" />
+ {t("settings:gitlabIntegration.disconnect")}
+ </Button>
+ )}
+ </div>
+ </div>
+ </form>
+ </Form>
+
+ {verificationResult && (
+ <>
+ <Separator />
+ <div
+ className={cn(
+ "flex items-start gap-3 p-3 border rounded-md text-sm",
+ verificationResult.result.isInstalled &&
+ verificationResult.result.hasRequiredPermissions
+ ? "border-success/25 bg-success/10"
+ : verificationResult.result.failureReason
+ ? "border-destructive/25 bg-destructive/10"
+ : "border-warning/25 bg-warning/10",
+ )}
+ >
+ {verificationResult.result.isInstalled &&
+ verificationResult.result.hasRequiredPermissions ? (
+ <CheckCircle className="mt-0.5 h-4 w-4 flex-shrink-0 text-success-foreground" />
+ ) : verificationResult.result.failureReason ? (
+ <XCircle className="mt-0.5 h-4 w-4 flex-shrink-0 text-destructive-foreground" />
+ ) : (
+ <AlertTriangle className="mt-0.5 h-4 w-4 flex-shrink-0 text-warning-foreground" />
+ )}
+ <div className="flex-1">
+ <p className="font-medium">
+ {verificationResult.result.message}
+ </p>
+ </div>
+ </div>
+ </>
+ )}
+ </div>
+
+ {isConnected && (
+ <div className="space-y-4 border border-border rounded-md p-4 bg-sidebar">
+ <div className="flex items-center justify-between">
+ <div className="space-y-0.5">
+ <p className="text-sm font-medium">
+ {t("settings:gitlabIntegration.importSectionTitle")}
+ </p>
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.importSectionHint")}
+ </p>
+ </div>
+ <Button
+ onClick={handleImportIssues}
+ disabled={isImporting || !canImport}
+ className="gap-2"
+ size="sm"
+ variant="outline"
+ >
+ {isImporting ? (
+ <RefreshCw className="size-3 animate-spin" />
+ ) : (
+ <Import className="size-3" />
+ )}
+ {isImporting
+ ? t("settings:gitlabIntegration.importing")
+ : t("settings:gitlabIntegration.importIssues")}
+ </Button>
+ </div>
+ {!canImport && (
+ <>
+ <Separator />
+ <p className="text-xs text-muted-foreground">
+ {t("settings:gitlabIntegration.importDisabledHint")}
+ </p>
+ </>
+ )}
+ </div>
+ )}
+
+ <GitlabProjectBrowserModal
+ open={showProjectBrowser}
+ projectId={projectId}
+ onOpenChange={setShowProjectBrowser}
+ onSelectProject={handleProjectSelect}
+ selectedProjectPath={projectPath || undefined}
+ baseUrl={baseUrl}
+ accessToken={accessToken}
+ tokenType={tokenType}
+ />
+ </div>
+ );
+}
diff --git a/apps/web/src/components/project/gitlab-project-browser-modal.tsx b/apps/web/src/components/project/gitlab-project-browser-modal.tsx
new file mode 100644
index 000000000..9f2d1a92a
--- /dev/null
+++ b/apps/web/src/components/project/gitlab-project-browser-modal.tsx
@@ -0,0 +1,180 @@
+import { useQuery } from "@tanstack/react-query";
+import { ExternalLink, GitBranch, Lock, Search } from "lucide-react";
+import React from "react";
+import { useTranslation } from "react-i18next";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import { Input } from "@/components/ui/input";
+import listGitlabProjects, {
+ type ListGitlabProjectsResponse,
+} from "@/fetchers/gitlab-integration/list-gitlab-projects";
+import { cn } from "@/lib/cn";
+
+type GitlabProjectBrowserModalProps = {
+ open: boolean;
+ projectId: string;
+ onOpenChange: (open: boolean) => void;
+ onSelectProject: (projectPath: string) => void;
+ selectedProjectPath?: string;
+ baseUrl: string;
+ accessToken: string;
+ tokenType: "private" | "bearer";
+};
+
+export function GitlabProjectBrowserModal({
+ open,
+ projectId,
+ onOpenChange,
+ onSelectProject,
+ selectedProjectPath,
+ baseUrl,
+ accessToken,
+ tokenType,
+}: GitlabProjectBrowserModalProps) {
+ const { t } = useTranslation();
+ const [searchTerm, setSearchTerm] = React.useState("");
+
+ const canFetch =
+ open && baseUrl.trim().length > 0 && accessToken.trim().length > 0;
+
+ const { data, isLoading, error, refetch } = useQuery({
+ queryKey: ["gitlab-projects", projectId, baseUrl, tokenType],
+ queryFn: () =>
+ listGitlabProjects({ projectId, baseUrl, accessToken, tokenType }),
+ enabled: canFetch,
+ // The token is part of the request but deliberately not part of the key, so
+ // the result is dropped when the modal closes rather than being replayed for
+ // whatever token is in the form the next time it opens.
+ gcTime: 0,
+ });
+
+ const filteredProjects = React.useMemo(() => {
+ if (!data?.projects) return [];
+
+ if (!searchTerm) return data.projects;
+
+ const search = searchTerm.toLowerCase();
+ return data.projects.filter((project) =>
+ project.path_with_namespace.toLowerCase().includes(search),
+ );
+ }, [data?.projects, searchTerm]);
+
+ const handleSelectProject = (
+ project: ListGitlabProjectsResponse["projects"][number],
+ ) => {
+ onSelectProject(project.path_with_namespace);
+ resetAndCloseModal(false);
+ };
+
+ const resetAndCloseModal = (next: boolean) => {
+ if (!next) {
+ setSearchTerm("");
+ }
+ onOpenChange(next);
+ };
+
+ return (
+ <Dialog open={open} onOpenChange={resetAndCloseModal}>
+ <DialogContent className="!max-w-2xl max-h-[85vh] p-0 gap-0 flex flex-col">
+ <DialogHeader className="px-6 pt-6 pb-4">
+ <DialogTitle className="flex items-center gap-2">
+ <GitBranch className="size-5" />
+ {t("settings:gitlabIntegration.browseModalTitle")}
+ </DialogTitle>
+ <DialogDescription>
+ {t("settings:gitlabIntegration.browseModalHint")}
+ </DialogDescription>
+ </DialogHeader>
+
+ <div className="px-6 pb-4">
+ <div className="relative">
+ <Search className="absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" />
+ <Input
+ className="pl-9"
+ placeholder={t("settings:gitlabIntegration.searchProjects")}
+ value={searchTerm}
+ onChange={(e) => setSearchTerm(e.target.value)}
+ />
+ </div>
+ </div>
+
+ <div className="flex-1 overflow-y-auto border-t border-border px-6 py-2">
+ {!canFetch && (
+ <p className="text-sm text-muted-foreground py-8 text-center">
+ {t("settings:gitlabIntegration.browseNeedsCredentials")}
+ </p>
+ )}
+ {canFetch && isLoading && (
+ <p className="text-sm text-muted-foreground py-8 text-center">
+ {t("settings:gitlabIntegration.loadingProjects")}
+ </p>
+ )}
+ {canFetch && error && (
+ <div className="py-6 text-center space-y-2">
+ <p className="text-sm text-destructive">
+ {error instanceof Error ? error.message : "Error"}
+ </p>
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => refetch()}
+ >
+ {t("settings:gitlabIntegration.retry")}
+ </Button>
+ </div>
+ )}
+ {canFetch && data && (
+ <ul className="space-y-1">
+ {filteredProjects.map((project) => (
+ <li key={project.id}>
+ <div className="flex items-center gap-2">
+ <button
+ type="button"
+ onClick={() => handleSelectProject(project)}
+ className={cn(
+ "flex-1 flex items-center justify-between gap-3 rounded-md px-3 py-2 text-left text-sm hover:bg-muted/80 transition-colors",
+ selectedProjectPath === project.path_with_namespace &&
+ "bg-muted",
+ )}
+ >
+ <span className="font-medium truncate">
+ {project.path_with_namespace}
+ </span>
+ <div className="flex items-center gap-2 shrink-0">
+ {project.visibility !== "public" ? (
+ <Lock className="size-3.5 text-muted-foreground" />
+ ) : null}
+ <Badge variant="secondary" className="text-xs">
+ {project.visibility}
+ </Badge>
+ </div>
+ </button>
+ <a
+ href={project.web_url}
+ target="_blank"
+ rel="noopener noreferrer"
+ aria-label={t("settings:gitlabIntegration.openInGitlab", {
+ project: project.path_with_namespace,
+ })}
+ className="rounded-md p-2 text-primary hover:bg-muted/80 transition-colors"
+ >
+ <ExternalLink className="size-3.5" />
+ </a>
+ </div>
+ </li>
+ ))}
+ </ul>
+ )}
+ </div>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/apps/web/src/components/project/workflow-editor.tsx b/apps/web/src/components/project/workflow-editor.tsx
index 002bddc83..da126ae29 100644
--- a/apps/web/src/components/project/workflow-editor.tsx
+++ b/apps/web/src/components/project/workflow-editor.tsx
@@ -47,9 +47,9 @@ export default function WorkflowEditor({ projectId }: WorkflowEditorProps) {
}
const renderRuleSection = (
- integrationType: "github" | "gitea",
- headingKey: "githubHeading" | "giteaHeading",
- hintKey: "githubHint" | "giteaHint",
+ integrationType: "github" | "gitea" | "gitlab",
+ headingKey: "githubHeading" | "giteaHeading" | "gitlabHeading",
+ hintKey: "githubHint" | "giteaHint" | "gitlabHint",
) => (
<div className="space-y-4">
<div className="space-y-1">
@@ -130,6 +130,7 @@ export default function WorkflowEditor({ projectId }: WorkflowEditorProps) {
<div className="space-y-10">
{renderRuleSection("github", "githubHeading", "githubHint")}
{renderRuleSection("gitea", "giteaHeading", "giteaHint")}
+ {renderRuleSection("gitlab", "gitlabHeading", "gitlabHint")}
</div>
);
}
diff --git a/apps/web/src/components/task/task-properties-sidebar.tsx b/apps/web/src/components/task/task-properties-sidebar.tsx
index b25d64edd..a6cb545e4 100644
--- a/apps/web/src/components/task/task-properties-sidebar.tsx
+++ b/apps/web/src/components/task/task-properties-sidebar.tsx
@@ -21,6 +21,7 @@ import {
import { useGetColumns } from "@/hooks/queries/column/use-get-columns";
import useGetGiteaIntegration from "@/hooks/queries/gitea-integration/use-get-gitea-integration";
import useGetGithubIntegration from "@/hooks/queries/github-integration/use-get-github-integration";
+import useGetGitlabIntegration from "@/hooks/queries/gitlab-integration/use-get-gitlab-integration";
import useGetLabelsByTask from "@/hooks/queries/label/use-get-labels-by-task";
import useGetProject from "@/hooks/queries/project/use-get-project";
import useGetProjects from "@/hooks/queries/project/use-get-projects";
@@ -93,6 +94,7 @@ export default function TaskPropertiesSidebar({
const { data: taskLabels = [] } = useGetLabelsByTask(taskId ?? "");
const { data: githubIntegration } = useGetGithubIntegration(projectId);
const { data: giteaIntegration } = useGetGiteaIntegration(projectId);
+ const { data: gitlabIntegration } = useGetGitlabIntegration(projectId);
const { data: workspaceProjects = [] } = useGetProjects({ workspaceId });
const canMoveTask =
Boolean(task) && workspaceProjects.some((p) => p.id !== task?.projectId);
@@ -111,6 +113,7 @@ export default function TaskPropertiesSidebar({
const branchPattern =
githubIntegration?.branchPattern ||
giteaIntegration?.branchPattern ||
+ gitlabIntegration?.branchPattern ||
"{slug}-{number}";
const assignee = workspaceUsers?.members?.find(
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/integrations.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/integrations.tsx
index 63efe5bed..d211b80f6 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/integrations.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/integrations.tsx
@@ -11,11 +11,13 @@ import {
import type { ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { GithubIcon } from "@/components/icons/github-icon";
+import { GitlabIcon } from "@/components/icons/gitlab-icon";
import PageTitle from "@/components/page-title";
import { DiscordIntegrationSettings } from "@/components/project/discord-integration-settings";
import { GenericWebhookIntegrationSettings } from "@/components/project/generic-webhook-integration-settings";
import { GiteaIntegrationSettings } from "@/components/project/gitea-integration-settings";
import { GitHubIntegrationSettings } from "@/components/project/github-integration-settings";
+import { GitlabIntegrationSettings } from "@/components/project/gitlab-integration-settings";
import { MattermostIntegrationSettings } from "@/components/project/mattermost-integration-settings";
import { SlackIntegrationSettings } from "@/components/project/slack-integration-settings";
import { TelegramIntegrationSettings } from "@/components/project/telegram-integration-settings";
@@ -65,6 +67,14 @@ function RouteComponent() {
<GiteaIntegrationSettings projectId={projectId} />
</IntegrationSection>
+ <IntegrationSection
+ icon={<GitlabIcon className="size-4" />}
+ subtitle={t("settings:projectIntegrations.gitlabSectionSubtitle")}
+ title={t("settings:projectIntegrations.gitlabSectionTitle")}
+ >
+ <GitlabIntegrationSettings projectId={projectId} />
+ </IntegrationSection>
+
<IntegrationSection
icon={<MessageCircle className="size-4" />}
subtitle={t("settings:projectIntegrations.discordSectionSubtitle")}
diff --git a/apps/web/src/types/external-link/index.ts b/apps/web/src/types/external-link/index.ts
index 6752cd768..28b40f148 100644
--- a/apps/web/src/types/external-link/index.ts
+++ b/apps/web/src/types/external-link/index.ts
@@ -5,7 +5,14 @@ export type ExternalLinkMetadata = {
draft?: boolean;
branch?: string;
author?: string;
- createdFrom?: "github" | "kaneo" | "gitea" | "gitea-import" | "github-import";
+ createdFrom?:
+ | "github"
+ | "kaneo"
+ | "gitea"
+ | "gitea-import"
+ | "github-import"
+ | "gitlab"
+ | "gitlab-import";
lastCommit?: {
sha: string;
message: string;