3.5 KiB
3.5 KiB
Interactive User Removal
Reference for remove_user_interactive.sh.
Purpose
Use this script to remove a GitHub user from repositories that match a name pattern. It supports both:
- interactive prompting
- command-line arguments for repeatable runs
This is the safer collaborator-removal path when you want per-repository confirmation by default.
Requirements
bashcurljq- a GitHub token with enough access to inspect repositories and remove collaborators
The script accepts a token via -t/--token, or it will prompt for one interactively.
Usage
Interactive:
./remove_user_interactive.sh
Non-interactive:
./remove_user_interactive.sh \
--user <github-username> \
--root <owner-or-org> \
--pattern '<repo-pattern>' \
--token "$GITHUB_TOKEN" \
--non-interactive
Help:
./remove_user_interactive.sh --help
Supported Flags
-u,--userUsername to remove.-r,--rootRoot GitHub user or organization used for repository discovery.-p,--patternRepository name filter.*is supported as a wildcard.-t,--tokenGitHub personal access token.--non-interactiveAuto-confirms all removals after discovery.-h,--helpShow usage.
How Discovery Works
The script:
- validates dependencies
- validates the GitHub token
- collects the root owner, target user, and repository pattern
- fetches repositories for the root user
- fetches organizations visible from that user and their repositories
- filters repositories by the provided pattern
- checks each repository for the target user as a collaborator
- asks for confirmation before each removal unless
--non-interactiveis used
Repository names are handled as owner/repo. Invalid names discovered from the API are skipped.
Pattern Matching
Examples:
*Match all discovered repositories.frontend-*Match repositories whose names begin withfrontend-.*api*Match repositories whose names containapi.exact-repo-nameMatch that exact repository name.
The script converts * to a regex-style wildcard internally. Matching is done against the repository name, not the full owner/repo path.
Confirmation Modes
During interactive execution, each repository prompt supports:
yRemove from the current repository.nSkip the current repository.aRemove from all remaining repositories.sSkip all remaining repositories.qExit immediately.
Exit And Result Notes
204from the GitHub API means the collaborator removal succeeded.404usually means the user is not a collaborator on that repository, or the repository could not be resolved with the current access.403during collaborator checks usually means the token lacks sufficient access for that repository.
At the end, the script prints counts for:
- processed repositories
- successful removals
- failed removals
- skipped removals
Operational Guidance
- Prefer running without
--non-interactivefirst unless you have already validated the repository pattern. - Use a narrow pattern before using
*against a large owner or organization. - Keep the token out of shell history when possible. Prompted entry is safer than embedding it directly in commands.
- Cross-check
docs/operations.mdanddocs/supported-scripts.mdif you are choosing between this script,remove_user_guided.sh, andremove_user_from_repos.sh.