Skip to content

[jsweep] Clean add_reaction_and_edit_comment.cjs - #18252

Merged
pelikhan merged 1 commit into
mainfrom
jsweep/clean-add-reaction-and-edit-comment-319175b9e7077d79
Feb 25, 2026
Merged

[jsweep] Clean add_reaction_and_edit_comment.cjs#18252
pelikhan merged 1 commit into
mainfrom
jsweep/clean-add-reaction-and-edit-comment-319175b9e7077d79

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Cleaned and modernized add_reaction_and_edit_comment.cjs (github-script context).

Changes

add_reaction_and_edit_comment.cjs

  • Added {} blocks to switch cases — all case clauses with const declarations now have proper block scope, eliminating lexical declaration scope issues
  • Extracted EVENT_TYPE_DESCRIPTIONS lookup object — replaced a verbose switch statement in addCommentWithWorkflowLink with a single-line lookup, matching the pattern already used in add_workflow_run_comment.cjs
  • Removed unused getDiscussionCommentId function — dead code that was never called anywhere
  • Extracted setCommentOutputs helper — eliminates ~8 lines of duplicated core.info/core.setOutput code that appeared in 3 places
  • Reuse getDiscussionId in addCommentWithWorkflowLink — removed duplicate inline GraphQL queries for discussion events; now calls the existing helper
  • Exported addCommentWithWorkflowLink, addReaction, addDiscussionReaction — enables direct unit testing without eval

add_reaction_and_edit_comment.test.cjs

Complete rewrite of the test file:

  • Removed eval-based test execution — tests now use dynamic imports (import("./...cjs?" + Date.now())) matching the pattern in newer test files
  • Fixed badly minified/comma-chained code — rewrote all tests with proper function bodies and readable structure
  • Use vi.resetAllMocks() instead of vi.clearAllMocks() — prevents mock queue leakage between tests
  • 28 comprehensive tests covering:
    • All 6 event types: issues, issue_comment, pull_request, pull_request_review_comment, discussion, discussion_comment
    • All 8 GraphQL reaction type mappings
    • Lock notice behavior
    • Workflow-id and tracker-id markers
    • Error handling (403 locked, non-locked 403, 500 errors)
    • Missing payload field validation
    • Direct testing of exported functions (addReaction, addDiscussionReaction, addCommentWithWorkflowLink)

Context: github-script (uses core, github, context globals)

Validation ✅

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: all 28 tests pass (npm run test:js) ✓

Generated by jsweep - JavaScript Unbloater

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org
  • expires on Feb 27, 2026, 3:28 AM UTC

- Add {} blocks to all switch cases with const declarations
- Extract EVENT_TYPE_DESCRIPTIONS lookup object (replaces switch in addCommentWithWorkflowLink)
- Remove unused getDiscussionCommentId function
- Extract setCommentOutputs helper to eliminate duplicate output code
- Reuse getDiscussionId in addCommentWithWorkflowLink instead of duplicating GraphQL queries
- Export addCommentWithWorkflowLink, addReaction, addDiscussionReaction for testing

Test improvements:
- Rewrite test file from eval-based/minified code to proper dynamic imports
- Use vi.resetAllMocks() for clean state between tests
- Add 28 comprehensive tests covering all event types and edge cases
- Test exported functions directly instead of via eval

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review February 25, 2026 04:33
Copilot AI review requested due to automatic review settings February 25, 2026 04:33
@pelikhan
pelikhan merged commit 6d2b6b1 into main Feb 25, 2026
@pelikhan
pelikhan deleted the jsweep/clean-add-reaction-and-edit-comment-319175b9e7077d79 branch February 25, 2026 04:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the add_reaction_and_edit_comment.cjs github-script by removing dead code, reducing duplication, and making key helpers directly testable, along with a full rewrite of the associated test suite to avoid eval and improve coverage/readability.

Changes:

  • Refactors the reaction/comment script with scoped switch cases, shared helpers (EVENT_TYPE_DESCRIPTIONS, setCommentOutputs), and exports for unit testing.
  • Removes unused discussion-comment helper logic and reuses getDiscussionId() for discussion comment creation.
  • Rewrites tests to use dynamic imports (cache-busting) and adds broader coverage across event types, reactions, markers, and error handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
actions/setup/js/add_reaction_and_edit_comment.cjs Refactors reaction/comment creation logic, reduces duplication, and exports functions for direct testing.
actions/setup/js/add_reaction_and_edit_comment.test.cjs Replaces eval-based tests with dynamic-import tests and expands coverage across events and error scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 356 to 374
@@ -450,13 +374,7 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName) {
);

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

addCommentWithWorkflowLink() relies on context.payload.comment.node_id for the discussion_comment path but doesn’t validate it before passing it as replyToId. Since the function is now exported (and can be called directly in unit tests/other modules), callers can easily trigger a GraphQL request with replyToId: undefined, yielding a confusing API error. Consider validating commentNodeId (and that the discussion number parsed from endpoint is a real number) and returning/logging a clear ERR_NOT_FOUND/validation message before making the GraphQL request.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants