Skip to content

Conversation

github-actions[bot]
Copy link

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:

  • create(content: string) — invokes the correct “create reaction” endpoint
  • list() — lists existing reactions on the target
  • delete(reaction_id: number) — deletes a reaction by ID (with a fallback for review comments)
  • logTarget — human‑readable target description for logging

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.

@YiweiShen YiweiShen merged commit dff3676 into main Jul 26, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-chore-539-refactor-reactions-clean-up-github-reactions-code-3121099049 branch July 26, 2025 03:32
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.

[Done] Refactor src/github/reactions.ts

1 participant