fix(repo-settings): stop reporting unreadable settings as drift - #3
Merged
Merged
Conversation
compare() already distinguishes "cannot read with this token" from real drift —
it checks for a value of exactly `unknown` and counts those separately, so a
permissions gap does not masquerade as a settings problem. Three probes defeated
that guard.
They were written `x=$(gh api … 2>/dev/null || echo unknown)`. On a 403 `gh api`
exits non-zero *and* writes the error JSON to stdout, so the substitution
captured that JSON with `unknown` appended. The result never equals `unknown`,
the guard missed, and the row was reported as drift with a JSON blob as its
observed value.
So the weekly job failed for a reason that was not true — the inverse of the
green-by-omission failure the unreadable count exists to prevent. `topics` (187),
`secrets` (319) and `variables` (320) were all affected; anything checked with a
token lacking administration:read hit it.
Rewritten as `x=$(gh api …) || x=unknown`, so the fallback replaces the captured
output instead of being appended to it. Verified against a real 403: the old
idiom yields `{"message":"Resource not accessible…` and the new one yields
`unknown`, which compare() then counts as unreadable.
Also fixed SC2015 in the ruleset apply path: `A && B || C` meant a failure of the
success-message branch would also print the failure message. Rewritten as
if/else. This repository's own quality job runs shellcheck at
`--severity=warning`, where SC2015 is info-level and invisible, so it surfaced
only when a consuming repository linting at default severity adopted the file.
RSRMID-2989
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira: RSRMID-2989
Two defects in
scripts/repo-settings.sh, both found whenrtldev-middleware-php-sdkadopted this tooling under RSRMID-2988.1. Unreadable settings were reported as drift
compare()already distinguishes "cannot read with this token" from real drift — it checks for a value of exactlyunknownand counts those separately, so a permissions gap doesn't masquerade as a settings problem.Three probes defeated that guard. They were written:
x=$(gh api … 2>/dev/null || echo unknown)On a 403,
gh apiexits non-zero and writes the error JSON to stdout. So the substitution captures that JSON withunknownappended — which never equalsunknown, so the guard misses and the row falls through to the drift branch, reporting a JSON blob as its observed value.The weekly job therefore failed for a reason that wasn't true: the exact inverse of the green-by-omission failure the
unreadablecount exists to prevent.Proven against a live 403:
Fixed to
x=$(gh api …) || x=unknown, so the fallback replaces the captured output rather than being appended to it.All three affected:
topics(187),secrets(319),variables(320). Any repo whose token lacksadministration:readhits it — which, given the drift workflow's own comment recommends running onGITHUB_TOKENby default, is the common case rather than the edge case.2. SC2015 in the ruleset apply path
A && B || C, so a failure of the success-message branch would also print the failure message. Rewritten asif/else.This repo's own
quality.ymlrunsshellcheck --severity=warning, where SC2015 is info-level and invisible. It surfaced only when a consuming repository linting at default severity adopted the file — so the template was shipping a file its own gate couldn't check.Verification
shellcheckclean at both default and--severity=warningbash -ncleanprettier --check .cleanNote
The SDK's copy is being fixed in the same issue (its PR) so the two don't diverge — it had two of the three probes fixed at adoption time, and the
topicsone was missed.