Skip to content

chore(rulesets): add audit and apply scripts for the org baseline - #444

Merged
BryanFRD merged 1 commit into
mainfrom
chore/rulesets-baseline-scripts
Nov 28, 2026
Merged

BryanFRD merged 1 commit into
mainfrom
chore/rulesets-baseline-scripts

Conversation

@BryanFRD

Copy link
Copy Markdown
Contributor

Scripts for LABS-1048: read-only audit, per-repo required-check derivation, and an apply script (dry run by default, backup before each write, --rollback). Nothing is applied by this PR. Auto-merge intentionally left off.

@BryanFRD
BryanFRD enabled auto-merge (squash) November 28, 2026 15:24

@ferrfleet-interne ferrfleet-interne Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved. The ruleset tooling is dry-run by default, backs up every write and reads each change back to verify it. The review found no blocking issue, only minor ones.

To fix (minor)

  • scripts/rulesets/apply.sh:171: rollback of a created ruleset reports success when the DELETE fails. writes_enabled && gh api -X DELETE ... && log ... is followed by an unconditional return 0, so a 403, 404 or network error exits 0 with no message. Every other write path logs the failure and returns 1. Fix: if writes_enabled; then gh api -X DELETE "$path" >/dev/null || { log "DELETE failed: $path"; return 1; }; log "deleted $path"; fi; return 0
  • scripts/rulesets/derive-checks.sh:4: checks.json is written to the caller's cwd, but apply.sh reads $HERE/checks.json. Running the script from the repo root puts the file at the root, outside the .gitignore, where it can be committed, and apply.sh then reports it missing. Fix: default the output to the script directory, out=${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/checks.json}. Do the same for audit.sh (audit.tsv and audit.notes).

Suggestions

  • scripts/rulesets/apply.sh:148: the second fetch json=$(gh api "repos/$repo/rulesets/$id") has no error handling, unlike the identical fetch in the loop above. Store the candidate's JSON in the loop (e.g. cand_json) and reuse it.
  • scripts/rulesets/apply.sh:143: the .created.json backup is written with the default umask, while backup_current sets 600 on PUT backups. Add chmod 600 or route it through backup_current.
  • scripts/rulesets/derive-checks.sh:9: gh pr list sorts by creation date, so the sample is the 5 most recently created merged PRs, not the 5 most recently merged. The README says "last 5 merged PRs". Reword the README, or sort by mergedAt after fetching a larger limit.

Formal verification

Nothing to prove. The PR touches no Rust source, Cargo.toml or Cargo.lock, only bash scripts, a README and a .gitignore. The scripts call the live GitHub API through gh, so nothing was built or run.

@BryanFRD
BryanFRD merged commit 598b7c9 into main Nov 28, 2026
13 checks passed
@BryanFRD
BryanFRD deleted the chore/rulesets-baseline-scripts branch November 28, 2026 15:28
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.

1 participant