Skip to content

feat(discussion): add comment command - #13620

Merged
babakks merged 12 commits into
feature/discussionfrom
babakks/add-discussion-comment
Jun 10, 2026
Merged

babakks merged 12 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
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 :)

babakks and others added 12 commits June 10, 2026 09:32
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>
…ment argument

Drop the --replies flag from gh discussion view and instead accept a
comment URL or comment node ID (DC_*) as the positional argument. A
discussion number, #number, or discussion URL behaves as before, while a
comment reference shows that comment and its replies.

Rework GetCommentReplies to be node-centric: it resolves the parent
discussion directly from the comment node, so it no longer needs the
discussion number or a repository ownership check. The method now takes a
host string instead of a full repository.

Also add a comment mode for --web that resolves and opens the comment URL,
and add godoc to the DiscussionClient interface methods.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
GetComment resolves a comment by its node ID, so it only needs the host
to select the GraphQL endpoint. Change its signature from a full
ghrepo.Interface to a host string and update all callers and tests
accordingly, mirroring GetCommentReplies.

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

Replace --replies usage with a positional comment node ID or URL to match
the redesigned gh discussion view command.

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

In replies mode the --comments flag is meaningless, so reject the
combination with a flag error instead of silently ignoring it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@babakks
babakks force-pushed the babakks/add-discussion-comment branch from a147fed to 8d2b059 Compare June 10, 2026 11:48
@babakks

babakks commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

@BagToad, I've pushed the changes we discussed in sync, and I'll merge this into the feature branch once the CI passes.

@babakks
babakks merged commit 42db02d into feature/discussion Jun 10, 2026
8 checks passed
@babakks
babakks deleted the babakks/add-discussion-comment branch June 10, 2026 11:57
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