Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Feb 2, 2026

Summary

Cleaned and modernized close_discussion.cjs by removing unnecessary code, optimizing performance, and adding comprehensive test coverage.

Context

This file runs in github-script context with access to github, core, and context globals.

Changes Made

Code Improvements

  1. Removed unnecessary intermediate variable: Eliminated const item = message assignment
  2. Simplified discussion number extraction: Used ternary operators to combine validation and assignment in one expression
  3. Optimized label validation: Used Set instead of array.includes() for O(1) lookup performance (previously O(n))
  4. Used modern JavaScript patterns:
    • Nullish coalescing (??) for reason parameter instead of logical OR
    • Object property shorthand for commentUrl return value
  5. Eliminated redundant variable: Removed closedDiscussion variable and used discussion.url directly
  6. Reduced code duplication: Extracted error message to variable to avoid duplicating strings

Test Coverage

Created comprehensive test suite with 15 test cases covering:

  • ✅ Close with explicit discussion number
  • ✅ Close from context payload
  • ✅ Close with comment
  • ✅ Close with reason (RESOLVED, DUPLICATE, OUTDATED, ANSWERED)
  • ✅ Missing discussion number errors
  • ✅ Invalid discussion number handling
  • ✅ Max count limit enforcement
  • ✅ Required labels validation (missing and present)
  • ✅ Required title prefix validation (missing and present)
  • ✅ GraphQL error handling
  • ✅ Label pagination (100+ labels)
  • ✅ Discussion not found errors
  • ✅ Nullish coalescing behavior for undefined/null reason

Validation Checks

All validation checks passed successfully:

  • Formatting: npm run format:cjs - All files formatted correctly
  • Linting: npm run lint:cjs - No linting errors
  • Type checking: npm run typecheck - No type errors
  • Tests: npm run test:js - 15/15 tests passed (100%)

Impact

  • Performance: Label validation now O(1) instead of O(n) using Set
  • Maintainability: Reduced code verbosity and improved readability
  • Quality: Added comprehensive test coverage (previously had no tests)
  • Safety: All functionality preserved, type checking passes

AI generated by jsweep - JavaScript Unbloater

  • expires on Feb 4, 2026, 3:10 PM UTC

- Simplified discussion number extraction with ternary operators
- Optimized label validation using Set for O(1) lookup
- Used nullish coalescing (??) and object property shorthand
- Removed unnecessary intermediate variables
- Created comprehensive test suite with 15 test cases
- All validation checks passed (format, lint, typecheck, tests)
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.

1 participant