Skip to content

[code-simplifier] refactor(js): derive VALID_REACTIONS from REACTION_MAP to eliminate duplication#43929

Merged
pelikhan merged 1 commit into
mainfrom
simplify/deduplicate-valid-reactions-constant-50317607af167e11
Jul 7, 2026
Merged

[code-simplifier] refactor(js): derive VALID_REACTIONS from REACTION_MAP to eliminate duplication#43929
pelikhan merged 1 commit into
mainfrom
simplify/deduplicate-valid-reactions-constant-50317607af167e11

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

Summary

Refactors reaction validation in two JavaScript CJS modules to derive VALID_REACTIONS from REACTION_MAP, eliminating a hardcoded duplicate list.

Changes

actions/setup/js/add_reaction.cjs

  • Removes the intermediate validReactions local variable.
  • Replaces validReactions.includes(reaction) with Object.prototype.hasOwnProperty.call(REACTION_MAP, reaction) — a prototype-safe property lookup.
  • Inlines Object.keys(REACTION_MAP).join(", ") directly in the validation error message.

actions/setup/js/add_reaction_and_edit_comment.cjs

  • Imports REACTION_MAP from ./add_reaction.cjs.
  • Replaces the hardcoded frozen array with the derived form:
    const VALID_REACTIONS = Object.freeze(Object.keys(REACTION_MAP));

Impact

  • No behavioral change. Valid reactions are still the same set.
  • Single source of truth: REACTION_MAP in add_reaction.cjs is now the sole authoritative definition; all validation derives from it automatically.
  • Eliminates the risk of the two lists drifting out of sync if reactions are added or removed.

Files Changed

File Type
actions/setup/js/add_reaction.cjs Refactor
actions/setup/js/add_reaction_and_edit_comment.cjs Refactor

Commits

  • 6edbd5457 refactor(js): derive VALID_REACTIONS from REACTION_MAP to remove duplication

Generated by PR Description Updater for #43929 · 31.4 AIC · ⌖ 6.2 AIC · ⊞ 4.7K ·

…ication

- add_reaction_and_edit_comment.cjs: remove hardcoded VALID_REACTIONS array
  and derive it from the exported REACTION_MAP from add_reaction.cjs.
  This eliminates a duplicate list that could drift out of sync.
- add_reaction.cjs: remove transient validReactions local variable;
  validate directly against REACTION_MAP using hasOwnProperty.

Behavior is unchanged — key order is preserved (insertion order matches
the original frozen array), and all 105 JS tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review July 7, 2026 06:05
Copilot AI review requested due to automatic review settings July 7, 2026 06:05
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #43929 does not have the 'implementation' label and has 0 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

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 removes duplication in the GitHub Actions JS “reaction” helpers by deriving the set of valid reaction strings from the existing REACTION_MAP, ensuring a single source of truth and reducing drift risk.

Changes:

  • Simplified reaction validation in add_reaction.cjs by checking membership directly against REACTION_MAP.
  • Refactored add_reaction_and_edit_comment.cjs to derive VALID_REACTIONS from REACTION_MAP instead of maintaining a separate hardcoded list.
Show a summary per file
File Description
actions/setup/js/add_reaction.cjs Uses REACTION_MAP key presence for validation and derives the “valid reactions” list directly from the map for error messaging.
actions/setup/js/add_reaction_and_edit_comment.cjs Removes hardcoded VALID_REACTIONS values and derives them from REACTION_MAP to prevent drift.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@github-actions github-actions Bot mentioned this pull request Jul 7, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The refactoring is correct and safe. Both changes are semantically equivalent to the originals while eliminating duplication. REACTION_MAP is properly exported and imported, hasOwnProperty.call is a clean validation pattern, and Object.freeze(Object.keys(REACTION_MAP)) preserves the original frozen-array contract. No issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 20.5 AIC · ⌖ 5.95 AIC · ⊞ 4.9K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Approved - Clean deduplication with no behavioral changes. Both changes achieve a single source of truth for reaction validation. No correctness, security, or performance issues found.

🔎 Code quality review by PR Code Quality Reviewer · 40.9 AIC · ⌖ 5.08 AIC · ⊞ 5.5K
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /codebase-design and /tdd — two minor suggestions, no blocking issues.

📋 Key Themes & Highlights

Key Themes

  • Style inconsistency: add_reaction.cjs now uses Object.prototype.hasOwnProperty.call while add_reaction_and_edit_comment.cjs uses Array.includes. Object.hasOwn would be the cleaner, consistent choice for the map-based check.
  • Test still documents old shape: The existing VALID_REACTIONS test asserts a hard-coded array rather than asserting the derivation relationship introduced by this PR.

Positive Highlights

  • ✅ Excellent DRY improvement — REACTION_MAP is the true source of truth and the PR correctly centralises it.
  • ✅ Exporting REACTION_MAP from add_reaction.cjs is the right seam; keeps the single source in the module that owns the map.
  • ✅ 105 tests passing; PR scope is tight and the description is thorough.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 73.3 AIC · ⌖ 6.95 AIC · ⊞ 6.7K
Comment /matt to run again

Comment thread actions/setup/js/add_reaction.cjs
Comment thread actions/setup/js/add_reaction_and_edit_comment.cjs
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for this tidy cleanup from the Code Simplifier! Deriving VALID_REACTIONS from REACTION_MAP via Object.freeze(Object.keys(REACTION_MAP)) is a solid DRY improvement that removes the drift risk between the hardcoded array and the map.

One small gap to address before merge:

  • No test file changes in the diff — the PR body reports 105 existing tests passing, which is great, but neither add_reaction.test.cjs nor add_reaction_and_edit_comment.test.cjs were modified. Since add_reaction.cjs now uses Object.prototype.hasOwnProperty.call(REACTION_MAP, reaction) instead of validReactions.includes(reaction), it's worth adding at least one explicit test case that confirms an invalid reaction is rejected under the new validation path, and that the error message still lists all valid reactions correctly.

If you'd like a hand, you can assign this prompt to your coding agent:

In the test files for the add_reaction action, add targeted test cases to cover the refactored validation path introduced in PR #43929:

1. In `actions/setup/js/add_reaction.test.cjs`: add a test that passes an invalid reaction type and asserts that `core.setFailed` is called with a message containing the valid reactions list (derived from `REACTION_MAP`). Confirm the existing passing tests still pass.

2. In `actions/setup/js/add_reaction_and_edit_comment.test.cjs`: add a test that verifies `VALID_REACTIONS` matches `Object.keys(REACTION_MAP)` exactly, ensuring the derived constant stays in sync.

Do not change any production code — only add test cases.

Warning

Firewall blocked 1 domain

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

  • patchdiff.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "patchdiff.githubusercontent.com"

See Network Configuration for more information.

Generated by ✅ Contribution Check · 261.8 AIC · ⌖ 15.6 AIC · ⊞ 6.2K ·

@pelikhan
pelikhan merged commit cc7b2db into main Jul 7, 2026
61 of 68 checks passed
@pelikhan
pelikhan deleted the simplify/deduplicate-valid-reactions-constant-50317607af167e11 branch July 7, 2026 07:45
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.82.3

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