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
2 changes: 1 addition & 1 deletion apps/cli-docs/src/content/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ toolkit/
│ │ │ ├── event/ # analytics, list, send, view
│ │ │ ├── feedback/ # list, resolve, spam, unresolve, view
│ │ │ ├── integration/ # delete, list
│ │ │ ├── issue/ # archive, events, explain, link, list, merge, plan, resolve, tags, unlink, unresolve, view
│ │ │ ├── issue/ # archive, comment, comments, events, explain, link, list, merge, plan, resolve, tags, unlink, unresolve, view
│ │ │ ├── local/ # close, create, list, reset, restart, retention, run, serve, start, status, stop, view
│ │ │ ├── log/ # list, view
│ │ │ ├── monitor/ # list, run
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/lint-rules/cli-oxlint-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,11 @@ const MANUAL_API_REQUEST_EXCEPTIONS = new Map([
"openSnapshotArchive",
],
],
// Issue comments are not in the public API schema.
[
"lib/api/issue-comments.ts",
["fetchIssueCommentPage", "createIssueComment"],
],
// Unauthenticated transport for the generated shared-issue call on another host.
["lib/api/issues.ts", ["getSharedIssue"]],
// Unauthenticated transport for the generated handoff claim before login exists.
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/plugins/sentry-cli/skills/sentry-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ Manage Sentry issues
- `sentry issue list [<org/project>]` — List issues in a project
- `sentry issue events <issue>` — List events for a specific issue
- `sentry issue tags <issue> <key>` — Show the top values of an issue tag
- `sentry issue comment <issue> <text>` — Comment on an issue, optionally attaching videos
- `sentry issue comments <issue>` — List an issue's comments and their videos
- `sentry issue explain <issue...>` — Analyze one or more issues using Seer AI
- `sentry issue plan <issue>` — Generate a solution plan using Seer AI
- `sentry issue view <issue...>` — View details of one or more issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,82 @@ sentry issue tags FRONT-ABC browser.name --json
sentry issue tags FRONT-ABC release --json --fields key,totalValues,topValues
```

### `sentry issue comment <issue> <text>`

Comment on an issue, optionally attaching videos

**Arguments:**

| Argument | Description |
|----------|-------------|
| `<issue>` | Issue: @latest, @most_frequent, &lt;org&gt;/ID, &lt;org&gt;/&lt;project&gt;#ID, &lt;project&gt;-suffix, ID, or suffix |
| `<text>` | Comment text (Markdown) |

**Flags:**
- `-a, --attach <value>... - Path of a video to attach (repeatable)`
- `-n, --dry-run - Show what would happen without making changes`

**JSON Fields** (use `--json --fields` to select specific fields):

| Field | Type | Description |
|-------|------|-------------|
| `id` | string | Comment ID; absent with --dry-run |
| `dateCreated` | string | When the comment was posted |
| `author` | string | Who posted the comment |
| `text` | string | Comment text, including links to attached videos |
| `attachments` | array | Videos attached to the comment |
| `dryRun` | boolean | True when --dry-run made no change |

**Examples:**

```bash
# Comment on an issue
sentry issue comment my-org/FRONT-ABC "Fixed in the next deploy"

# Attach a screen recording of the bug
sentry issue comment FRONT-ABC "Repro steps below" --attach repro.mp4

# Check attachments without posting
sentry issue comment FRONT-ABC "Repro" --attach a.mp4 --attach b.webm --dry-run
```

### `sentry issue comments <issue>`

List an issue's comments and their videos

**Arguments:**

| Argument | Description |
|----------|-------------|
| `<issue>` | Issue: @latest, @most_frequent, &lt;org&gt;/ID, &lt;org&gt;/&lt;project&gt;#ID, &lt;project&gt;-suffix, ID, or suffix |

**Flags:**
- `-d, --download <value> - Directory to save attached videos into`

**JSON Fields** (use `--json --fields` to select specific fields):

| Field | Type | Description |
|-------|------|-------------|
| `id` | string | Comment ID; absent with --dry-run |
| `dateCreated` | string | When the comment was posted |
| `author` | string | Who posted the comment |
| `text` | string | Comment text, including links to attached videos |
| `attachments` | array | Videos attached to the comment |
| `dryRun` | boolean | True when --dry-run made no change |

**Examples:**

```bash
# Read the comments on an issue
sentry issue comments my-org/FRONT-ABC

# Save the attached videos to ./videos
sentry issue comments FRONT-ABC --download ./videos

# Get comments and video URLs as JSON
sentry issue comments FRONT-ABC --json --fields author,text,attachments
```

### `sentry issue explain <issue...>`

Analyze one or more issues using Seer AI
Expand Down
261 changes: 261 additions & 0 deletions packages/cli/src/commands/issue/comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
/**
* sentry issue comment / sentry issue comments
*
* Post a comment on an issue, optionally with screen recordings attached, and
* read an issue's comments, optionally saving their videos to disk.
*/

import { mkdir } from "node:fs/promises";
import { basename, join } from "node:path";
import {
commentAttachmentPath,
parseCommentAttachments,
} from "@sentry/mcp-core/comment-attachments";
import type { SentryContext } from "../../context.js";
import {
createIssueCommentWithVideos,
downloadIssueCommentAttachment,
type IssueComment,
listIssueComments,
readLocalVideo,
} from "../../lib/api-client.js";
import { buildCommand } from "../../lib/command.js";
import {
parseDirectoryPath,
parseFilePath,
parseText,
} from "../../lib/completion-target.js";
import {
formatIssueComment,
formatIssueComments,
} from "../../lib/formatters/issue-comments.js";
import { CommandOutput } from "../../lib/formatters/output.js";
import { DRY_RUN_ALIASES, DRY_RUN_FLAG } from "../../lib/mutate-command.js";
import { withProgress } from "../../lib/polling.js";
import { resolveOrgRegion } from "../../lib/region.js";
import { IssueCommentOutputSchema } from "../../generated/output-schemas/issue.js";
import type { IssueCommentOutput } from "../../output-schemas/issue.js";
import {
type IssueTarget,
issueParameter,
issuePositional,
} from "./positional.js";

function commentAuthor(comment: IssueComment): string {
return (
comment.user?.name ||
comment.user?.email ||
comment.sentry_app?.name ||
"Sentry"
);
}

/**
* Comment output with each linked video's full API URL, built from the issue
* being read, the same URL `--download` fetches.
*/
function toOutput(
comment: IssueComment,
regionUrl: string,
org: string,
issueId: string,
): IssueCommentOutput {
const text = comment.data.text ?? "";
const origin = regionUrl.replace(/\/$/, "");
return {
id: comment.id,
dateCreated: comment.dateCreated,
author: commentAuthor(comment),
text,
attachments: parseCommentAttachments(text).map((link) => ({
id: link.id,
name: link.name,
url: `${origin}${commentAttachmentPath(org, issueId, link.id)}`,
})),
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
};
}

type CommentFlags = {
readonly json: boolean;
readonly fields?: string[];
readonly attach?: string[];
readonly "dry-run": boolean;
};

export const commentCommand = buildCommand({
docs: {
brief: "Comment on an issue, optionally attaching videos",
fullDescription:
"Post a comment to an issue's activity feed, visible to the whole team.\n\n" +
"Use --attach to upload screen recordings with the comment. Accepted\n" +
"formats are MP4, MOV, WebM and Ogg; the server's size limit applies\n" +
"(95 MB by default). Each video is linked after the comment text and\n" +
"plays inline in Sentry.\n\n" +
"Use --dry-run to check the files without uploading or posting anything.",
examples: [
{
description: "Comment on an issue",
run: 'issue comment my-org/FRONT-ABC "Fixed in the next deploy"',
},
{
description: "Attach a screen recording of the bug",
run: 'issue comment FRONT-ABC "Repro steps below" --attach repro.mp4',
},
{
description: "Check attachments without posting",
run: 'issue comment FRONT-ABC "Repro" --attach a.mp4 --attach b.webm --dry-run',
},
],
},
output: {
human: formatIssueComment,
schema: IssueCommentOutputSchema,
},
parameters: {
positional: {
kind: "tuple",
parameters: [
issueParameter({ command: "comment" }),
{
placeholder: "text",
brief: "Comment text (Markdown)",
parse: parseText,
},
],
},
flags: {
attach: {
kind: "parsed",
parse: parseFilePath,
brief: "Path of a video to attach (repeatable)",
optional: true,
variadic: true,
},
"dry-run": DRY_RUN_FLAG,
},
aliases: { ...DRY_RUN_ALIASES, a: "attach" },
},
async *func(
this: SentryContext,
flags: CommentFlags,
target: IssueTarget,
text: string,
) {
const paths = flags.attach ?? [];
// Read and check every file before anything is uploaded.
const videos = await Promise.all(paths.map(readLocalVideo));
const { org, issue } = await target.resolved;

if (flags["dry-run"]) {
yield new CommandOutput<IssueCommentOutput>({
text,
attachments: videos.map((video) => ({
id: "",
name: video.name,
url: "",
})),
dryRun: true,
});
return { hint: `Issue: ${issue.shortId}. Nothing was uploaded.` };
}

const { comment } = await withProgress(
{
message: videos.length
? `Uploading ${videos.length} video(s) and posting comment...`
: "Posting comment...",
json: flags.json,
},
() => createIssueCommentWithVideos(org, issue.id, text, videos),
);
yield new CommandOutput(
toOutput(comment, await resolveOrgRegion(org), org, issue.id),
);
return { hint: `Issue: ${issue.shortId}.` };
},
});

type CommentsFlags = {
readonly json: boolean;
readonly fields?: string[];
readonly download?: string;
};

export const commentsCommand = buildCommand({
docs: {
brief: "List an issue's comments and their videos",
fullDescription:
"Show an issue's comments, newest first, with any videos attached to them.\n\n" +
"Use --download to save every attached video into a directory. Files are\n" +
"named <attachment-id>-<file name> so videos with the same name do not\n" +
"overwrite each other.",
examples: [
{
description: "Read the comments on an issue",
run: "issue comments my-org/FRONT-ABC",
},
{
description: "Save the attached videos to ./videos",
run: "issue comments FRONT-ABC --download ./videos",
},
{
description: "Get comments and video URLs as JSON",
run: "issue comments FRONT-ABC --json --fields author,text,attachments",
},
],
},
output: {
human: formatIssueComments,
schema: IssueCommentOutputSchema,
},
parameters: {
positional: issuePositional({ command: "comments" }),
flags: {
download: {
kind: "parsed",
parse: parseDirectoryPath,
brief: "Directory to save attached videos into",
optional: true,
},
},
aliases: { d: "download" },
},
async *func(this: SentryContext, flags: CommentsFlags, target: IssueTarget) {
const { org, issue } = await target.resolved;
const [comments, regionUrl] = await withProgress(
{ message: "Fetching comments...", json: flags.json },
() =>
Promise.all([listIssueComments(org, issue.id), resolveOrgRegion(org)]),
);
const output = comments.map((comment) =>
toOutput(comment, regionUrl, org, issue.id),
);

if (flags.download !== undefined) {
const dir = flags.download;
await mkdir(dir, { recursive: true });
for (const comment of output) {
for (const attachment of comment.attachments) {
const destPath = join(
dir,
`${attachment.id}-${basename(attachment.name)}`,
);
await withProgress(
{ message: `Downloading ${attachment.name}...`, json: flags.json },
() =>
downloadIssueCommentAttachment(
org,
issue.id,
attachment.id,
destPath,
),
);
attachment.savedTo = destPath;
}
}
}

yield new CommandOutput(output);
return { hint: `Issue: ${issue.shortId}. ${output.length} comment(s).` };
},
});
Loading
Loading