Skip to content

Commit 6377d5a

Browse files
committed
refactor: preserve GraphQL payload shape in project update list JSON
1 parent 8234a61 commit 6377d5a

3 files changed

Lines changed: 105 additions & 42 deletions

File tree

src/commands/project-update/project-update-list.ts

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
import { Command } from "@cliffy/command"
2+
import { gql } from "../../__codegen__/gql.ts"
23
import { getGraphQLClient } from "../../utils/graphql.ts"
34
import { getTimeAgo, padDisplay, truncateText } from "../../utils/display.ts"
45
import { resolveProjectId } from "../../utils/linear.ts"
56
import { shouldShowSpinner } from "../../utils/hyperlink.ts"
67
import { handleError, NotFoundError } from "../../utils/errors.ts"
78

8-
interface ProjectUpdateNode {
9-
id: string
10-
body: string | null
11-
health: string | null
12-
url: string
13-
createdAt: string
14-
user: {
15-
name: string
16-
displayName: string
17-
} | null
18-
}
19-
20-
interface ListProjectUpdatesQueryResult {
21-
project: {
22-
name: string
23-
slugId: string
24-
projectUpdates: {
25-
nodes: ProjectUpdateNode[]
26-
} | null
27-
} | null
28-
}
29-
30-
const ListProjectUpdatesQuery = /* GraphQL */ `
9+
const ListProjectUpdatesQuery = gql(`
3110
query ListProjectUpdates($id: String!, $first: Int) {
3211
project(id: $id) {
3312
name
@@ -44,10 +23,14 @@ const ListProjectUpdatesQuery = /* GraphQL */ `
4423
displayName
4524
}
4625
}
26+
pageInfo {
27+
hasNextPage
28+
endCursor
29+
}
4730
}
4831
}
4932
}
50-
`
33+
`)
5134

5235
export const listCommand = new Command()
5336
.name("list")
@@ -67,13 +50,10 @@ export const listCommand = new Command()
6750
const resolvedProjectId = await resolveProjectId(projectId)
6851

6952
const client = getGraphQLClient()
70-
const result = await client.request<ListProjectUpdatesQueryResult>(
71-
ListProjectUpdatesQuery,
72-
{
73-
id: resolvedProjectId,
74-
first: limit,
75-
},
76-
)
53+
const result = await client.request(ListProjectUpdatesQuery, {
54+
id: resolvedProjectId,
55+
first: limit,
56+
})
7757
spinner?.stop()
7858

7959
const project = result.project
@@ -84,17 +64,7 @@ export const listCommand = new Command()
8464
const updates = project.projectUpdates?.nodes || []
8565

8666
if (json) {
87-
console.log(JSON.stringify(
88-
{
89-
project: {
90-
name: project.name,
91-
slugId: project.slugId,
92-
},
93-
updates,
94-
},
95-
null,
96-
2,
97-
))
67+
console.log(JSON.stringify(project, null, 2))
9868
return
9969
}
10070

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const snapshot = {};
2+
3+
snapshot[`Project Update List Command - JSON Output 1`] = `
4+
stdout:
5+
'{
6+
"name": "JSON Project",
7+
"slugId": "json-project",
8+
"projectUpdates": {
9+
"nodes": [
10+
{
11+
"id": "project-update-1",
12+
"body": "Project is healthy.",
13+
"health": "onTrack",
14+
"url": "https://linear.app/test/project-update-1",
15+
"createdAt": "2026-02-10T09:00:00Z",
16+
"user": {
17+
"name": "alex.active",
18+
"displayName": "Alex Active"
19+
}
20+
}
21+
],
22+
"pageInfo": {
23+
"hasNextPage": false,
24+
"endCursor": null
25+
}
26+
}
27+
}
28+
'
29+
stderr:
30+
""
31+
`;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { snapshotTest as cliffySnapshotTest } from "@cliffy/testing"
2+
import { listCommand } from "../../../src/commands/project-update/project-update-list.ts"
3+
import { commonDenoArgs } from "../../utils/test-helpers.ts"
4+
import { MockLinearServer } from "../../utils/mock_linear_server.ts"
5+
6+
await cliffySnapshotTest({
7+
name: "Project Update List Command - JSON Output",
8+
meta: import.meta,
9+
colors: false,
10+
args: ["550e8400-e29b-41d4-a716-446655440000", "--json"],
11+
denoArgs: commonDenoArgs,
12+
async fn() {
13+
const server = new MockLinearServer([
14+
{
15+
queryName: "ListProjectUpdates",
16+
variables: {
17+
id: "550e8400-e29b-41d4-a716-446655440000",
18+
first: 10,
19+
},
20+
response: {
21+
data: {
22+
project: {
23+
name: "JSON Project",
24+
slugId: "json-project",
25+
projectUpdates: {
26+
nodes: [
27+
{
28+
id: "project-update-1",
29+
body: "Project is healthy.",
30+
health: "onTrack",
31+
url: "https://linear.app/test/project-update-1",
32+
createdAt: "2026-02-10T09:00:00Z",
33+
user: {
34+
name: "alex.active",
35+
displayName: "Alex Active",
36+
},
37+
},
38+
],
39+
pageInfo: {
40+
hasNextPage: false,
41+
endCursor: null,
42+
},
43+
},
44+
},
45+
},
46+
},
47+
},
48+
])
49+
50+
try {
51+
await server.start()
52+
Deno.env.set("LINEAR_GRAPHQL_ENDPOINT", server.getEndpoint())
53+
Deno.env.set("LINEAR_API_KEY", "Bearer test-token")
54+
55+
await listCommand.parse()
56+
} finally {
57+
await server.stop()
58+
Deno.env.delete("LINEAR_GRAPHQL_ENDPOINT")
59+
Deno.env.delete("LINEAR_API_KEY")
60+
}
61+
},
62+
})

0 commit comments

Comments
 (0)