refactor(reactions): clean up GitHub reactions code #581
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.
Closes #539
Applied changes based on Issue #539.
I’ve refactored src/github/reactions.ts to eliminate the repetitive branching logic in the three export functions and centralized the endpoint selection into a single helper. Here’s what changed:
1. Introduced
getReactionHandlers
A new function at the top that, based on the incoming
GitHubEvent
, returns a uniform handler object:This replaces the three scattered
if/else
blocks across add/remove functions.2. Simplified
addEyeReaction
Before: three separate
if
blocks to choose issue vs. comment vs. review‑comment.After: one call to
getReactionHandlers(...)
, then a single.create('eyes')
plus logging.3. Simplified
removeEyeReaction
Before: three loops over
listFor*
results with inline endpoint selection.After: one
handler.list()
, then a.find(…)
and.delete(reaction.id)
if it’s the bot’s “eyes” reaction.4. Simplified
addThumbUpReaction
Now just calls
removeEyeReaction
, reuses the same handler helper, and.create('+1')
.These changes preserve all original behavior while improving readability, reducing duplication, and making it easy to extend or adjust reaction logic in a single place.
Ready for review.