Skip to content

[jsweep] Clean hide_comment.cjs#20754

Merged
pelikhan merged 1 commit intomainfrom
jsweep/hide-comment-cleanup-a3822c62f5e0c5cf
Mar 13, 2026
Merged

[jsweep] Clean hide_comment.cjs#20754
pelikhan merged 1 commit intomainfrom
jsweep/hide-comment-cleanup-a3822c62f5e0c5cf

Conversation

@github-actions
Copy link
Contributor

Summary

Cleaned actions/setup/js/hide_comment.cjs and added a comprehensive test suite.

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

Changes

hide_comment.cjs

  • Removed redundant alias: const item = message was assigned and then used everywhere — replaced with direct message access
  • Inlined reason normalization: Two-step const reason = item.reason || "SPAM"; const normalizedReason = reason.toUpperCase() collapsed into a single expression (message.reason || "SPAM").toUpperCase()
  • No logic changes — all behavior preserved exactly

hide_comment.test.cjs (new file)

  • Created 14 tests covering all code paths:
    • Factory initialization (returns handler, logs config, logs allowed-reasons)
    • Happy path: successful comment hide
    • Default reason (SPAM) when not provided
    • Reason normalization to uppercase
    • Missing comment_id validation
    • Non-string comment_id validation
    • Max count enforcement
    • Allowed-reasons list rejection
    • Case-insensitive allowed-reasons matching
    • GraphQL API error handling
    • isMinimized: false failure case
    • Staged mode preview (no API call)

Validation ✅

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js -- --no-file-parallelism ✓ (14/14 passing)

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 15, 2026, 3:16 AM UTC

- Remove redundant `const item = message` alias, use `message` directly
- Inline `reason` variable into single normalized expression
- Add 14 comprehensive tests covering happy path, error cases,
  staged mode, allowed-reasons validation, and max count enforcement

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 13, 2026 03:26
Copilot AI review requested due to automatic review settings March 13, 2026 03:26
@pelikhan pelikhan merged commit 00137b1 into main Mar 13, 2026
1 check passed
@pelikhan pelikhan deleted the jsweep/hide-comment-cleanup-a3822c62f5e0c5cf branch March 13, 2026 03:26
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

This PR refactors actions/setup/js/hide_comment.cjs for minor cleanup (alias removal and inlining reason normalization) and introduces a new Vitest suite to cover the handler’s behavior end-to-end.

Changes:

  • Simplified hide_comment.cjs by removing a redundant item alias and inlining reason normalization.
  • Added hide_comment.test.cjs with a broad set of unit tests covering success paths, validation, limits, allowed-reason filtering, staged mode, and error handling.

Reviewed changes

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

File Description
actions/setup/js/hide_comment.cjs Refactor to reduce indirection and inline reason normalization while preserving behavior.
actions/setup/js/hide_comment.test.cjs New Vitest suite validating handler factory + execution paths for hide_comment.

💡 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.

Comment on lines +100 to 104
core.warning(`Reason "${message.reason}" is not in allowed-reasons list [${allowedReasons.join(", ")}]. Skipping comment ${commentId}.`);
return {
success: false,
error: `Reason "${reason}" is not in allowed-reasons list`,
error: `Reason "${message.reason}" is not in allowed-reasons list`,
};
Comment on lines +126 to +130
it("should reject reason not in allowed-reasons list", async () => {
const { main } = await loadModule();
const handler = await main({ allowed_reasons: ["SPAM", "ABUSE"] });

const result = await handler({ comment_id: "IC_kwDOABCD123456", reason: "OFF_TOPIC" }, {});
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