[jsweep] Clean add_reaction_and_edit_comment.cjs#30756
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[jsweep] Clean add_reaction_and_edit_comment.cjs#30756github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cleaned
actions/setup/js/add_reaction_and_edit_comment.cjsas part of the jsweep unbloat initiative.Changes
Context: github-script
This file runs in the
github-scriptaction context with access tocore,github, andcontextglobals.Code Improvements
resolveEventEndpoints()helper — The 90-line switch statement inmain()was extracted into a dedicated async function that returns{reactionEndpoint, commentUpdateEndpoint} | null, makingmain()cleaner and the endpoint logic independently testableVALID_REACTIONSconstant — Moved from insidemain()to module scope where it belongs; it never changes between callsif (commentUpdateEndpoint)guard — After the refactored switch,commentUpdateEndpointis always set (all returning paths are handled byresolveEventEndpointsreturningnull), so the guard was unnecessaryRecord<string, string>type annotation toEVENT_TYPE_DESCRIPTIONSfor clarityresolveEventEndpointsandVALID_REACTIONSto enable direct unit testingTest Improvements
Added 9 new tests (35 → 44 total):
resolveEventEndpoints()forissues,pull_request,issue_comment,pull_request_review_comment,discussion,discussion_commenteventsresolveEventEndpoints()returnsnull+ callssetFailedwhen required fields missingresolveEventEndpoints()returnsnullfor unknown event typeVALID_REACTIONSexports the expected listValidation
npm run format:cjs✓npm run lint:cjs✓npm run typecheck✓npm run test:js— 44 tests passed ✓