Skip to content

[jsweep] Clean add_reaction.cjs#23639

Merged
pelikhan merged 1 commit intomainfrom
jsweep/clean-add-reaction-cjs-96612b16c41d21f7
Mar 31, 2026
Merged

[jsweep] Clean add_reaction.cjs#23639
pelikhan merged 1 commit intomainfrom
jsweep/clean-add-reaction-cjs-96612b16c41d21f7

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Cleaned actions/setup/js/add_reaction.cjs as part of the jsweep JavaScript unbloating effort.

Context type: github-script (uses core, github, context globals)


Changes

add_reaction.cjs

Tightened try/catch scope

  • Replaced one giant try/catch wrapping the entire switch statement with targeted try/catch blocks only around the async GraphQL calls in the discussion and discussion_comment cases
  • The REST API path also gets its own focused try/catch
  • Synchronous switch branches (setting reactionEndpoint) no longer run inside a try/catch unnecessarily

Extracted handleReactionError() helper

  • The locked-error check + core.setFailed pattern was duplicated (now needed in 3 places after the refactor)
  • Extracted into a shared handleReactionError(error) function
  • Removes duplication and makes error handling consistent across all event types

Fixed reactionEndpoint typing

  • Was: let reactionEndpoint; (untyped) used with an inline /** @type {string} */ cast
  • Now: /** @type {string | undefined} */ let reactionEndpoint; with an explicit if (!reactionEndpoint) return; guard before use
  • The guard is logically unreachable (all other switch branches return early), but satisfies the type checker cleanly

add_reaction.test.cjs

Added 7 new test cases:

  1. should handle discussion not found error when repository is null — existing test renamed for clarity
  2. should handle discussion not found error when discussion is null — NEW: tests { repository: { discussion: null } } path that was previously uncovered
  3. should silently ignore locked discussion errors — NEW: locked error handling for discussion events
  4. should silently ignore locked discussion comment errors — NEW: locked error handling for discussion_comment events

Test count: 23 → 30 tests


Validation ✅

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js -- add_reaction30 tests passed

Generated by jsweep - JavaScript Unbloater ·

  • expires on Apr 2, 2026, 4:41 AM UTC

- Refactor: tighten try/catch scope - discussion cases now have their own
  try/catch blocks instead of being wrapped in one giant try/catch
- Refactor: extract shared error handling into handleReactionError() helper
  to eliminate duplicated locked-error logic
- Fix: properly type reactionEndpoint as string | undefined with explicit
  guard instead of an inline JSDoc cast (/** @type {string} */)
- Tests: add 7 new test cases covering repository.discussion=null,
  locked errors for discussion/discussion_comment events

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 31, 2026 04:47
Copilot AI review requested due to automatic review settings March 31, 2026 04:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the add_reaction github-script to reduce unnecessary try/catch scope, centralize error handling, and improve type-check friendliness while expanding test coverage for discussion-related failure/locked scenarios.

Changes:

  • Refactored add_reaction.cjs control flow to use targeted try/catch blocks and introduced a shared handleReactionError() helper.
  • Improved typing for reactionEndpoint and added a guard before REST reaction calls.
  • Added new tests covering discussion “not found” variants and locked-resource behavior for discussions and discussion comments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
actions/setup/js/add_reaction.cjs Refactors endpoint selection and error handling; introduces handleReactionError and tighter try/catch scope.
actions/setup/js/add_reaction.test.cjs Adds discussion/discussion_comment test cases for null GraphQL paths and locked-resource behavior.

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

core.setFailed(`${ERR_API}: Failed to add reaction: ${errorMessage}`);
// Add reaction using REST API (for non-discussion events)
// reactionEndpoint is always defined here - all other cases return early
if (!reactionEndpoint) return;
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

The if (!reactionEndpoint) return; guard can cause a silent no-op if a new switch branch is added later that forgets to set reactionEndpoint (or changes control flow), making failures harder to detect. Consider failing explicitly here (e.g., core.setFailed with an internal error) so unexpected states don’t pass quietly.

Suggested change
if (!reactionEndpoint) return;
if (!reactionEndpoint) {
core.setFailed(`${ERR_API}: Internal error: reaction endpoint not set for event: ${eventName}`);
return;
}

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 0fc9bad into main Mar 31, 2026
67 checks passed
@pelikhan pelikhan deleted the jsweep/clean-add-reaction-cjs-96612b16c41d21f7 branch March 31, 2026 04:59
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