Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"devDependencies": {
"@eslint/js": "^9.39.4",
"@linear/sdk": "^81.0.0",
"@typescript-eslint/eslint-plugin": "^8.58.2",
"@typescript-eslint/parser": "^8.58.2",
"eslint": "^9.16.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/outpost/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"types": "./shared/dist/index.d.ts",
"import": "./shared/dist/index.js"
},
"./shared/source/sync": {
"types": "./shared/src/sync/index.ts",
"import": "./shared/src/sync/index.ts"
},
"./shared/platforms": {
"types": "./shared/dist/platforms/index.d.ts",
"import": "./shared/dist/platforms/index.js"
Expand Down
28 changes: 25 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- "apps/*"
- "packages/*"
- 'apps/*'
- 'packages/*'
- 'scripts'
50 changes: 24 additions & 26 deletions scripts/import-linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

import { LinearClient } from '@linear/sdk';
import { PrismaClient } from '@prisma/client';
// Source-only subpath for tsx and vitest; runtime packages import @copilotkit/outpost/shared.
import {
createLinearStatusMap,
createLinearPriorityMap,
createLinearLabelMapper,
} from '../packages/outpost/shared/src/sync/index.js';
} from '@copilotkit/outpost/shared/source/sync';

// ─── Types ────────────────────────────────────────────────────────────────

Expand Down Expand Up @@ -78,7 +79,7 @@ let displayIdCounter = 0;

async function nextDisplayId(prisma: PrismaClient): Promise<string> {
if (displayIdCounter === 0) {
const latest = await (prisma.ticket as { findFirst: (args: Record<string, unknown>) => Promise<{ displayId: string } | null> }).findFirst({
const latest = await prisma.ticket.findFirst({
orderBy: { createdAt: 'desc' },
select: { displayId: true },
});
Expand Down Expand Up @@ -132,9 +133,7 @@ export async function importLinearIssues(
for (const issue of issuesPage.nodes) {
try {
// Check if this issue is already linked
const existingLink = await (prisma.ticketExternalLink as {
findUnique: (args: Record<string, unknown>) => Promise<{ id: string; ticketId: string } | null>;
}).findUnique({
const existingLink = await prisma.ticketExternalLink.findUnique({
where: {
plugin_externalId: {
plugin: 'linear',
Expand All @@ -145,7 +144,9 @@ export async function importLinearIssues(

if (existingLink) {
report.skipped++;
console.log(` SKIP ${issue.identifier}: already linked to ${existingLink.ticketId}`);
console.log(
` SKIP ${issue.identifier}: already linked to ${existingLink.ticketId}`,
);
continue;
}

Expand All @@ -157,9 +158,7 @@ export async function importLinearIssues(
const url = attachment.url;
if (url && /github\.com\/.*\/(issues|pull)\/\d+/.test(url)) {
// Try to find an existing ticket linked to this GitHub URL
const githubLink = await (prisma.ticketExternalLink as {
findFirst: (args: Record<string, unknown>) => Promise<{ ticketId: string } | null>;
}).findFirst({
const githubLink = await prisma.ticketExternalLink.findFirst({
where: {
plugin: 'github',
externalUrl: url,
Expand All @@ -175,9 +174,7 @@ export async function importLinearIssues(
if (matchedTicketId) {
// Cross-reference match: link to existing ticket
if (!args.dryRun) {
await (prisma.ticketExternalLink as {
create: (args: Record<string, unknown>) => Promise<unknown>;
}).create({
await prisma.ticketExternalLink.create({
data: {
ticketId: matchedTicketId,
plugin: 'linear',
Expand All @@ -203,16 +200,16 @@ export async function importLinearIssues(
const outpostTags = labelMapper.toOutpost(labelNames);

if (args.dryRun) {
console.log(` DRY-RUN ${issue.identifier}: would create ticket (${outpostStatus}, ${outpostPriority})`);
console.log(
` DRY-RUN ${issue.identifier}: would create ticket (${outpostStatus}, ${outpostPriority})`,
);
report.created++;
continue;
}

// Create the Outpost ticket
const displayId = await nextDisplayId(prisma);
const ticket = await (prisma.ticket as {
create: (args: Record<string, unknown>) => Promise<{ id: string }>;
}).create({
const ticket = await prisma.ticket.create({
data: {
displayId,
title: issue.title,
Expand All @@ -233,9 +230,7 @@ export async function importLinearIssues(
});

// Create the external link
await (prisma.ticketExternalLink as {
create: (args: Record<string, unknown>) => Promise<unknown>;
}).create({
await prisma.ticketExternalLink.create({
data: {
ticketId: ticket.id,
plugin: 'linear',
Expand All @@ -249,9 +244,7 @@ export async function importLinearIssues(
const comments = await issue.comments();
for (const comment of comments.nodes) {
const authorUser = await comment.user;
await (prisma.message as {
create: (args: Record<string, unknown>) => Promise<unknown>;
}).create({
await prisma.message.create({
data: {
ticketId: ticket.id,
author: authorUser?.name ?? 'Unknown',
Expand All @@ -262,7 +255,9 @@ export async function importLinearIssues(
}

report.created++;
console.log(` CREATE ${issue.identifier} → ${displayId} (${comments.nodes.length} comments)`);
console.log(
` CREATE ${issue.identifier} → ${displayId} (${comments.nodes.length} comments)`,
);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
report.failed++;
Expand All @@ -275,7 +270,7 @@ export async function importLinearIssues(
}

hasMore = issuesPage.pageInfo.hasNextPage;
afterCursor = issuesPage.pageInfo.endCursor;
afterCursor = issuesPage.pageInfo.endCursor ?? undefined;
}

return report;
Expand All @@ -287,7 +282,9 @@ async function main(): Promise<void> {
const args = parseArgs(process.argv);

if (!args.teamId) {
console.error('Usage: npx tsx scripts/import-linear.ts --team-id <TEAM_ID> [--dry-run] [--since DATE]');
console.error(
'Usage: npx tsx scripts/import-linear.ts --team-id <TEAM_ID> [--dry-run] [--since DATE]',
);
process.exit(1);
}

Expand Down Expand Up @@ -331,7 +328,8 @@ async function main(): Promise<void> {
}

// Only run when executed directly (not when imported by tests)
const isDirectRun = process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/.*\//, ''));
const isDirectRun =
process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/.*\//, ''));
if (isDirectRun) {
main().catch((err) => {
console.error('Fatal error:', err);
Expand Down
21 changes: 21 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@copilotkit/outpost-scripts",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"test": "vitest run",
"typecheck": "tsc --project tsconfig.json --noEmit"
},
"dependencies": {
"@copilotkit/outpost": "workspace:*",
"@linear/sdk": "^81.0.0",
"@prisma/client": "^6.2.0"
},
"devDependencies": {
"@types/node": "^22.10.0",
"tsx": "^4.21.0",
"typescript": "^5.7.0",
"vitest": "^4.1.4"
}
}
3 changes: 1 addition & 2 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"include": ["**/*.ts"],
"exclude": ["__tests__"]
"include": ["**/*.ts"]
}
2 changes: 1 addition & 1 deletion vitest.config.ts → scripts/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
include: ['scripts/__tests__/**/*.test.ts'],
include: ['__tests__/**/*.test.ts'],
},
});
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// EVERY package, so a file listed here busts build and test caches too. tsconfig.json
// qualifies — everything builds and typechecks against it. The ESLint config does not,
// and lives on the lint task's `inputs` instead; it cannot change a build or test result,
// which is the same reason .prettierrc and the root vitest.config.ts are absent.
// which is the same reason .prettierrc is absent.
"globalDependencies": ["tsconfig.json"],
// Pinned rather than relying on turbo 2's default, so the reasoning below cannot be
// invalidated by a future change to that default: in strict mode a task sees only the
Expand Down
Loading