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
32 changes: 31 additions & 1 deletion src/commands/issue/issue-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ export const viewCommand = new Command()
outputLines.push(...renderedAttachments.split("\n"))
}

if (issueData.documents && issueData.documents.length > 0) {
const documentsMarkdown = formatDocumentsAsMarkdown(
issueData.documents,
)
const renderedDocuments = renderMarkdown(documentsMarkdown, {
lineWidth: terminalWidth,
extensions,
})
outputLines.push(...renderedDocuments.split("\n"))
}

if (
showComments && derivedComments &&
derivedComments.visibleRootComments.length > 0
Expand Down Expand Up @@ -255,6 +266,10 @@ export const viewCommand = new Command()
)
}

if (issueData.documents && issueData.documents.length > 0) {
markdown += formatDocumentsAsMarkdown(issueData.documents)
}

if (
showComments && derivedComments &&
derivedComments.visibleRootComments.length > 0
Expand Down Expand Up @@ -727,8 +742,9 @@ async function downloadIssueImages(
return urlToPath
}

// Type for attachments
// Type for attachments and documents
type AttachmentInfo = FetchedIssueDetails["attachments"][number]
type DocumentInfo = FetchedIssueDetails["documents"][number]

function getAttachmentCacheDir(): string {
const configuredDir = getOption("attachment_dir")
Expand Down Expand Up @@ -837,3 +853,17 @@ function formatAttachmentsAsMarkdown(

return markdown
}

function formatDocumentsAsMarkdown(documents: DocumentInfo[]): string {
if (documents.length === 0) {
return ""
}

let markdown = "\n\n## Documents\n\n"

for (const document of documents) {
markdown += `- **${document.title}**: ${document.url}\n`
}

return markdown
}
34 changes: 32 additions & 2 deletions src/utils/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ const issueDetailsWithCommentsQuery = gql(/* GraphQL */ `
createdAt
}
}
documents(first: 50) {
nodes {
id
title
slugId
url
createdAt
updatedAt
}
}
}
}
`)
Expand Down Expand Up @@ -326,6 +336,16 @@ const issueDetailsQuery = gql(/* GraphQL */ `
createdAt
}
}
documents(first: 50) {
nodes {
id
title
slugId
url
createdAt
updatedAt
}
}
}
}
`)
Expand Down Expand Up @@ -354,18 +374,26 @@ export type FetchedIssueComment = IssueDetailsWithComments["comments"]["nodes"][
]

export type FetchedIssueDetailsWithComments =
& Omit<IssueDetailsWithComments, "children" | "comments" | "attachments">
& Omit<
IssueDetailsWithComments,
"children" | "comments" | "attachments" | "documents"
>
& {
children: IssueDetailsWithComments["children"]["nodes"]
comments: IssueDetailsWithComments["comments"]["nodes"]
attachments: IssueDetailsWithComments["attachments"]["nodes"]
documents: IssueDetailsWithComments["documents"]["nodes"]
}

export type FetchedIssueDetailsWithoutComments =
& Omit<IssueDetailsWithoutComments, "children" | "attachments">
& Omit<
IssueDetailsWithoutComments,
"children" | "attachments" | "documents"
>
& {
children: IssueDetailsWithoutComments["children"]["nodes"]
attachments: IssueDetailsWithoutComments["attachments"]["nodes"]
documents: IssueDetailsWithoutComments["documents"]["nodes"]
}

export type FetchedIssueDetails =
Expand Down Expand Up @@ -395,6 +423,7 @@ export async function fetchIssueDetails(
children: data.children?.nodes || [],
comments: data.comments?.nodes || [],
attachments: data.attachments?.nodes || [],
documents: data.documents?.nodes || [],
}
}

Expand All @@ -405,6 +434,7 @@ export async function fetchIssueDetails(
...data,
children: data.children?.nodes || [],
attachments: data.attachments?.nodes || [],
documents: data.documents?.nodes || [],
}
} catch (error) {
spinner?.stop()
Expand Down
87 changes: 87 additions & 0 deletions test/commands/issue/__snapshots__/issue-view.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ Users are experiencing issues logging in when their session expires.
Sounds good! Also, we should add better error messaging for expired sessions.


"
stderr:
""
`;

snapshot[`Issue View Command - With Documents And Attachments 1`] = `
stdout:
"# TEST-246: Audit issue resource output

**State:** In Progress | **Priority:** ▄▆█ | **Assignee:** @Jane Smith

Ensure issue view shows both attachments and documents.

## Attachments

- **Design mock**: https://example.com/design-mock _[figma]_
_Figma file_


## Documents

- **Implementation plan**: https://linear.app/test-team/document/implementation-plan-impl-plan-123
- **QA checklist**: https://linear.app/test-team/document/qa-checklist-qa-checklist-456

"
stderr:
""
Expand Down Expand Up @@ -188,6 +212,69 @@ stderr:
""
`;

snapshot[`Issue View Command - JSON Output With Documents And Attachments 1`] = `
stdout:
'{
"identifier": "TEST-246",
"title": "Audit issue resource output",
"description": "Ensure issue view shows both attachments and documents.",
"url": "https://linear.app/test-team/issue/TEST-246/audit-issue-resource-output",
"branchName": "test-246-issue-resource-output",
"state": {
"name": "In Progress",
"color": "#f87462"
},
"assignee": {
"name": "jane.smith",
"displayName": "Jane Smith"
},
"priority": 2,
"project": null,
"projectMilestone": null,
"cycle": null,
"parent": null,
"children": {
"nodes": []
},
"attachments": {
"nodes": [
{
"id": "attachment-1",
"title": "Design mock",
"url": "https://example.com/design-mock",
"subtitle": "Figma file",
"sourceType": "figma",
"metadata": {},
"createdAt": "2024-01-15T10:30:00Z"
}
]
},
"documents": {
"nodes": [
{
"id": "document-1",
"title": "Implementation plan",
"slugId": "impl-plan-123",
"url": "https://linear.app/test-team/document/implementation-plan-impl-plan-123",
"createdAt": "2024-01-15T09:30:00Z",
"updatedAt": "2024-01-15T09:45:00Z"
},
{
"id": "document-2",
"title": "QA checklist",
"slugId": "qa-checklist-456",
"url": "https://linear.app/test-team/document/qa-checklist-qa-checklist-456",
"createdAt": "2024-01-15T09:00:00Z",
"updatedAt": "2024-01-15T09:15:00Z"
}
]
}
}
'
stderr:
""
`;

snapshot[`Issue View Command - With Parent And Sub-issues 1`] = `
stdout:
"# TEST-456: Implement user authentication
Expand Down
Loading
Loading