Skip to content

fix: Correct repo vulnerability alert logic - #3144

Merged
stevehipwell merged 1 commit into
integrations:mainfrom
stevehipwell:fix-repo-vulnerability-alerts
Feb 3, 2026
Merged

stevehipwell merged 1 commit into
integrations:mainfrom
stevehipwell:fix-repo-vulnerability-alerts

Conversation

@stevehipwell

Copy link
Copy Markdown
Collaborator

Corrects logic in #3127


Before the change?

  • Resource github_repository would call vulnerability alerts endpoint on every modification
  • Resource github_repository used ignore_vulnerability_alerts_during_read to allow unprivileged users to skip calling the vulnerability alerts endpoint

After the change?

  • Resource github_repository only calls vulnerability alerts endpoint when required
  • Resource github_repository only calls vulnerability alerts endpoint during read if the repo response show that the user has the correct permission

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

@stevehipwell stevehipwell added this to the v6.11.0 Release milestone Jan 30, 2026
@stevehipwell stevehipwell self-assigned this Jan 30, 2026
@stevehipwell stevehipwell added the Type: Bug Something isn't working as documented label Jan 30, 2026
@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@stevehipwell
stevehipwell force-pushed the fix-repo-vulnerability-alerts branch from 8693117 to c92ee2b Compare February 3, 2026 13:48
@stevehipwell
stevehipwell enabled auto-merge (squash) February 3, 2026 13:49
@stevehipwell
stevehipwell merged commit 2c8e72a into integrations:main Feb 3, 2026
7 checks passed
@stevehipwell
stevehipwell deleted the fix-repo-vulnerability-alerts branch February 3, 2026 14:00
JiayangZhou pushed a commit to JiayangZhou/terraform-provider-github that referenced this pull request Apr 16, 2026
th7 added a commit to th7/terraform-provider-github that referenced this pull request Aug 1, 2026
GitHub omits merge-related settings from the repository object unless
the caller has push or admin access: "To view merge-related settings,
you must have the contents:read and contents:write permissions." It
omits fields for archived repositories too.

Read through a Get* accessor, an omitted field yields the zero value,
which is indistinguishable from the field genuinely being false or
empty. Writing that to state produces a diff on every plan that no
apply can resolve, because the value an apply would write back is not
readable either. Setting only what the response actually contained
leaves prior state in place instead.

That is what the archived special-case was reaching for; a presence
check covers both causes, so the branch is gone, and with it the TODO
questioning whether those fields really are omitted for archived
repositories. integrations#3144 took the same approach for vulnerability_alerts
and security_and_analysis.

The cost is that drift in those fields goes undetected while the token
cannot read them, which is preferable to a permanent diff no apply can
clear.

Verified with a scoped installation token holding administration:read
and contents:read against a configuration managing nine repositories:
every one reported the diff on every plan before, none do after.
Reverting to the released provider reproduces it, so the binary is the
only variable.

Refs integrations#3382
th7 added a commit to th7/terraform-provider-github that referenced this pull request Aug 8, 2026
GitHub omits merge-related settings from the repository object unless the
caller has push or admin access: "To view merge-related settings, you must
have the contents:read and contents:write permissions."

Read through a Get* accessor, an omitted field yields the zero value, which
is indistinguishable from the field genuinely being false or empty. Writing
that to state produces a diff on every plan that no apply can resolve,
because the value an apply would write back is not readable either. Setting
only what the response actually contained leaves prior state in place
instead.

integrations#3144 took this approach for vulnerability_alerts and security_and_analysis,
keying off the presence of security_and_analysis in the response and
deprecating ignore_vulnerability_alerts_during_read as "ignored as the
provider now handles lack of permissions automatically". setIfPresent
extends the same treatment to the merge-related fields, and sits in util.go
next to resourceKeysGetOk because the bug class is not repository-specific.

The archived special-case is deliberately left in place. It may be redundant
— the TODO added alongside integrations#3144 doubts that GitHub omits these fields for
archived repositories at all — but that is unverified, and removing it would
be a second, untested behaviour change on top of this one.

The cost is that drift in these fields goes undetected while the token
cannot read them, which is preferable to a permanent diff no apply can
clear.

Verified with a scoped installation token holding administration:read and
contents:read against a configuration managing nine repositories: every one
reported the diff on every plan before, none do after. Reverting to the
released provider reproduces it, so the binary is the only variable.

Refs integrations#3382
th7 added a commit to th7/terraform-provider-github that referenced this pull request Aug 8, 2026
GitHub omits merge-related settings from the repository object unless the
caller has push or admin access: "To view merge-related settings, you must
have the contents:read and contents:write permissions."

Read through a Get* accessor, an omitted field yields the zero value, which
is indistinguishable from the field genuinely being false or empty. Writing
that to state produces a diff on every plan that no apply can resolve,
because the value an apply would write back is not readable either. Setting
only what the response actually contained leaves prior state in place
instead.

integrations#3144 took this approach for vulnerability_alerts and security_and_analysis,
keying off the presence of security_and_analysis in the response and
deprecating ignore_vulnerability_alerts_during_read as "ignored as the
provider now handles lack of permissions automatically". setIfPresent
extends the same treatment to the merge-related fields, and sits in util.go
next to resourceKeysGetOk because the bug class is not repository-specific.

Skipping a field silently would hide the trade-off, so the read logs one
tflog.Warn per repository naming the fields it could not read. integrations#3553 uses
the same signal for archived and deleted repositories. A user-facing
warning diagnostic would fire on every plan for a token that is
permanently read-only, which is noise rather than information.

The archived special-case is deliberately left in place. It may be redundant
— the TODO added alongside integrations#3144 doubts that GitHub omits these fields for
archived repositories at all — but that is unverified, and removing it would
be a second, untested behaviour change on top of this one.

The cost is that drift in these fields goes undetected while the token
cannot read them, which is preferable to a permanent diff no apply can
clear.

Verified with a scoped installation token holding administration:read and
contents:read against a configuration managing nine repositories: every one
reported the diff on every plan before, none do after. Reverting to the
released provider reproduces it, so the binary is the only variable.

Refs integrations#3382
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.

3 participants