Skip to content

Fix: prevent unexpected status check contexts deletion for archived repositories#3305

Open
hanyouqing wants to merge 1 commit intointegrations:mainfrom
hanyouqing:fix-unexpected-branch-protection-changes
Open

Fix: prevent unexpected status check contexts deletion for archived repositories#3305
hanyouqing wants to merge 1 commit intointegrations:mainfrom
hanyouqing:fix-unexpected-branch-protection-changes

Conversation

@hanyouqing
Copy link

@hanyouqing hanyouqing commented Mar 25, 2026

Resolves #3306

This PR addresses an issue where archiving a repository would cause Terraform to show a plan diff to delete
the contexts field in github_branch_protection and github_branch_protection_v3 resources, even when status
checks are still active via the newer checks API.


Before the change?

  • REST (v3): When a repository is archived, the GitHub REST API stops returning data in the legacy contexts
    field but continues to return it in the checks array. Since contexts is Computed, the provider detects
    this as a deletion in the state.
  • GraphQL (v4): The contexts field was not marked as Computed, leading to drift detection when it was
    populated by the API but absent from the user's HCL configuration.

After the change?

  1. REST (v3) Fallback: Modified the Read logic in github/resource_github_branch_protection_v3_utils.go to
    automatically populate the contexts state from the checks array if the legacy contexts field is empty.
    This keeps the legacy field in sync with the actual status checks.
  2. GraphQL (v4) Schema Update: Marked the contexts field as Computed: true in
    github/resource_github_branch_protection.go. This prevents Terraform from seeing the field as drift that
    needs to be "corrected" (deleted) when not explicitly specified in the configuration.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@hanyouqing hanyouqing changed the title Fix unexpected changes reported branch protection Fix: prevent unexpected status check contexts deletion for archived repositories Mar 25, 2026
@hanyouqing hanyouqing marked this pull request as ready for review March 25, 2026 09:02
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.

[BUG]: unexpected 'contexts' deletion in github_branch_protection when archiving repository

1 participant