Skip to content

fix(admin): let setup_repo.sh finish cleanly when the org blocks approvals - #251

Merged
jamesconwaydev merged 1 commit into
devstreamhq:mainfrom
foothillsdigital:fix/setup-repo-rough-edges
Nov 6, 2026
Merged

jamesconwaydev merged 1 commit into
devstreamhq:mainfrom
foothillsdigital:fix/setup-repo-rough-edges

Conversation

@foothillsdigital

Copy link
Copy Markdown
Collaborator

What and why

Closes #54.

Org setting on the last step. When PUT …/actions/permissions/workflow with can_approve_pull_request_reviews=true is refused, the script reads orgs/devstreamhq/actions/permissions/workflow.

  • Org forbids approvals: the script re-sends just default_workflow_permissions=read, so the default token still goes read-only. It prints a note on stderr saying auto-approve can't approve bot PRs yet and where to allow it (org Settings > Actions > General), then ends with done and exit 0.
  • Any other failure: it still exits 1, with an error.

Ruleset lookup.

  • Duplicate names: two rulesets with the same name gave $id two lines, so the PUT URL broke. The lookup now reads the IDs into an array (sorted), updates the oldest, and warns with the full list. It doesn't delete the extras, since that seemed a call for you to make by hand.
  • Org rulesets: it passes includes_parents=false, so an org ruleset with the same name can't be picked up (it can't be updated from the repo endpoint).
  • Paging: it uses --paginate.

.prettierrc.json was {}, so it's deleted. Prettier's defaults are identical, .editorconfig is still honoured, and nothing references the file. prettier --check over all tracked files is clean with it gone.

Tests. test_setup_repo.py runs the real script with a fake gh on PATH that logs every call. It covers a clean run (one PUT, one POST), duplicates (the oldest is updated, with a warning), the org blocking approvals (exit 0, a note, read-only token still set) and any other permissions failure (exit 1). All four fail against the old script. shellcheck is clean.

Checks

  • The PR title follows Conventional Commits
  • python3 -m unittest discover -s scripts -t . passes (601)
  • npm --prefix site test passes (if you touched site/)
  • npx prettier --check . passes
  • This doesn't edit data/entries.json by hand (submissions go through the form)

…ovals

The last step failed with exit 1 while the org forbids GitHub Actions
approving pull requests, so a good run looked broken. When that PUT is
refused and the org setting is the reason, the script still makes the
default workflow token read-only, prints a note saying where to allow
approvals, and finishes. Any other failure there still exits 1.

The ruleset lookup now pages, ignores org-level rulesets
(includes_parents=false), and copes with two rulesets of the same name
by updating the oldest and warning about the rest instead of building a
broken URL from both IDs.

The empty .prettierrc.json is gone. Prettier's defaults are the same as
{}, and .editorconfig is still read.

Tests run the script against a fake gh.

@jamesconwaydev jamesconwaydev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice. Treating the org approval setting as a note rather than a failure is the right call, and updating the oldest of the duplicates (instead of deleting) is exactly how I'd want it. The fake-gh test is a good pattern. I'll follow up separately so the script's ruleset matches the code-owner and last-push settings I turned on today.

@jamesconwaydev
jamesconwaydev merged commit f81bfe4 into devstreamhq:main Nov 6, 2026
9 checks passed
@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Heads-up for next time: mapfile isn't in bash 3.2, which is still what macOS ships, and this script gets run from a Mac. CI didn't notice because it uses bash 5. I switched it to a read loop in #252.

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.

Smooth the rough edges in setup_repo.sh

2 participants