Skip to content

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

Open
hanyouqing wants to merge 4 commits intointegrations:mainfrom
hanyouqing:fix-unexpected-branch-protection-changes
Open

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

Conversation

@hanyouqing
Copy link
Copy Markdown

@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
@github-actions github-actions bot added the Type: Bug Something isn't working as documented label Mar 26, 2026
@hanyouqing hanyouqing force-pushed the fix-unexpected-branch-protection-changes branch from 7680c34 to a58deef Compare March 26, 2026 09:38
Copy link
Copy Markdown
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

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

Nice! Left a few change requests :)

@hanyouqing hanyouqing requested a review from deiga March 28, 2026 02:20
@hanyouqing
Copy link
Copy Markdown
Author

Hi @deiga,

PR updated, feel free to take a look. Thanks for your review and suggestion.

@hanyouqing hanyouqing requested a review from deiga March 30, 2026 07:52
@hanyouqing
Copy link
Copy Markdown
Author

Hi @deiga, any more suggestions for this PR?

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

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants