From 3b83d9cc96819900a50a8f63aae0f9f13ecd367e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baldur=20P=C3=A1ll=20H=C3=B3lmgeirsson?= Date: Mon, 23 Nov 2026 13:16:07 +0000 Subject: [PATCH] fix(linear): batch the issue-state filter as an and per issue Linear does not apply an `or` whose elements each carry two fields (team key and number): it answers with issues from across the workspace and no error, so `list --issues` and `cleanup` read most Linear worktrees as state unknown. Each element is now an `and` of two single-field filters, the shape #358 measured returning exactly the issues asked for. Closes #358 --- .changeset/linear-issue-state-filter.md | 5 +++++ src/integrations/linear.test.ts | 16 +++++++++++----- src/integrations/linear.ts | 9 +++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 .changeset/linear-issue-state-filter.md diff --git a/.changeset/linear-issue-state-filter.md b/.changeset/linear-issue-state-filter.md new file mode 100644 index 00000000..259d8811 --- /dev/null +++ b/.changeset/linear-issue-state-filter.md @@ -0,0 +1,5 @@ +--- +"@northguild/worktree": patch +--- + +`worktree list --issues` and `worktree cleanup` now read the state of every Linear issue instead of showing most as `state unknown`. Linear ignored the filter `worktree` sent for the batch, so a canceled issue's worktree was rarely offered for removal. diff --git a/src/integrations/linear.test.ts b/src/integrations/linear.test.ts index 651eaf60..3c14631b 100644 --- a/src/integrations/linear.test.ts +++ b/src/integrations/linear.test.ts @@ -1644,12 +1644,14 @@ describe("fetchLinearIssueStates", () => { "query IssueStates($filter: IssueFilter!, $first: Int!) { issues(filter: $filter, first: $first, includeArchived: true) { nodes { identifier state { type } } } }", ); expect(body.query).not.toMatch(/ENG|OPS|123/i); - // Expected variables are D6's filter shape, split at the last "-". + // Expected variables are #358's measured filter shape (each `or` element + // an `and` of team key and number; D6's two-field element is ignored by + // Linear), split at the last "-". expect(body.variables).toEqual({ filter: { or: [ - { team: { key: { eq: "ENG" } }, number: { eq: 123 } }, - { team: { key: { eq: "OPS" } }, number: { eq: 7 } }, + { and: [{ team: { key: { eq: "ENG" } } }, { number: { eq: 123 } }] }, + { and: [{ team: { key: { eq: "OPS" } } }, { number: { eq: 7 } }] }, ], }, first: 2, @@ -1666,7 +1668,11 @@ describe("fetchLinearIssueStates", () => { const body = JSON.parse(fetchSpy.mock.calls[0][1].body); expect(body.variables).toEqual({ - filter: { or: [{ team: { key: { eq: "ENG" } }, number: { eq: 1 } }] }, + filter: { + or: [ + { and: [{ team: { key: { eq: "ENG" } } }, { number: { eq: 1 } }] }, + ], + }, first: 1, }); expect(states).toEqual(new Map([["ENG-1", "canceled"]])); @@ -1694,7 +1700,7 @@ describe("fetchLinearIssueStates", () => { expect(first.filter.or).toHaveLength(50); expect(second.first).toBe(1); expect(second.filter.or).toEqual([ - { team: { key: { eq: "ENG" } }, number: { eq: 51 } }, + { and: [{ team: { key: { eq: "ENG" } } }, { number: { eq: 51 } }] }, ]); expect(states.size).toBe(51); expect(states.get("ENG-1")).toBe("canceled"); diff --git a/src/integrations/linear.ts b/src/integrations/linear.ts index 2c499fc4..04e8643e 100644 --- a/src/integrations/linear.ts +++ b/src/integrations/linear.ts @@ -742,13 +742,18 @@ const LINEAR_STATE_TYPES: ReadonlySet = new Set([ "duplicate", ]); +// Each `or` element is an `and` of two single-field filters. Linear does not +// apply an `or` whose elements carry two fields at once: it answers with +// issues from across the workspace and no error (#358). function issueStatesFilter(identifiers: string[]) { return { or: identifiers.map((identifier) => { const dash = identifier.lastIndexOf("-"); return { - team: { key: { eq: identifier.slice(0, dash) } }, - number: { eq: Number(identifier.slice(dash + 1)) }, + and: [ + { team: { key: { eq: identifier.slice(0, dash) } } }, + { number: { eq: Number(identifier.slice(dash + 1)) } }, + ], }; }), };