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
20 changes: 14 additions & 6 deletions sdk/typescript/src/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ export async function importLinearIssues(options: {
);
}

const page = await projects.nodes[0]!.issues({ first: 50, filter });
while (page.pageInfo.hasNextPage) await page.fetchNext();
issues.push(...page.nodes);
let page = await projects.nodes[0]!.issues({ first: 50, filter });
while (true) {
issues.push(...page.nodes);
if (!page.pageInfo.hasNextPage) break;
page = await page.fetchNext();
}
if (issues.length === 0) {
throw new CodexSecurityError(
`No open Linear issues matched project "${options.project}" and its filter.`,
Expand Down Expand Up @@ -114,16 +117,21 @@ export async function importLinearIssues(options: {

const imports: ImportedIssue[] = [];
for (const issue of issues) {
const comments = await issue.comments({ first: 50 });
while (comments.pageInfo.hasNextPage) await comments.fetchNext();
let comments = await issue.comments({ first: 50 });
const commentNodes = [];
while (true) {
commentNodes.push(...comments.nodes);
if (!comments.pageInfo.hasNextPage) break;
comments = await comments.fetchNext();
}
imports.push({
source: "linear",
id: issue.identifier,
url: issue.url,
text: [
`Title: ${issue.title}`,
`<description>\n${issue.description ?? ""}\n</description>`,
...comments.nodes.map(
...commentNodes.map(
({ url, body }) => `<comment>\nURL: ${url}\n\n${body}\n</comment>`,
),
].join("\n\n"),
Expand Down
39 changes: 24 additions & 15 deletions sdk/typescript/tests-ts/cli-skills.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ function linearIssue(identifier: string, comments: string[] = []) {
body,
url: `https://linear.app/example/issue/${identifier}#comment-${index}`,
}));
const nextPage = {
nodes: nodes.slice(1),
pageInfo: { hasNextPage: false },
async fetchNext() {
throw new Error("unexpected extra Linear comment page");
},
};
const firstPage = {
nodes: nodes.slice(0, 1),
pageInfo: { hasNextPage: nodes.length > 1 },
async fetchNext() {
return nextPage;
},
};
return {
identifier,
title: `Fix ${identifier}`,
description: `Synthetic evidence for ${identifier}`,
url: `https://linear.app/example/issue/${identifier}`,
comments: async () => ({
nodes: nodes.slice(0, 1),
pageInfo: { hasNextPage: nodes.length > 1 },
async fetchNext() {
this.nodes.push(...nodes.slice(1));
this.pageInfo.hasNextPage = false;
return this;
},
}),
comments: async () => firstPage,
};
}

Expand Down Expand Up @@ -191,7 +197,7 @@ describe("CLI skill commands", () => {
description,
};
},
} as ReturnType<LinearClientFactory>;
} as unknown as ReturnType<LinearClientFactory>;
},
onCodex: (_args, output, processEnvironment) => {
inputs = JSON.parse(output!.appServer!.prompt.split("\n").at(-1)!);
Expand Down Expand Up @@ -308,16 +314,19 @@ describe("CLI skill commands", () => {
environment: { LINEAR_ACCESS_TOKEN: "SYNTHETIC_OAUTH_TOKEN" },
linearClient: ({ accessToken }) => {
expect(accessToken).toBe("SYNTHETIC_OAUTH_TOKEN");
const nextPage = {
nodes: [linearIssue("SEC-124", ["Second issue comment"])],
pageInfo: { hasNextPage: false },
async fetchNext() {
throw new Error("unexpected extra Linear issue page");
},
};
const page = {
nodes: [linearIssue("SEC-123", ["First issue comment"])],
pageInfo: { hasNextPage: true },
async fetchNext() {
nextPages++;
this.nodes.push(
linearIssue("SEC-124", ["Second issue comment"]),
);
this.pageInfo.hasNextPage = false;
return this;
return nextPage;
},
};
return {
Expand Down