Skip to content

Add --write-private-only flag#6

Open
tlongwell-block wants to merge 3 commits intotoolset_ro_rwfrom
toolset_ro_rw_dev
Open

Add --write-private-only flag#6
tlongwell-block wants to merge 3 commits intotoolset_ro_rwfrom
toolset_ro_rw_dev

Conversation

@tlongwell-block
Copy link
Owner

Restricts write operations to private repos when enabled. Env var: GITHUB_WRITE_PRIVATE_ONLY, CLI: --write-private-only.

Decorator wraps all 19 write tool handlers at registration time — no changes to individual tools. create_repository requires private=true; fork_repository is blocked (can't guarantee visibility). Fails closed on any visibility check error.

…vate repos

When GITHUB_WRITE_PRIVATE_ONLY=true (or --write-private-only flag), all write
tool handlers are wrapped with a visibility guard that:
- Checks repo.Private via Repositories.Get() before each write (no cache)
- Fails closed on any API error (blocks the write)
- Blocks create_repository if private!=true (param pre-flight, no API call)
- Blocks fork_repository entirely (GitHub API can't guarantee private output)
- Logs WARN on each blocked write for audit trail

Architecture: decorator pattern in pkg/github/write_guard.go wraps
ToolHandlerFunc at InitToolsetsWithConfig() time. Zero changes to
toolsets.go or individual tool implementations.

19 write tools across 3 toolsets (repos, issues, pull_requests) are
all covered. 13 new unit tests verify guard behavior.
Viper's AutomaticEnv() doesn't automatically replace hyphens with
underscores when looking up env vars. Without an explicit BindEnv,
the GITHUB_WRITE_PRIVATE_ONLY env var would not be recognized.
This is the same gap that exists for --read-only (which also lacks
a BindEnv), but since our feature name implies env var usage, we
add the explicit binding.
- Test_WritePrivateOnlyGuard_GetClientFailure: verifies fail-closed
  behavior when getClient returns an error
- TestWritePrivateOnlyGuardWiring: integration test verifying that
  writePrivateOnly=true wraps all write tools and that fork_repository
  is blocked. Tests the InitToolsetsWithConfig wiring path.

Total: 15 tests covering all guard paths.
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