Refactor duplicated reaction setup into shared helper#43483
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors duplicated reaction initialization/validation and invocation-context resolution logic used by the setup action scripts into a shared helper, reducing drift risk between the reaction entrypoints.
Changes:
- Added a new
reaction_setup_helpers.cjsmodule that centralizes the reaction allowlist and the “reaction + invocation context” setup logic. - Updated both reaction entrypoints (
add_reaction.cjsandadd_reaction_and_edit_comment.cjs) to use the shared setup helper instead of duplicating setup/validation logic. - Added targeted unit tests for the new helper covering default reaction, env override, and invalid reaction handling.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/reaction_setup_helpers.cjs | Introduces shared reaction setup/validation + invocation-context resolution helper. |
| actions/setup/js/add_reaction.cjs | Refactors reaction-only entrypoint to use the shared setup helper. |
| actions/setup/js/add_reaction_and_edit_comment.cjs | Refactors reaction+comment entrypoint to use the shared setup helper and import the shared allowlist. |
| actions/setup/js/reaction_setup_helpers.test.cjs | Adds unit coverage for shared helper behavior (default, override, invalid). |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Low
| function resolveReactionSetup(rawContext) { | ||
| const reaction = process.env.GH_AW_REACTION || "eyes"; | ||
| const invocationContext = resolveInvocationContext(rawContext); | ||
| if (!VALID_REACTIONS.includes(reaction)) { | ||
| core.setFailed(`${ERR_VALIDATION}: Invalid reaction type: ${reaction}. Valid reactions are: ${VALID_REACTIONS.join(", ")}`); | ||
| return null; | ||
| } | ||
| return { reaction, invocationContext }; | ||
| } |
| it("fails and returns null for invalid reaction", async () => { | ||
| process.env.GH_AW_REACTION = "invalid"; | ||
| const { resolveReactionSetup } = await importHelpers(); | ||
|
|
||
| const result = resolveReactionSetup({ | ||
| eventName: "issues", | ||
| repo: { owner: "testowner", repo: "testrepo" }, | ||
| payload: { issue: { number: 123 } }, | ||
| }); | ||
|
|
||
| expect(result).toBeNull(); | ||
| expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Invalid reaction type: invalid")); | ||
| }); | ||
| }); |
|
@copilot invoke pr-finisher skill |
|
@copilot please run the
|
…ION_MAP sync test Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed both reviewer threads in commit
All 4 unit tests pass locally. |
🤖 PR Triage — Run #7
Score breakdown: impact 16 + urgency 12 + quality 12 Extracts shared
|
The reaction-only and reaction-plus-comment action scripts duplicated the same setup path (read
GH_AW_REACTION, validate allowed reactions, resolve invocation context), creating drift risk between entrypoints. This change consolidates that setup into one helper and keeps each entrypoint focused on its distinct side effects.Problem summary
add_reaction.cjsandadd_reaction_and_edit_comment.cjsimplemented identical reaction initialization/validation/context-resolution logic.Refactor: shared reaction setup
actions/setup/js/reaction_setup_helpers.cjs:VALID_REACTIONSresolveReactionSetup(context)returning{ reaction, invocationContext }ornullaftercore.setFailed(...)eyes)Entrypoint updates
actions/setup/js/add_reaction.cjsresolveReactionSetup(context).actions/setup/js/add_reaction_and_edit_comment.cjsVALID_REACTIONSconstantreaction_setup_helpers.cjs.Targeted coverage
actions/setup/js/reaction_setup_helpers.test.cjsto cover: