fix(branches): prevent duplicate nop entries for multiple branches#1027
Open
tdabasinskas wants to merge 2 commits into
Open
fix(branches): prevent duplicate nop entries for multiple branches#1027tdabasinskas wants to merge 2 commits into
tdabasinskas wants to merge 2 commits into
Conversation
When running in nop mode with multiple branches configured, the plugin was accumulating NopCommand entries in a shared `resArray` across all branches, causing each branch's planned changes to be duplicated for every subsequent branch processed. Moved the results array from module scope to branch scope so each branch collects its own NopCommand entries independently. Also updated the deduplication logic in `handleResults` to compare the full NopCommand object (endpoint, body, and action) rather than just type/repo/plugin, which was incorrectly treating distinct branch protection changes as duplicates.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses duplicated dry-run (nop) output when multiple branches have planned protection changes, ensuring each planned change is reported exactly once and that only truly identical result rows are deduplicated.
Changes:
- Fix
Branches.sync()nop-mode aggregation so each branch contributes its own result list (avoiding shared-array duplication). - Tighten
Settings.handleResults()deduping to compare full rows (type/repo/plugin + endpoint/body/action) rather than collapsing distinct same-repo/plugin entries. - Add unit tests covering multi-branch nop output and
handleResultsexact-duplicate removal behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/plugins/branches.js | Collect nop results per-branch and flatten, preventing duplicate nop entries across multiple branches. |
| lib/settings.js | Deduplicate nop results by full row content rather than only type/repo/plugin. |
| test/unit/lib/plugins/branches.test.js | Adds a regression test to ensure multi-branch nop mode reports each planned change once. |
| test/unit/lib/settings.test.js | Adds a test ensuring only exact duplicates are removed while distinct entries remain. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace O(n²) array filtering with O(n) Set-based deduplication for better performance when processing large result sets. The previous implementation used nested `findIndex` which became slow with many results. Also add null check to prevent errors when processing undefined results.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1026.
Two changes, one per layer of the bug:
lib/plugins/branches.jsEach
.map()callback now collects its NopCommands in its ownbranchResultsarray instead of pushing to (and returning) one shared array. Theres.flat(2)at the end now flattens disjoint per-branch arrays, so every planned change appears exactly once. No behavior change in apply mode, which never returned the shared array.lib/settings.jsThe duplicate filter in
handleResultsnow compares the whole row (endpoint,body, andactionincluded) instead oftype/repo/pluginonly. It still removes exact duplicates (a safety net), but no longer collapses distinct planned changes for the same repo and plugin — previously a repo with protection changes on two branches reported only one of them. Rendered check-run/PR-comment output stays tidy: rows whose action carries no additions/modifications/deletions were already skipped by the renderers.