Skip to content

Commit 6edbd54

Browse files
refactor(js): derive VALID_REACTIONS from REACTION_MAP to remove duplication
- 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>
1 parent 23829db commit 6edbd54

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

actions/setup/js/add_reaction.cjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ async function main() {
3030
core.info(`Adding reaction: ${reaction}`);
3131

3232
// Validate reaction type
33-
const validReactions = Object.keys(REACTION_MAP);
34-
if (!validReactions.includes(reaction)) {
35-
core.setFailed(`${ERR_VALIDATION}: Invalid reaction type: ${reaction}. Valid reactions are: ${validReactions.join(", ")}`);
33+
if (!Object.prototype.hasOwnProperty.call(REACTION_MAP, reaction)) {
34+
core.setFailed(`${ERR_VALIDATION}: Invalid reaction type: ${reaction}. Valid reactions are: ${Object.keys(REACTION_MAP).join(", ")}`);
3635
return;
3736
}
3837

actions/setup/js/add_reaction_and_edit_comment.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { ERR_API, ERR_NOT_FOUND, ERR_VALIDATION } = require("./error_codes.cjs");
99
const { buildWorkflowRunUrl } = require("./workflow_metadata_helpers.cjs");
1010
const { createDiscussionComment, resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs");
1111
const { resolveInvocationContext } = require("./invocation_context_helpers.cjs");
12-
const { addReaction, addDiscussionReaction, getDiscussionNodeId } = require("./add_reaction.cjs");
12+
const { addReaction, addDiscussionReaction, getDiscussionNodeId, REACTION_MAP } = require("./add_reaction.cjs");
1313

1414
/**
1515
* Event type descriptions for comment messages
@@ -25,7 +25,7 @@ const EVENT_TYPE_DESCRIPTIONS = {
2525
};
2626

2727
/** Valid GitHub reaction types */
28-
const VALID_REACTIONS = Object.freeze(["+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", "eyes"]);
28+
const VALID_REACTIONS = Object.freeze(Object.keys(REACTION_MAP));
2929

3030
/**
3131
* Resolve the reaction and comment API endpoints for a given event.

0 commit comments

Comments
 (0)