Skip to content

Safe Settings do not update org Branch Protection Rulesets after created #998

Open

Description

@ddhananjay

Problem Description

Branch Protection Rulesets not getting updated properly

Steps to reproduce:

  1. create an org level ruleset with required reviewers present in ruleset.

  2. Verify ruleset having required reviewers populated

  3. Now go to safe settings file and review required reviewers and push changes to main branch

  4. Verify ruleset is updated

What is the expected behavior

Ruleset get updated, removed required reviewers condition

Error output, if available

Ruleset do not get updated


Context

Are you using the hosted instance of probot/settings or running your own?

If running your own instance, are you using it with github.com or GitHub Enterprise?

Version of probot/settings

Version of GitHub Enterprise

Activity

  1. decyjphr commented on Jun 17, 2026

    @decyjphr
    Collaborator

    The issue is mergeDeep had a bug. Here are the details:

    The Bug

    When you manually removed required_reviewers from a ruleset via the GitHub UI, safe-settings failed to detect the change because the comparison logic in mergeDeep.js was silently ignoring array items without identifying properties (like name, username, etc.).

    What was happening:

    • GitHub state: required_reviewers: [] (empty after manual removal)
    • YAML config: required_reviewers: [{minimum_approvals: 1, file_patterns: ["*.js"], reviewer: {...}}]
    • Result: Comparison returned hasChanges: false ❌

    Root Cause

    In mergeDeep.js, the processArrays() method tracks array items using identifying properties. The required_reviewers objects don't have these properties, so they were never added to the visited object and therefore never compared.

    The Fix

    I modified mergeDeep.js in three places to use JSON.stringify as a fallback identifier when objects lack identifying properties:

    1. In processArrays() (line 206): Changed from silently skipping items to using JSON representation as a unique key
    2. In array comparison filters (lines 225-245): Updated both additions and deletions filters to use the fallback identifier
    3. In compareDeepIfVisited() (line 259): Updated to use the same fallback identifier for consistency

    Verification

    ✅ Created test case: "detects when required_reviewers array changes from populated to empty"
    ✅ Manual testing confirms the fix: comparison now returns hasChanges: true
    ✅ StandardJS linting passed
    ✅ Syntax validation passed

    Files Modified

    • mergeDeep.js - Fixed comparison logic
    • rulesets.test.js - Added regression test

    The fix is general-purpose and will now work for ANY array field where items lack identifying properties, making drift detection more robust across the board.

  2. decyjphr commented on Jun 17, 2026

    @decyjphr
    Collaborator

    @ddhananjay this has been fixed in yadhav/fix-recent-issues branch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions