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: 1 addition & 0 deletions skills/linear-cli/references/issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Options:
--project <project> - Filter by project name
--cycle <cycle> - Filter by cycle name, number, or 'active'
--milestone <milestone> - Filter by project milestone name (requires --project)
-l, --label <label> - Filter by label name (can be repeated for multiple labels)
--limit <limit> - Maximum number of issues to fetch (default: 50, use 0 for unlimited) (Default: 50)
-w, --web - Open in web browser
-a, --app - Open in Linear.app
Expand Down
11 changes: 11 additions & 0 deletions src/commands/issue/issue-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export const listCommand = new Command()
"--milestone <milestone:string>",
"Filter by project milestone name (requires --project)",
)
.option(
"-l, --label <label:string>",
"Filter by label name (can be repeated for multiple labels)",
{ collect: true },
)
.option(
"--limit <limit:number>",
"Maximum number of issues to fetch (default: 50, use 0 for unlimited)",
Expand All @@ -115,6 +120,7 @@ export const listCommand = new Command()
project,
cycle,
milestone,
label: labels,
limit,
pager,
},
Expand Down Expand Up @@ -205,6 +211,10 @@ export const listCommand = new Command()
milestoneId = await getMilestoneIdByName(milestone, projectId)
}

const labelNames = labels && labels.length > 0
? labels.flat()
: undefined

const { Spinner } = await import("@std/cli/unstable-spinner")
const showSpinner = shouldShowSpinner()
const spinner = showSpinner ? new Spinner() : null
Expand All @@ -221,6 +231,7 @@ export const listCommand = new Command()
sort,
cycleId,
milestoneId,
labelNames,
)
spinner?.stop()
const issues = result.issues?.nodes || []
Expand Down
13 changes: 13 additions & 0 deletions src/utils/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export async function fetchIssuesForState(
sortParam?: "manual" | "priority",
cycleId?: string,
milestoneId?: string,
labelNames?: string[],
) {
const sort = sortParam ??
getOption("issue_sort") as "manual" | "priority" | undefined
Expand Down Expand Up @@ -469,6 +470,18 @@ export async function fetchIssuesForState(
filter.projectMilestone = { id: { eq: milestoneId } }
}

if (labelNames && labelNames.length > 0) {
if (labelNames.length === 1) {
filter.labels = { some: { name: { eqIgnoreCase: labelNames[0] } } }
} else {
filter.labels = {
and: labelNames.map((name) => ({
some: { name: { eqIgnoreCase: name } },
})),
}
}
}

const query = gql(/* GraphQL */ `
query GetIssuesForState($sort: [IssueSortInput!], $filter: IssueFilter!, $first: Int, $after: String) {
issues(filter: $filter, sort: $sort, first: $first, after: $after) {
Expand Down
10 changes: 10 additions & 0 deletions test/commands/issue/__snapshots__/issue-list.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Options:
--project <project> - Filter by project name
--cycle <cycle> - Filter by cycle name, number, or 'active'
--milestone <milestone> - Filter by project milestone name (requires --project)
-l, --label <label> - Filter by label name (can be repeated for multiple labels)
--limit <limit> - Maximum number of issues to fetch (default: 50, use 0 for unlimited) (Default: \\x1b[33m50\\x1b[39m)
-w, --web - Open in web browser
-a, --app - Open in Linear.app
Expand All @@ -32,3 +33,12 @@ Options:
stderr:
""
`;

snapshot[`Issue List Command - Filter By Label 1`] = `
stdout:
"◌ ID TITLE LABELS E STATE UPDATED
⚠⚠⚠ ENG-101 Fix login bug Bug 3 In Progress 4 days ago
"
stderr:
""
`;
67 changes: 66 additions & 1 deletion test/commands/issue/issue-list.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { snapshotTest } from "@cliffy/testing"
import { listCommand } from "../../../src/commands/issue/issue-list.ts"
import { commonDenoArgs } from "../../utils/test-helpers.ts"
import {
commonDenoArgs,
setupMockLinearServer,
} from "../../utils/test-helpers.ts"

// Test help output
await snapshotTest({
Expand All @@ -13,3 +16,65 @@ await snapshotTest({
await listCommand.parse()
},
})

await snapshotTest({
name: "Issue List Command - Filter By Label",
meta: import.meta,
colors: false,
args: ["--label", "Bug", "--team", "ENG", "--sort", "priority"],
denoArgs: commonDenoArgs,
async fn() {
const { cleanup } = await setupMockLinearServer([
{
queryName: "GetTeamIdByKey",
variables: { team: "ENG" },
response: {
data: {
teams: {
nodes: [{ id: "team-eng-id" }],
},
},
},
},
{
queryName: "GetIssuesForState",
response: {
data: {
issues: {
nodes: [
{
id: "issue-1",
identifier: "ENG-101",
title: "Fix login bug",
priority: 1,
estimate: 3,
assignee: { initials: "MC" },
state: {
id: "state-1",
name: "In Progress",
color: "#f2c94c",
},
labels: {
nodes: [{
id: "label-1",
name: "Bug",
color: "#eb5757",
}],
},
updatedAt: "2026-03-13T10:00:00.000Z",
},
],
pageInfo: { hasNextPage: false, endCursor: null },
},
},
},
},
], { LINEAR_TEAM_ID: "ENG", LINEAR_ISSUE_SORT: "priority" })

try {
await listCommand.parse()
} finally {
await cleanup()
}
},
})
Loading