Skip to content

Fix suborg-applied settings not removed when targeting rules change#1006

Merged
decyjphr merged 7 commits into
yadhav/fix-recent-issuesfrom
decyjphr-fix-suborg-targeting-removal
Jun 23, 2026
Merged

Fix suborg-applied settings not removed when targeting rules change#1006
decyjphr merged 7 commits into
yadhav/fix-recent-issuesfrom
decyjphr-fix-suborg-targeting-removal

Conversation

@decyjphr

Copy link
Copy Markdown
Collaborator

Problem

When a suborg.yml file changes its targeting rules (suborgrepos, suborgteams, or suborgproperties), repos that no longer match the updated targeting were not having their suborg-applied settings (e.g. rulesets) removed.

This happens because getSubOrgConfigs() only resolves the new targeting, and updateRepos() skips repos not in the current targeting set (subOrgConfigMap check at line 1241). Repos that used to match but no longer match are never processed, so their orphaned rulesets persist.

Note: The case where a repo property changes (causing the repo to drop out of targeting) was already working via the re-evaluation logic. This fix addresses the other case -- when the suborg.yml targeting rules themselves change.

Approach

Load the previous version of changed suborg config files from the base ref, resolve which repos were previously targeted, compare with current targeting, and process removed repos so diffable.sync() detects and removes orphaned settings.

Key design decisions:

  • For push events, payload.before (previous commit SHA) serves as the base ref
  • For PR/NOP events, pull_request.base.ref is already passed as baseRef
  • Previous targeting is resolved using the same mechanisms (API calls for teams/properties, direct matching for repo patterns)
  • Removed repos are processed before the suborg iteration loop, when subOrgConfigMap is not yet set, so the existing skip logic naturally allows them through
  • Removed repos are added to changedRepoNames so NOP filtering correctly includes their results in PR checks

Changes

  • index.js: Pass payload.after/payload.before as ref/baseRef to syncSelectedSettings in the push handler
  • lib/settings.js: Add getReposRemovedFromSubOrgTargeting() to compare old vs new targeting and return dropped repos; add loadYamlFromRef() helper for cache-free ref-specific file loading; update syncSelectedRepos to accept baseRef and process removed repos
  • test/unit/lib/settings.test.js: 7 new tests covering suborgrepos, suborgteams, suborgproperties removal, deduplication, and error handling

When a suborg.yml file changes its targeting rules (suborgrepos,
suborgteams, or suborgproperties), repos that no longer match the
updated targeting were not having their suborg-applied settings
(e.g. rulesets) removed. This happened because getSubOrgConfigs()
only resolves the new targeting, and repos not in the new targeting
were skipped in updateRepos().

Fix: Load the previous version of changed suborg config files from
the base ref (payload.before for push events, pull_request.base.ref
for PR/NOP mode), resolve which repos were previously targeted,
compare with current targeting, and process removed repos so
diffable's sync() detects and removes orphaned rulesets.

Changes:
- index.js: Pass payload.after/payload.before as ref/baseRef to
  syncSelectedSettings in push handler
- lib/settings.js: Add getReposRemovedFromSubOrgTargeting() method
  that compares old vs new targeting to find removed repos
- lib/settings.js: Add loadYamlFromRef() helper to load config
  from a specific git ref without cache interference
- lib/settings.js: Update syncSelectedRepos to accept baseRef,
  identify removed repos, and process them before the suborg loop
- test/unit/lib/settings.test.js: Add tests for targeting removal

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 23, 2026 15:07
@decyjphr decyjphr linked an issue Jun 23, 2026 that may be closed by this pull request

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 aims to ensure that when a suborg config file changes its targeting rules (suborgrepos, suborgteams, suborgproperties), repositories that no longer match are still processed so previously suborg-applied settings (e.g., rulesets) are removed.

Changes:

  • Pass push-event after/before SHAs through the sync path so the previous version of a changed suborg config can be loaded.
  • Add logic to load prior suborg configs from baseRef, compare previous vs current targeting, and process repos dropped from targeting.
  • Add unit tests for dropped-repo detection across suborgrepos, suborgteams, suborgproperties, plus deduping and 404 handling.
Show a summary per file
File Description
index.js Threads push SHAs (payload.after/payload.before) into the selected-settings sync path.
lib/settings.js Introduces previous-targeting comparison (getReposRemovedFromSubOrgTargeting) and a ref-specific YAML loader (loadYamlFromRef); processes removed repos during selected sync.
test/unit/lib/settings.test.js Adds unit coverage for removed-repo detection scenarios and error handling.

Copilot's findings

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread lib/settings.js Outdated
Comment thread test/unit/lib/settings.test.js
decyjphr and others added 6 commits June 23, 2026 11:30
Adds a sub-test to phase 5 that narrows suborg targeting from
suborgteams to suborgrepos (excluding demo-repo-service1), then
verifies the suborg ruleset is removed from the dropped repo while
retained on the still-targeted repo. Restores team-targeted config
afterward for subsequent phases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The plugin was updated to use github.rest.repos.* but the test was
still mocking github.repos.*, causing TypeError failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The implementation now resolves suborgrepos glob patterns against
installation repos via github.paginate(). Updated the tests to mock
paginate returning the repos that match the patterns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When repos are removed from suborg targeting, the rulesets plugin was
never instantiated because returnRepoSpecificConfigs strips 'rulesets'
from org config, and the repo has no suborg/override rulesets section.
Without the plugin, existing suborg-applied rulesets were never removed.

Fix: Track which plugin sections the previous suborg config provided
(e.g. rulesets, teams) and inject them as empty arrays into the merged
config for removed repos. This ensures the plugins are instantiated
and sync() detects/removes existing entries.

Also fix smoke test to use 'test' repo (exists in Phase 1) instead of
'demo-repo-service2' (not created until Phase 7) for the retention
assertion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@decyjphr decyjphr merged commit 4605093 into yadhav/fix-recent-issues Jun 23, 2026
2 checks passed
@decyjphr decyjphr deleted the decyjphr-fix-suborg-targeting-removal branch June 23, 2026 22:44
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.

Repository branch protection ruleset not getting removed

2 participants