31907ba651
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
70 lines
2.7 KiB
TypeScript
70 lines
2.7 KiB
TypeScript
import { copyJiraConfig } from "@/lib/api/domains/jira-api";
|
|
import { copyLinearConfig } from "@/lib/api/domains/linear-api";
|
|
import { copySentryInstances } from "@/lib/api/domains/sentry-api";
|
|
import { copyGitHubWorkspaceSettings } from "@/lib/api/domains/github-api";
|
|
import { copyAzureDevOpsConfig } from "@/lib/api/domains/azure-devops-api";
|
|
import { copyGitLabConfig } from "@/lib/api/domains/gitlab-api";
|
|
|
|
// IntegrationSlug is the set of integration settings pages that support copying
|
|
// their per-workspace config to another workspace.
|
|
export type IntegrationSlug = "azure-devops" | "jira" | "linear" | "sentry" | "github" | "gitlab";
|
|
|
|
// integrationLabels maps each slug to how the rest of the app spells it.
|
|
const integrationLabels: Record<IntegrationSlug, string> = {
|
|
"azure-devops": "Azure DevOps",
|
|
jira: "Jira",
|
|
linear: "Linear",
|
|
sentry: "Sentry",
|
|
github: "GitHub",
|
|
gitlab: "GitLab",
|
|
};
|
|
|
|
// integrationFromPathname returns the integration slug for a settings pathname
|
|
// like /settings/workspaces/<id>/integrations/jira (or the legacy
|
|
// /settings/workspace/<id>/... and /settings/integrations/... spellings), or
|
|
// null when the current page is not a copyable integration page.
|
|
export function integrationFromPathname(pathname: string): IntegrationSlug | null {
|
|
const match = pathname.match(/^\/settings(?:\/workspaces?\/[^/]+)?\/integrations\/([^/]+)/);
|
|
const slug = match?.[1];
|
|
if (slug && Object.prototype.hasOwnProperty.call(integrationLabels, slug)) {
|
|
return slug as IntegrationSlug;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// integrationLabel returns the display name for a slug.
|
|
export function integrationLabel(slug: IntegrationSlug): string {
|
|
return integrationLabels[slug];
|
|
}
|
|
|
|
// copyIntegrationConfig copies the config for the given integration from
|
|
// sourceWorkspaceId to targetWorkspaceId. GitHub copies settings only (its auth
|
|
// is install-wide); every other integration copies config + credentials.
|
|
export async function copyIntegrationConfig(
|
|
slug: IntegrationSlug,
|
|
sourceWorkspaceId: string,
|
|
targetWorkspaceId: string,
|
|
): Promise<void> {
|
|
const options = { workspaceId: sourceWorkspaceId };
|
|
switch (slug) {
|
|
case "azure-devops":
|
|
await copyAzureDevOpsConfig(sourceWorkspaceId, targetWorkspaceId);
|
|
return;
|
|
case "jira":
|
|
await copyJiraConfig(targetWorkspaceId, options);
|
|
return;
|
|
case "linear":
|
|
await copyLinearConfig(targetWorkspaceId, options);
|
|
return;
|
|
case "sentry":
|
|
await copySentryInstances(targetWorkspaceId, options);
|
|
return;
|
|
case "github":
|
|
await copyGitHubWorkspaceSettings(targetWorkspaceId, options);
|
|
return;
|
|
case "gitlab":
|
|
await copyGitLabConfig(targetWorkspaceId, options);
|
|
return;
|
|
}
|
|
}
|