Skip to content

[code-simplifier] Simplify close safe-output handlers#15504

Merged
pelikhan merged 2 commits intomainfrom
code-simplifier-20260213-ebeca609d995e9ba
Feb 13, 2026
Merged

[code-simplifier] Simplify close safe-output handlers#15504
pelikhan merged 2 commits intomainfrom
code-simplifier-20260213-ebeca609d995e9ba

Conversation

@github-actions
Copy link
Contributor

Code Simplification - 2026-02-13

This PR simplifies recently modified JavaScript code to improve clarity, consistency, and maintainability while preserving all functionality.

Files Simplified

  • actions/setup/js/close_pull_request.cjs - Simplified imports and function structure
  • actions/setup/js/close_entity_helpers.cjs - Simplified conditional logic and function chaining

Improvements Made

  1. Reduced Complexity

    • Moved inline require() statements to top of file (consistent with project patterns)
    • Used single-line early returns for clearer control flow
    • Simplified buildCommentBody with expression chaining
  2. Enhanced Clarity

    • Updated JSDoc comments to explicitly mention "no filter" behavior
    • Removed unnecessary intermediate variables
    • Made early-return pattern consistent across filter functions
  3. Applied Project Standards

    • Followed consistent import style (top-level requires)
    • Used early returns for guard clauses
    • Maintained explicit JSDoc documentation

Changes Based On

Recent changes from:

Code Reduction

  • Before: 43 lines across both files
  • After: 28 lines across both files
  • Reduction: 15 lines (-35%) while maintaining identical functionality

Testing

  • ✅ JavaScript formatting passes (make fmt-cjs)
  • ✅ Linting passes (make lint-cjs)
  • ✅ No functional changes - behavior is identical
  • ✅ All type definitions preserved

Review Focus

Please verify:

  • Functionality is preserved (early returns behave identically)
  • Expression chaining in buildCommentBody is readable
  • Import consolidation doesn't affect module loading
  • JSDoc comments accurately reflect behavior

Technical Details

Import Consolidation (close_pull_request.cjs):

// Before: Inline requires in buildCommentBody function
function buildCommentBody(...) {
  const { getTrackerID } = require("./get_tracker_id.cjs");
  const { generateFooter } = require("./generate_footer.cjs");
  // ...
}

// After: Top-level imports
const { getTrackerID } = require("./get_tracker_id.cjs");
const { generateFooter } = require("./generate_footer.cjs");

Early Return Pattern:

// Before
if (requiredLabels.length === 0) {
  return true;
}

// After
if (requiredLabels.length === 0) return true;

Expression Chaining:

// Before
let commentBody = body.trim();
commentBody += getTrackerID("markdown");
commentBody += generateFooter(...);
return commentBody;

// After
return body.trim() + getTrackerID("markdown") + generateFooter(...);

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

AI generated by Code Simplifier

  • expires on Feb 14, 2026, 8:08 PM UTC

- Move requires to top of file instead of inline
- Use single-line early returns for clarity
- Simplify buildCommentBody with expression chaining
- Update JSDoc comments to reflect no-filter behavior
- Reduce code by 15 lines while preserving functionality
@pelikhan pelikhan marked this pull request as ready for review February 13, 2026 20:16
Copilot AI review requested due to automatic review settings February 13, 2026 20:16
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 the close safe-output JavaScript handlers to reduce boilerplate and standardize patterns (imports, guard clauses, and comment-body construction) while keeping behavior the same as the recent “comment even if already closed” update.

Changes:

  • Hoists getTrackerID / generateFooter imports to the module top in close_pull_request.cjs (removing inline require() calls).
  • Simplifies filter helpers (checkLabelFilter, checkTitlePrefixFilter) using consistent early-return guard clauses and updates JSDoc to reflect “no filter” behavior.
  • Simplifies buildCommentBody in both files by returning a single concatenated expression.

Reviewed changes

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

File Description
actions/setup/js/close_pull_request.cjs Consolidates imports and simplifies filter helpers + comment body construction.
actions/setup/js/close_entity_helpers.cjs Applies the same simplifications for shared helper logic (filters + comment body).

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

@pelikhan pelikhan merged commit df83a53 into main Feb 13, 2026
51 checks passed
@pelikhan pelikhan deleted the code-simplifier-20260213-ebeca609d995e9ba branch February 13, 2026 20:22
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