Skip to content

feat(discussion): add comment command#13620

Open
babakks wants to merge 8 commits into
feature/discussionfrom
babakks/add-discussion-comment
Open

feat(discussion): add comment command#13620
babakks wants to merge 8 commits into
feature/discussionfrom
babakks/add-discussion-comment

Conversation

@babakks

@babakks babakks commented Jun 8, 2026

Copy link
Copy Markdown
Member

Add gh discussion comment command

This PR adds a new gh discussion comment command for managing comments and replies on GitHub Discussions, along with UX improvements to the view command.

gh discussion comment

The command supports adding, editing, and deleting comments and replies. The positional argument determines the action context:

Adding a top-level comment:

gh discussion comment 123 --body "Thanks for raising this"
gh discussion comment 123 --body-file response.md

Replying to a comment (positional arg is a comment ID or URL):

gh discussion comment DC_abc123 --body "Good point"
gh discussion comment "https://github.com/OWNER/REPO/discussions/123#discussioncomment-456" --body "I agree"

Editing a comment or reply:

gh discussion comment DC_abc123 --edit --body "Updated text"
gh discussion comment "https://github.com/OWNER/REPO/discussions/123#discussioncomment-456" --edit --body-file updated.md

Deleting a comment or reply:

gh discussion comment DC_abc123 --delete --yes
gh discussion comment "https://github.com/OWNER/REPO/discussions/123#discussioncomment-456" --delete --yes

When no --body or --body-file is provided in an interactive terminal, an editor is opened for input. For edits, the editor is pre-populated with the existing comment body.

Comment URLs are resolved to node IDs via msgpack encoding of the repository database ID and comment database ID extracted from the URL fragment.

Changes to gh discussion view

The --replies flag now accepts both comment node IDs and comment URLs:

gh discussion view 123 --replies DC_abc123
gh discussion view 123 --replies "https://github.com/OWNER/REPO/discussions/123#discussioncomment-456"

When a URL is provided, the repository and discussion number from the URL override the positional argument.

Tests

  • Added acceptance tests for the comment command covering add, reply, edit (including from file), delete (with confirmation prompt check), and URL-based operations.
  • Updated existing acceptance tests (discussion-view.txtar, discussion-list.txtar) to use the new comment command instead of raw gh api graphql mutations.
  • Added a test case in discussion-view.txtar to verify --replies works with a comment URL.
  • Unit tests cover flag parsing, all run paths (add/reply/edit/delete), comment URL resolution, body-file/stdin input, editor pre-population, and error cases.

babakks and others added 8 commits June 8, 2026 18:09
Add client methods for managing discussion comments and replies:
- AddComment: creates a top-level comment or reply via addDiscussionComment
- UpdateComment: edits a comment body via updateDiscussionComment
- DeleteComment: removes a comment via deleteDiscussionComment
- GetComment: fetches a comment by node ID with typename validation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Implement gh discussion comment for adding, editing, and deleting
comments and replies on discussions. Supports --body, --body-file,
--editor for input, --reply-to for threading, --edit and --delete
for modifying existing comments, with confirmation prompts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…PI calls

Replace gh api graphql addDiscussionComment mutations in view and list
acceptance tests with gh discussion comment. Extract comment IDs via
a single view call with jq2env instead of multiple calls.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cover add, reply, edit, delete flows including body-file input,
non-interactive delete requiring --yes, and deletion of both parent
comment and reply to avoid ghost entries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add test for --delete without --yes in non-TTY mode and fix existing
delete tests to set isTTY: true for prompter-based confirmation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add ParseDiscussionOrCommentArg to the shared package for parsing
discussion numbers, URLs, comment node IDs, and comment URLs
(with #discussioncomment-NNNNN fragments).

Add ResolveCommentNodeID to the client for constructing node IDs from
repository database ID and comment database ID via msgpack encoding.

Update the comment command to accept comment URLs as positional args
for reply, edit, and delete operations. Update the view command to
accept comment URLs in the --replies flag.

Add DiscussionID field to DiscussionComment for reply flow (fetches
the parent discussion ID from a comment).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ests

Update comment acceptance test to use positional comment IDs instead of
--reply-to, and add URL-based add/edit/delete test cases. Update view
acceptance test to cover --replies with a comment URL.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
@babakks babakks marked this pull request as ready for review June 9, 2026 21:26
@babakks babakks requested a review from a team as a code owner June 9, 2026 21:26
@babakks babakks requested review from BagToad and removed request for a team June 9, 2026 21:26

@BagToad BagToad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - discussed in sync and there's some stuff we want to change but I trust you'll action those :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants