Skip to content

[jsweep] Clean add_reaction.cjs#21160

Merged
pelikhan merged 1 commit intomainfrom
jsweep/add-reaction-ceb17e145f62bd5c
Mar 16, 2026
Merged

[jsweep] Clean add_reaction.cjs#21160
pelikhan merged 1 commit intomainfrom
jsweep/add-reaction-ceb17e145f62bd5c

Conversation

@github-actions
Copy link
Contributor

Summary

Cleaned actions/setup/js/add_reaction.cjs as part of the daily JavaScript unbloat process.

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

Changes

add_reaction.cjs

  • Module-level REACTION_MAP constant: Moved the reactionMap object out of addDiscussionReaction() to module level. This avoids re-creating the object on every call and makes it the single source of truth for both reaction validation and GraphQL enum mapping.
  • Single source of truth for validation: main() now derives validReactions from Object.keys(REACTION_MAP) instead of maintaining a separate duplicate array.
  • Template literal for REST request: Changed "POST " + endpoint`POST \$\{endpoint}` in addReaction().
  • Simplified output handling: Collapsed the if/else in addReaction() into two lines using optional chaining (?.) and nullish coalescing (??):
    // Before
    if (reactionId) {
      core.info(`...reaction: \$\{reaction} (id: \$\{reactionId})`);
      core.setOutput("reaction-id", reactionId.toString());
    } else {
      core.info(`...reaction: \$\{reaction}`);
      core.setOutput("reaction-id", "");
    }
    
    // After
    core.info(`...reaction: \$\{reaction}\$\{reactionId ? ` (id: \$\{reactionId})` : ""}`);
    core.setOutput("reaction-id", reactionId?.toString() ?? "");

Test Coverage

The existing add_reaction.test.cjs already has 27 comprehensive tests covering all code paths:

  • Reaction validation (valid/invalid reactions, environment variable)
  • All 6 event types (issues, issue_comment, pull_request, pull_request_review_comment, discussion, discussion_comment)
  • GraphQL reaction mapping for all 8 reaction types
  • Error handling (API errors, locked resources, 403 vs non-403)
  • Output handling (with/without reaction ID)

All 27 tests pass with the changes.

Validation ✅

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npx vitest run add_reaction.test.cjs — 27/27 passed ✓

Generated by jsweep - JavaScript Unbloater ·

Warning

⚠️ Firewall blocked 1 domain

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

  • proxy.golang.org

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

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

  • expires on Mar 18, 2026, 3:24 AM UTC

- Move REACTION_MAP to module level (avoids re-creating on every call)
- Use REACTION_MAP keys for reaction validation (single source of truth)
- Use template literal for REST endpoint: `POST ${endpoint}`
- Simplify addReaction output with optional chaining + nullish coalescing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
Copy link
Contributor

@copilot recompile

Copy link
Contributor

Copilot AI commented Mar 16, 2026

@copilot recompile

Recompiled successfully — all 172 workflow files compiled with no changes (lock files were already up to date).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan March 16, 2026 04:01
@pelikhan pelikhan marked this pull request as ready for review March 16, 2026 04:05
Copilot AI review requested due to automatic review settings March 16, 2026 04:05
@pelikhan pelikhan merged commit b049e6d into main Mar 16, 2026
1 check passed
@pelikhan pelikhan deleted the jsweep/add-reaction-ceb17e145f62bd5c branch March 16, 2026 04:05
Copy link
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 actions/setup/js/add_reaction.cjs to reduce duplication and simplify reaction handling as part of the jsweep cleanup.

Changes:

  • Hoists the REST→GraphQL reaction mapping to a module-level REACTION_MAP and reuses it for validation.
  • Simplifies the REST request string construction and collapses output handling into a single info/output path.
  • Replaces the per-function reaction map in addDiscussionReaction() with REACTION_MAP.

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

You can also share your feedback on Copilot code review. Take the survey.

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.

3 participants