Skip to content

[code-simplifier] simplify: extract update_branch via destructuring in update_pull_request.cjs#27281

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
code-simplifier/update-pr-destructuring-2026-04-20-668f8e98b739a726
Draft

[code-simplifier] simplify: extract update_branch via destructuring in update_pull_request.cjs#27281
github-actions[bot] wants to merge 1 commit intomainfrom
code-simplifier/update-pr-destructuring-2026-04-20-668f8e98b739a726

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

This PR simplifies recently modified code from PR #27244 to improve clarity and eliminate post-destructuring mutation.

Files Simplified

  • actions/setup/js/update_pull_request.cjs — extract update_branch in the initial destructuring to avoid a delete mutation on apiData

Improvements Made

Eliminated Post-Destructuring Mutation

The update_branch field added in #27244 was extracted from updateData in two steps: first via spread into apiData, then separately deleted with delete apiData.update_branch. This is a code smell — it mutates the object after construction.

Before:

// Remove internal fields
const { _operation, _rawBody, _includeFooter, _workflowRepo, ...apiData } = updateData;
const updateBranch = apiData.update_branch === true;
delete apiData.update_branch;

After:

// Remove internal fields (including update_branch which is handled separately below)
const { _operation, _rawBody, _includeFooter, _workflowRepo, update_branch, ...apiData } = updateData;
const updateBranch = update_branch === true;

The destructuring already extracted all the other internal fields; adding update_branch to that same pattern is consistent, eliminates the mutation, and makes the intent clearer.

Changes Based On

Recent changes from:

Testing

  • ✅ Prettier formatting check passes (npx prettier --check update_pull_request.cjs)
  • ✅ Logic is functionally equivalent — behavior is identical
  • ✅ No other files changed

Review Focus

Please verify:

  • Functionality is preserved (both approaches produce the same apiData without update_branch, and the same boolean updateBranch)
  • The simplification aligns with the project's destructuring convention for stripping internal fields

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

Note

🔒 Integrity filter blocked 1 item

The following item was blocked because it doesn't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Code Simplifier · ● 2.7M ·

  • expires on Apr 21, 2026, 6:32 AM UTC

…ation

Removes the need for post-destructuring mutation by including update_branch
in the initial destructuring of updateData, keeping apiData clean from the start.

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

Hey @github-actions[bot] 👋 — nice cleanup! Eliminating the post-destructuring delete apiData.update_branch mutation in update_pull_request.cjs is a clean improvement — it's more idiomatic JS and keeps the destructuring pattern consistent with how the other internal fields are already stripped.

One thing to address before this is ready for merge:

  • Add or update tests — the diff doesn't touch any test files. Even though the logic is functionally equivalent, a regression test (or a check in an existing test) that asserts apiData does not contain update_branch and that updateBranch is set correctly would make the equivalence explicit and guard against future regressions.

If you'd like a hand, you can assign this prompt to your coding agent:

Add or update tests for the `executePRUpdate` function in `actions/setup/js/update_pull_request.cjs`.

Specifically, verify that after the refactored destructuring:
1. `apiData` does NOT contain an `update_branch` key.
2. `updateBranch` is `true` when `updateData.update_branch === true`.
3. `updateBranch` is `false` when `updateData.update_branch` is absent or falsy.

Place the tests in the appropriate test file alongside the existing tests for this module.

Generated by Contribution Check · ● 1.7M ·

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.

0 participants