Skip to content

[jsweep] Clean add_reaction_and_edit_comment.cjs#30756

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
jsweep/add-reaction-and-edit-comment-b8ed33c4970c1183
Draft

[jsweep] Clean add_reaction_and_edit_comment.cjs#30756
github-actions[bot] wants to merge 1 commit intomainfrom
jsweep/add-reaction-and-edit-comment-b8ed33c4970c1183

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 7, 2026

Summary

Cleaned actions/setup/js/add_reaction_and_edit_comment.cjs as part of the jsweep unbloat initiative.

Changes

Context: github-script

This file runs in the github-script action context with access to core, github, and context globals.

Code Improvements

  • Extracted resolveEventEndpoints() helper — The 90-line switch statement in main() was extracted into a dedicated async function that returns {reactionEndpoint, commentUpdateEndpoint} | null, making main() cleaner and the endpoint logic independently testable
  • Module-level VALID_REACTIONS constant — Moved from inside main() to module scope where it belongs; it never changes between calls
  • Removed redundant if (commentUpdateEndpoint) guard — After the refactored switch, commentUpdateEndpoint is always set (all returning paths are handled by resolveEventEndpoints returning null), so the guard was unnecessary
  • Added Record<string, string> type annotation to EVENT_TYPE_DESCRIPTIONS for clarity
  • Exported resolveEventEndpoints and VALID_REACTIONS to enable direct unit testing

Test Improvements

Added 9 new tests (35 → 44 total):

  • resolveEventEndpoints() for issues, pull_request, issue_comment, pull_request_review_comment, discussion, discussion_comment events
  • resolveEventEndpoints() returns null + calls setFailed when required fields missing
  • resolveEventEndpoints() returns null for unknown event type
  • VALID_REACTIONS exports the expected list

Validation

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js44 tests passed

Generated by jsweep - JavaScript Unbloater · ● 16.2M ·

  • expires on May 9, 2026, 4:54 AM UTC

- Extract large switch statement into resolveEventEndpoints() helper
- Move validReactions to module-level VALID_REACTIONS constant
- Remove redundant if (commentUpdateEndpoint) guard after switch
- Add explicit Record<string, string> type for EVENT_TYPE_DESCRIPTIONS
- Export resolveEventEndpoints and VALID_REACTIONS for direct testing
- Add 9 new tests for resolveEventEndpoints and VALID_REACTIONS (35 → 44)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants