Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/linear-issue-state-filter.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 11 additions & 5 deletions src/integrations/linear.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]]));
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 7 additions & 2 deletions src/integrations/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,18 @@ const LINEAR_STATE_TYPES: ReadonlySet<string> = 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)) } },
],
};
}),
};
Expand Down