- Add remove_user_interactive.sh with rich visual logging and progress tracking - Support wildcard patterns for repository matching (*-go-api*, frontend-*, etc.) - Handle both root account and organization repositories - Implement flexible confirmation system (yes/no/all/skip/quit) - Add comprehensive documentation and usage examples - Update README.md with tool overview and usage instructions - Create CLAUDE.md for repository guidance - Add detailed documentation in docs/remove_user_interactive.md 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6.6 KiB
6.6 KiB
Interactive User Removal Tool
Overview
remove_user_interactive.sh is a comprehensive command-line tool designed to remove users from GitHub repositories with advanced pattern matching and interactive confirmation features. The tool supports both individual user repositories and organization-wide operations.
Features
🎯 Core Functionality
- Interactive User Input: Guides users through token, user, and pattern collection
- Multi-Level Repository Discovery: Handles both root account and organization repositories
- Wildcard Pattern Matching: Supports complex repository patterns
- Batch Operations: Process multiple repositories efficiently
- Rich Visual Feedback: Color-coded logging with progress indicators
🔐 Security Features
- Token Validation: Verifies GitHub API access before operations
- Interactive Confirmations: Prevents accidental bulk operations
- Permission Checks: Validates repository access permissions
- Error Handling: Comprehensive error reporting and recovery
🎨 User Experience
- Progress Tracking: Real-time progress indicators
- Flexible Confirmation System: Multiple response options
- Summary Reports: Detailed operation statistics
- Color-Coded Output: Enhanced readability with emojis
Usage
Basic Execution
./remove_user_interactive.sh
Interactive Flow
- Dependency Check: Validates required tools (
curl,jq) - Authentication: Collects and validates GitHub token
- Root User Input: Specifies the root account/organization
- Target User: Defines the user to remove
- Pattern Matching: Sets repository selection criteria
- Repository Discovery: Finds all matching repositories
- Confirmation: Reviews and confirms the operation
- Batch Processing: Removes user from selected repositories
- Summary Report: Displays operation results
Pattern Matching
The tool supports sophisticated wildcard patterns for repository selection:
Pattern Examples
*-go-api*- Matches any repository containing "-go-api"frontend-*- Matches repositories starting with "frontend-"*-service- Matches repositories ending with "-service"web-*-app- Matches repositories with "web-" prefix and "-app" suffixexact-repo-name- Matches specific repository name
Pattern Behavior
- Patterns are case-sensitive
- Wildcards (
*) match any sequence of characters - Patterns apply to repository names, not full paths
- Multiple patterns can be combined using shell globbing
Interactive Confirmation System
During the removal process, users have multiple response options:
Confirmation Options
[y]es- Remove user from current repository[n]o- Skip current repository[a]ll yes- Remove user from all remaining repositories[s]kip all- Skip all remaining repositories[q]uit- Cancel entire operation
Confirmation Modes
ask- Default mode, prompts for each repositoryyes_all- Automatically confirm all operationsno_all- Automatically skip all operations
Repository Discovery
The tool performs comprehensive repository discovery:
Discovery Process
- Root User Repositories: Fetches all repositories owned by the root user
- Organization Discovery: Identifies organizations the root user belongs to
- Organization Repositories: Fetches repositories from each organization
- Pattern Filtering: Applies wildcard patterns to repository names
- Deduplication: Removes duplicate repositories from the final list
API Endpoints Used
GET /users/{user}/repos- User repositoriesGET /users/{user}/orgs- User organizationsGET /orgs/{org}/repos- Organization repositoriesDELETE /repos/{owner}/{repo}/collaborators/{username}- Remove collaborator
Error Handling
The tool includes comprehensive error handling:
HTTP Status Codes
204- Successful removal404- User not found or not a collaborator403- Insufficient permissions401- Invalid authentication
Error Recovery
- Network Failures: Retry mechanisms for API calls
- Rate Limiting: Respects GitHub API rate limits
- Permission Errors: Clear error messages and suggestions
- Invalid Input: Input validation and correction prompts
Logging and Output
Log Levels
- Info (ℹ️): General information messages
- Success (✅): Successful operations
- Warning (⚠️): Non-critical issues
- Error (❌): Critical failures
- Progress (🔄): Operation progress updates
Output Format
[EMOJI] [TIMESTAMP] [LEVEL] Message
Summary Report
Operation Summary
=================
Total repositories processed: 15
Successful removals: 12
Failed removals: 1
Skipped removals: 2
Success rate: 80%
Prerequisites
Required Tools
curl- HTTP client for API requestsjq- JSON processor for API responses
GitHub Token Permissions
repo- Repository access (read/write)admin:org- Organization administration
Environment Requirements
- Bash 4.0 or higher
- Internet connectivity for GitHub API access
- Valid GitHub Personal Access Token
Security Considerations
Token Security
- Tokens are not stored or logged
- Input is hidden during token entry
- Tokens are validated before use
Operation Safety
- Interactive confirmations prevent accidental operations
- Detailed logging for audit trails
- Rollback information provided for manual recovery
Access Control
- Respects GitHub repository permissions
- Validates user access before operations
- Handles permission errors gracefully
Troubleshooting
Common Issues
- Token Validation Fails: Ensure token has correct permissions
- Repository Not Found: Check repository name and access permissions
- User Not Found: Verify username spelling and existence
- Rate Limiting: Wait for rate limit reset or use token with higher limits
Debug Mode
Enable verbose output by setting:
export DEBUG=1
./remove_user_interactive.sh
Integration
The tool integrates seamlessly with other ByteLyst DevOps tools:
- Can be called from
bytelyst-cli.sh - Supports JSON configuration files
- Compatible with existing workflow scripts
- Follows established logging and error handling patterns
Performance
Optimization Features
- Paginated API requests for large datasets
- Parallel processing where possible
- Efficient pattern matching algorithms
- Minimal memory footprint
Scale Considerations
- Handles hundreds of repositories efficiently
- Respects GitHub API rate limits
- Provides progress feedback for long operations
- Supports interruption and resumption