bytelyst-devops-tools/README_interactive_script.md

8.7 KiB
Raw Blame History

🚀 Interactive GitHub User Removal Script

An intuitive, guided script that walks you through the process of removing users from GitHub repositories with a beautiful interactive interface.

Features

🎯 Interactive Experience

  • Beautiful Welcome Screen with ASCII art
  • Step-by-step Guided Process - no command line arguments needed
  • Smart Input Validation with helpful error messages
  • Confirmation Prompts to prevent accidental operations
  • Real-time Progress Updates with visual progress bars

🛡️ Safety Features

  • Dry Run Mode (recommended first run) - preview changes without executing
  • Multiple Confirmation Steps for destructive operations
  • Token Validation before proceeding
  • Pattern Preview to show what repositories will match

🎨 User Interface

  • Color-coded Output for easy reading
  • Emoji Icons for visual clarity
  • Formatted Headers and sections
  • Clear Success/Error Messages

📋 Requirements

  • bash (version 4.0+)
  • curl
  • jq
  • Valid GitHub Personal Access Token with repo and admin:org permissions

🚀 Usage

Simply run the script - no command line arguments needed:

./remove_user_guided.sh

The script will guide you through each step:

1. 🔑 GitHub Authentication

🔑 GitHub Authentication
============================================================
Please provide your GitHub Personal Access Token:
💡 The token should have 'repo' and 'admin:org' permissions
💡 You can create one at: https://github.com/settings/tokens

🔐 Enter your GitHub token: [hidden input]

2. 👤 Target Organization/User

👤 Target Organization/User
============================================================
Enter the GitHub username or organization name:
💡 This is where we'll look for repositories
💡 Examples: 'mycompany', 'john-doe', 'my-organization'

🏢 Organization/Username: 

3. 🎯 User to Remove

🎯 User to Remove
============================================================
Enter the username you want to remove from repositories:
💡 This user will be removed as a collaborator from matching repositories
💡 They will lose access to private repositories (if applicable)

👤 Username to remove:

4. 📁 Repository Filter

📁 Repository Filter
============================================================
Enter a repository name pattern to filter repositories:
💡 Pattern examples:
   • '*' - All repositories
   • 'myproject-' - Repos starting with 'myproject-'
   • '*api*' - Repos containing 'api'
   • 'web-app' - Repos starting with 'web-app'

🔍 Repository pattern:

5. ⚙️ Operation Options

⚙️  Operation Options
============================================================
Choose your operation mode:

1) 🔍 Dry Run - Preview what would be done (Recommended)
2) 🚀 Execute - Perform the actual removal

Select option (1 or 2):

6. 📋 Final Summary

📋 Operation Summary
============================================================
Configuration:
  🏢 Organization/User: myorg
  👤 User to remove: olduser  
  🔍 Repository pattern: project-*
  ⚙️  Mode: Dry Run
  📝 Logging: Standard

Ready to proceed? (yes/no):

🎭 Interactive Flow Example

Here's what a complete session looks like:

  ╔══════════════════════════════════════════════════════════╗
  ║                                                          ║
  ║           🚀 GitHub User Removal Tool 🚀                ║
  ║                                                          ║
  ║     Remove users from repositories with ease!           ║
  ║                                                          ║
  ╚══════════════════════════════════════════════════════════╝

  Welcome to the Interactive GitHub User Removal Script!

🔑 GitHub Authentication
============================================================
[Token input and validation...]

👤 Target Organization/User
============================================================
[Organization selection...]

🎯 User to Remove  
============================================================
[User selection with confirmation...]

📁 Repository Filter
============================================================
[Pattern selection with preview...]

⚙️  Operation Options
============================================================
[Mode selection...]

📋 Operation Summary
============================================================
[Final confirmation...]

🚀 Processing Repositories
============================================================
  Discovering repositories for myorg...
✅ Found 25 repositories
  Filtering repositories by pattern 'project-*'...
✅ Found 8 repositories matching pattern 'project-*'
  Processing repositories...

Progress: [100%] 8/8 repositories processed
[DRY RUN] Would remove olduser from myorg/project-api
[DRY RUN] Would remove olduser from myorg/project-web

🎉 Operation Complete
============================================================
📊 Statistics:
  📁 Repositories scanned: 25
  🔍 Repositories matching pattern: 8
  👤 Repositories where user was collaborator: 2

  ✅ Successful removals: 0
    Already removed: 0
  ❌ Failed removals: 0

⚠️  This was a dry run - no actual changes were made
💡 To perform the actual removal, run the script again and select 'Execute' mode

🙏 Thank you for using the GitHub User Removal Tool!

🛡️ Safety Features in Detail

1. Token Validation

  • Validates GitHub token before any operations
  • Shows authenticated username for confirmation
  • Provides clear error messages for invalid tokens

2. Input Validation

  • Validates username/organization formats
  • Checks repository pattern syntax
  • Provides helpful suggestions for corrections

3. Confirmation Steps

  • Confirms user to be removed
  • Confirms repository pattern understanding
  • Requires explicit "YES" for destructive operations
  • Shows exactly what would be done
  • No actual changes made
  • Perfect for testing and verification

5. Pattern Preview

  • Shows what the pattern will match before execution
  • Examples: "This will match repositories starting with: project-"
  • Helps prevent unintended scope

🔧 Repository Patterns

Pattern What it Matches Examples
* All repositories All repos in the org/user
bytelyst- Repos starting with 'bytelyst-' bytelyst-web, bytelyst-api, bytelyst-mobile
*api* Repos containing 'api' web-api, user-api-v2, api-gateway
web-* Repos starting with 'web-' web-frontend, web-backend, web-app
*-service Repos ending with '-service' user-service, auth-service

🎨 Color Coding

The script uses intuitive color coding:

  • 🔵 Blue: Informational messages and prompts
  • 🟢 Green: Success messages and confirmations
  • 🟡 Yellow: Warnings and important notices
  • 🔴 Red: Errors and failures
  • 🟣 Purple: Section headers
  • 🟦 Cyan: Progress updates and statistics

🚨 Important Notes

  1. Always start with Dry Run mode to preview changes
  2. Double-check the user to remove - there's no undo!
  3. Verify repository patterns match your intentions
  4. Ensure your token has sufficient permissions
  5. Users will lose access to private repositories immediately

💡 Tips for Best Experience

  1. Have your GitHub token ready before starting
  2. Know the exact username you want to remove
  3. Think about the repository pattern beforehand
  4. Use Dry Run first to verify everything looks correct
  5. Keep the terminal window large enough for the interface

🔗 Quick Start Guide

  1. Prepare: Get your GitHub token with proper permissions
  2. Run: Execute ./remove_user_guided.sh
  3. Follow: The interactive prompts step by step
  4. Preview: Always do a dry run first
  5. Execute: Run again in execute mode if satisfied

Keyboard Shortcuts

  • Ctrl+C: Cancel operation at any time
  • Enter: Confirm current input
  • Arrow keys work in most terminals for command history

🆘 Need Help?

The script provides comprehensive help at each step:

  • Clear explanations for each input
  • Examples for common patterns
  • Helpful error messages
  • Recovery suggestions

Ready to clean up your repositories? Just run ./remove_user_guided.sh and let the script guide you! 🚀