# PRManage

A Python CLI tool to fetch and run GitHub PRs locally for different tech stacks.

## Features

- 🚀 Fetch any GitHub PR and run it locally
- 🔍 Auto-detect tech stack (Laravel, Phoenix, Python)  
- ⚡ Run appropriate install and test commands
- 🛠️ Support for multiple repository formats
- 🔄 Smart repository caching and updates

## Supported Tech Stacks

- **Laravel**: Auto-detects via `composer.json`, `artisan`, `app/` directory
- **Phoenix**: Auto-detects via `mix.exs`, `config/config.exs`, `lib/` directory  
- **Python**: Auto-detects via `requirements.txt`, `setup.py`, `pyproject.toml`, `.py` files

## Installation

1. Clone this repository:
```bash
git clone https://github.com/momentpay/PRManage.git
cd PRManage
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```

## Usage

### Basic Usage

```bash
python main.py <repo_url> <pr_number>
```

### Examples

```bash
# Fetch and run Laravel PR
python main.py https://github.com/laravel/laravel 123

# Fetch and run Phoenix PR  
python main.py git@github.com:phoenixframework/phoenix.git 456

# Fetch and run Python PR with custom work directory
python main.py https://github.com/python/cpython 789 --work-dir ./my_repos

# Dry run to see what commands would be executed
python main.py https://github.com/owner/repo 123 --dry-run

# Skip tests, only install dependencies
python main.py https://github.com/owner/repo 123 --skip-tests

# Verbose output
python main.py https://github.com/owner/repo 123 --verbose
```

### Additional Commands

```bash
# Detect tech stack of local directory
python main.py detect /path/to/project

# Show version
python main.py version
```

## Command Reference

### Options

- `--work-dir, -w`: Directory to clone repositories (default: `./repos`)
- `--skip-tests, -s`: Skip running tests, only install dependencies  
- `--dry-run, -n`: Show what commands would be run without executing them
- `--verbose, -v`: Show verbose output
- `--help`: Show help message

### Stack-Specific Commands

**Laravel:**
- `composer install` - Install PHP dependencies
- `composer dump-autoload` - Generate autoload files
- `vendor/bin/phpunit` or `php artisan test` - Run tests

**Phoenix:**
- `mix deps.get` - Install Elixir dependencies
- `mix compile` - Compile project
- `mix test` - Run tests

**Python:**
- `pip install -r requirements.txt` - Install dependencies
- `python -m pytest` or `python -m unittest discover` - Run tests

## Directory Structure

```
PRManage/
├── main.py              # CLI entry point
├── pr_fetcher/          # Core package
│   ├── __init__.py      # Package initialization
│   ├── git_utils.py     # Git operations (clone, fetch PR)
│   ├── stack_detect.py  # Tech stack detection
│   └── commands.py      # Stack-specific commands
├── requirements.txt     # Python dependencies
└── README.md           # This file
```

## How It Works

1. **Repository Management**: Clones the repository or updates if already exists
2. **PR Fetching**: Uses git to fetch the specific PR branch and checkout  
3. **Stack Detection**: Analyzes project files to determine tech stack
4. **Command Execution**: Runs appropriate install and test commands for the detected stack

## Error Handling

- Graceful handling of network issues
- Timeout protection for long-running commands  
- Clear error messages for missing dependencies
- Fallback options when primary detection methods fail

## Requirements

- Python 3.7+
- Git
- Internet connection for GitHub API and repository access
- Stack-specific tools (composer for Laravel, mix for Phoenix, etc.)

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable  
5. Submit a pull request

## License

This project is open source and available under the MIT License.
