c508eecc33
Factors out the duplicated logic between internal/jira + internal/linear (backend) and components/jira + components/linear (frontend) into reusable shared shapes. Follow-up to PR #736. Backend: - New internal/integrations/secretadapter wraps secrets.SecretStore with the upsert API both jira.SecretStore and linear.SecretStore expect; drops both adapter copies from cmd/kandev/services.go. - New internal/integrations/healthpoll owns the 90s auth-health loop via a Prober interface; linear/poller.go is a thin wrapper, jira/poller.go keeps only its (jira-specific) issue-watch loop. - provideServices split into initGitHubService / initJiraService / initLinearService — now 75 lines (was ~125, exceeded the 80-line limit). Frontend: - New hooks/domains/integrations/use-integration-availability.ts and use-integration-enabled.ts; jira/linear hooks reduce to one-line delegates and move from components/<x>/ to hooks/domains/<x>/ per the project convention Greptile flagged on PR #736. - New components/integrations/{auth-status-banner,auth-error-message, validated-popover}.tsx; the four link/import-bar wrappers drop from ~110 lines to ~35 each, and JiraLinkButton picks up the clear-error-on-close behaviour LinearLinkButton already had. Docs: - New 'Adding a new third-party integration' section in CLAUDE.md/AGENTS.md documenting the shared shapes and intentional Jira/Linear divergence (transition vs state, JQL vs filter object, eventBus only on jira).
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback } from "react";
|
|
import { IconLink } from "@tabler/icons-react";
|
|
import { toast } from "sonner";
|
|
import { getLinearIssue } from "@/lib/api/domains/linear-api";
|
|
import { updateTask } from "@/lib/api/domains/kanban-api";
|
|
import { LINEAR_KEY_RE } from "./linear-issue-common";
|
|
import { useLinearAvailable } from "@/hooks/domains/linear/use-linear-availability";
|
|
import { ValidatedPopover } from "@/components/integrations/validated-popover";
|
|
|
|
type LinearLinkButtonProps = {
|
|
taskId: string | null | undefined;
|
|
workspaceId: string | null | undefined;
|
|
taskTitle: string | undefined | null;
|
|
};
|
|
|
|
// LinearLinkButton attaches a Linear issue to an existing task by prepending
|
|
// the identifier to its title ("ENG-123: ...").
|
|
export function LinearLinkButton({ taskId, workspaceId, taskTitle }: LinearLinkButtonProps) {
|
|
const available = useLinearAvailable(workspaceId);
|
|
|
|
const onSuccess = useCallback(
|
|
async (key: string) => {
|
|
if (!taskId) return;
|
|
const stripped = (taskTitle ?? "").trim().replace(/^[A-Z][A-Z0-9]*-\d+:\s*/, "");
|
|
const newTitle = stripped ? `${key}: ${stripped}` : key;
|
|
await updateTask(taskId, { title: newTitle });
|
|
toast.success(`Linked to ${key}`);
|
|
},
|
|
[taskId, taskTitle],
|
|
);
|
|
|
|
if (!available || !taskId || !workspaceId) return null;
|
|
|
|
return (
|
|
<ValidatedPopover
|
|
triggerStyle="outline-with-label"
|
|
triggerIcon={<IconLink className="h-4 w-4" />}
|
|
triggerLabel="Link Linear"
|
|
tooltip="Link this task to a Linear issue"
|
|
headline="Link to Linear issue"
|
|
placeholder="ENG-123 or paste issue URL"
|
|
extractKey={(raw) => raw.toUpperCase().match(LINEAR_KEY_RE)?.[0] ?? null}
|
|
validationHint="Paste a Linear issue URL or identifier (ENG-123)"
|
|
fetch={(key) => getLinearIssue(workspaceId, key)}
|
|
onSuccess={(key) => void onSuccess(key)}
|
|
submitLabel="Link"
|
|
submittingLabel="Linking..."
|
|
/>
|
|
);
|
|
}
|