Skip to content

Fix comment creation to post to parent thread instead of replacing comments#1833

Merged
pelikhan merged 5 commits intomainfrom
copilot/remove-comment-editing-feature
Oct 17, 2025
Merged

Fix comment creation to post to parent thread instead of replacing comments#1833
pelikhan merged 5 commits intomainfrom
copilot/remove-comment-editing-feature

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 17, 2025

Problem

The add_reaction_and_edit_comment.cjs script had two critical issues:

  1. Misleading function and variable names that suggested it could edit comments
  2. Bug: Comment creation endpoints were pointing to specific comment IDs, which would replace/update existing comments instead of creating new ones in the thread

Solution

First commit:

  • Removed three lines that set shouldEditComment = true for non-command workflows
  • Line 42: Removed from issues event handler
  • Line 67: Removed from pull_request event handler
  • Line 93: Removed from discussion event handler

Second commit (reverted based on feedback):

  • Initially removed all comment functionality (over-correction)
  • This was reverted as the requirement was to remove EDITING, not CREATION

Third commit (clarification):

  • Renamed addOrEditCommentWithWorkflowLink()addCommentWithWorkflowLink()
  • Renamed shouldEditCommentshouldCreateComment
  • Updated JSDoc comments: "Add or edit a comment" → "Add a comment"
  • Updated log messages: "comment edit" → "comment creation"
  • Updated error messages: "Failed to add/edit comment" → "Failed to create comment"
  • Updated code comments: "Only edit comments" → "Only create comments"

Fourth commit (critical bug fix):

  • Fixed issue_comment event: Changed endpoint from /repos/.../issues/comments/{comment_id} to /repos/.../issues/{issue_number}/comments
  • Fixed pull_request_review_comment event: Changed endpoint from /repos/.../pulls/comments/{comment_id} to /repos/.../issues/{pr_number}/comments
  • Added validation to ensure issue/PR numbers are present in payloads
  • Discussion comments were already correct (using GraphQL addDiscussionComment mutation)

Key Changes

Endpoint Corrections

For issue_comment events:

  • Before: POST /repos/.../issues/comments/{comment_id} - Would update the triggering comment ❌
  • After: POST /repos/.../issues/{issue_number}/comments - Creates new comment on the issue thread ✅

For pull_request_review_comment events:

  • Before: POST /repos/.../pulls/comments/{review_comment_id} - Would update the triggering review comment ❌
  • After: POST /repos/.../issues/{pr_number}/comments - Creates new comment on the PR thread ✅

For discussion_comment events:

  • Already correct - uses GraphQL addDiscussionComment mutation ✅

Behavior Change

Before:

  • Added reactions to issues, PRs, comments, and discussions ✅
  • Created comments for command workflows AND non-command workflows ❌
  • Function/variable names incorrectly suggested editing capability ❌
  • Comment creation endpoints would replace/update existing comments

After:

  • Adds reactions to issues, PRs, comments, and discussions ✅
  • Creates comments ONLY for command workflows (when GITHUB_AW_COMMAND is set) ✅
  • Function/variable names accurately reflect comment creation (not editing) ✅
  • Comment creation endpoints correctly create NEW comments in parent threads

Testing

All 534 JavaScript tests pass ✅

Files Changed

  • pkg/workflow/js/add_reaction_and_edit_comment.cjs - Renamed functions/variables, fixed comment creation endpoints, added validation
  • pkg/workflow/js/add_reaction_and_edit_comment.test.cjs - Updated test expectations for corrected endpoints
Original prompt

The add reaction eyes JavaScript should not edit comments anymore, it should only add new ones.

Find occurences of this code which show that there are still code path updating the comments.

shouldEditComment = true;


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Oct 17, 2025
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove ability to edit comments in add reaction eyes JavaScript Remove shouldEditComment = true for non-command workflows Oct 17, 2025
Copilot AI requested a review from pelikhan October 17, 2025 04:16
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot we should never edit a comment anymore. remove entirely

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed comment editing functionality entirely. Commit: 9a4c1b7

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Remove shouldEditComment = true for non-command workflows Remove comment editing functionality entirely from add_reaction_and_edit_comment.cjs Oct 17, 2025
Copilot AI requested a review from pelikhan October 17, 2025 04:34
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot revert the last changes. The requirement is to remove code comment UPDATES and only do comment CREATE.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 17, 2025

@copilot revert the last changes. The requirement is to remove code comment UPDATES and only do comment CREATE.

Reverted to only create comments (never edit). The code was already only creating comments - renamed functions/variables to clarify this. Commit: 0c8df45

Copilot AI changed the title Remove comment editing functionality entirely from add_reaction_and_edit_comment.cjs Remove comment editing from add_reaction_and_edit_comment.cjs, keep comment creation Oct 17, 2025
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot the current code replaces the content of existing comments. If the event is an issue comment, you need to create a new comment on the issue itself. And so forth for all the events. Review each event and update the logic to create/add a comment to the thread it belongs to.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 17, 2025

@copilot the current code replaces the content of existing comments. If the event is an issue comment, you need to create a new comment on the issue itself. And so forth for all the events. Review eac...

Fixed endpoints to create new comments on parent threads. For issue_comment and pull_request_review_comment events, now posts to the issue/PR comments endpoint instead of the specific comment endpoint. Discussion comments were already correct. Commit: ea9c2b8

Copilot AI changed the title Remove comment editing from add_reaction_and_edit_comment.cjs, keep comment creation Fix comment creation to post to parent thread instead of replacing comments Oct 17, 2025
@pelikhan pelikhan marked this pull request as ready for review October 17, 2025 05:07
@pelikhan pelikhan merged commit 9b23d40 into main Oct 17, 2025
5 checks passed
@pelikhan pelikhan deleted the copilot/remove-comment-editing-feature branch October 17, 2025 05:07
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