Skip to content

fix(branches): prevent duplicate nop entries for multiple branches#1027

Open
tdabasinskas wants to merge 2 commits into
github-community-projects:main-enterprisefrom
datolabs-io:fix/duplicate-nop-entries
Open

fix(branches): prevent duplicate nop entries for multiple branches#1027
tdabasinskas wants to merge 2 commits into
github-community-projects:main-enterprisefrom
datolabs-io:fix/duplicate-nop-entries

Conversation

@tdabasinskas

@tdabasinskas tdabasinskas commented Jul 11, 2026

Copy link
Copy Markdown

Fixes #1026.

Two changes, one per layer of the bug:

lib/plugins/branches.js

Each .map() callback now collects its NopCommands in its own branchResults array instead of pushing to (and returning) one shared array. The res.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.js

The duplicate filter in handleResults now compares the whole row (endpoint, body, and action included) instead of type/repo/plugin only. 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.

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.
Copilot AI review requested due to automatic review settings July 11, 2026 11:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 handleResults exact-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.

Comment thread lib/settings.js
Comment thread lib/plugins/branches.js
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Branches plugin duplicates every dry-run entry once per configured branch

2 participants