Skip to content

Commit aab5950

Browse files
committed
feat: add github-review CLI tool for submitting PRs to code review queue
Adds bin/github-review as the entry point and implements the full CLI command structure (ListCommand, MetricsCommand, StatusCommand, SubmitCommand, CancelCommand, ConfigCommand, ActivityCommand) with: - Redis-backed code review queue with job tracking - Real-time activity monitoring (--activity/-a flag) - Bot PR exclusion by default (--review-bots/-b to include) - Base branch verification via GitHub API at enqueue time - Verbose logging (-v through -vvvv) with colored markdown output - File-based review prompt templates for easy tweaking Also adds comprehensive test suite for worker parsing functions, base branch fallback logic, and verbose logging.
1 parent e9972eb commit aab5950

56 files changed

Lines changed: 14450 additions & 5 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,55 @@ php scripts/github-code-review.php
2525
- **Quality**: `phpstan.neon` · `phpstan-bootstrap.php` · `.php-cs-fixer.dist.php` (PSR2 + PHP74Migration)
2626
- **CI**: `.github/` — GitHub Actions workflows (`.github/workflows/ci.yml`)
2727

28+
## GitHub Review CLI
29+
30+
The `github-review` CLI tool manages code reviews of GitHub Pull Requests.
31+
32+
### CLI Commands
33+
34+
```bash
35+
# Build PHAR distribution
36+
php -d phar.readonly=0 bin/build-phar
37+
38+
# Run CLI directly
39+
bin/github-review --version
40+
bin/github-review list --help
41+
bin/github-review metrics
42+
bin/github-review submit --help
43+
44+
# Run via PHAR
45+
php -d phar.readonly=0 build/github-review.phar --version
46+
```
47+
48+
### CLI Source Files
49+
50+
- **Entry point**: `bin/github-review`
51+
- **Application**: `src/Cli/Application.php`
52+
- **Commands**: `src/Cli/Command/`
53+
- `ListCommand.php` — List queued review jobs
54+
- `MetricsCommand.php` — Show queue statistics
55+
- `SubmitCommand.php` — Submit PR for review
56+
- `StatusCommand.php` — Check review status
57+
- `CancelCommand.php` — Cancel queued jobs
58+
- `ConfigCommand.php` — Manage configuration
59+
- **Services**: `src/Cli/Service/`
60+
- `CodeAnalyzer.php` — OpenCode integration
61+
- `CheckoutManager.php` — Git checkout management
62+
- `DiffGenerator.php` — Diff generation
63+
- `ReviewPoster.php` — GitHub API posting
64+
- **Config**: `src/Cli/Config/ConfigLoader.php`
65+
- **Renderers**: `src/Cli/Renderer/`
66+
- `JsonRenderer.php` — JSON output
67+
- `TableRenderer.php` — Table output
68+
- **Interactor**: `src/Cli/Interactor/InteractiveInteractor.php`
69+
70+
### CLI Tests
71+
72+
```bash
73+
vendor/bin/phpstan analyse src/Cli/ --level=8
74+
vendor/bin/phpunit tests/phpunit/unit/Cli/ --testdox
75+
```
76+
2877
## Event Handling Pattern
2978

3079
All event handling lives in `web/github.php`:

README.md

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,297 @@ Log verbosity controlled by `LOG_LEVEL` env var:
240240

241241
---
242242

243+
## GitHub Review CLI
244+
245+
A command-line tool for managing code reviews of GitHub Pull Requests.
246+
247+
### Installation
248+
249+
#### Option 1: PHAR Distribution (Recommended)
250+
251+
Download the pre-built PHAR archive and install it system-wide:
252+
253+
```bash
254+
# Download the latest PHAR from the releases page
255+
# or build it yourself: php bin/build-phar
256+
257+
# Install globally on Linux/macOS
258+
sudo mv github-review.phar /usr/local/bin/github-review
259+
sudo chmod +x /usr/local/bin/github-review
260+
261+
# Verify installation
262+
github-review --version
263+
```
264+
265+
**System Requirements:**
266+
- PHP 7.4 or higher
267+
- PHP extensions: phar, openssl (for signing), zlib (for compression)
268+
269+
#### Option 2: Composer Installation
270+
271+
```bash
272+
# Clone the repository
273+
git clone https://github.com/interserver/webhooks.interserver.net.git
274+
cd webhooks.interserver.net
275+
276+
# Install dependencies
277+
composer install
278+
279+
# Make the CLI executable
280+
chmod +x bin/github-review
281+
282+
# Run directly
283+
bin/github-review --help
284+
285+
# Or run via composer
286+
composer exec github-review
287+
```
288+
289+
#### Option 3: Build PHAR from Source
290+
291+
```bash
292+
# Clone and install dependencies
293+
git clone https://github.com/interserver/webhooks.interserver.net.git
294+
cd webhooks.interserver.net
295+
composer install
296+
297+
# Build the PHAR
298+
php -d phar.readonly=0 bin/build-phar
299+
300+
# The PHAR will be at build/github-review.phar
301+
302+
# Optional: Sign the PHAR
303+
openssl genpkey -algorithm RSA -out private.key
304+
php -d phar.readonly=0 bin/build-phar --sign
305+
306+
# Install the built PHAR
307+
sudo mv build/github-review.phar /usr/local/bin/github-review
308+
sudo chmod +x /usr/local/bin/github-review
309+
```
310+
311+
### Quick Start
312+
313+
```bash
314+
# List queued review jobs
315+
bin/github-review list
316+
317+
# Show queue statistics
318+
bin/github-review metrics
319+
320+
# Submit a PR for review
321+
bin/github-review submit owner/repo --pr 42
322+
323+
# Check review status
324+
bin/github-review status --repo owner/repo
325+
326+
# View help
327+
bin/github-review --help
328+
```
329+
330+
### Commands
331+
332+
#### `list` - List Queue Jobs
333+
334+
List pending code review jobs in the Redis queue.
335+
336+
```bash
337+
bin/github-review list
338+
bin/github-review list --limit 20
339+
bin/github-review list --repo owner/repo
340+
bin/github-review list --event-type pull_request --action opened
341+
bin/github-review list --json
342+
```
343+
344+
Options:
345+
- `-l, --limit N` — Show at most N entries (default: 50)
346+
- `-r, --repo OWNER/REPO` — Filter by repository
347+
- `-e, --event-type TYPE` — Filter by source type (push, pr, check_run, etc.)
348+
- `-a, --action ACTION` — Filter by action (opened, synchronize, closed)
349+
- `--json` — Output as JSON
350+
- `-d, --detailed` — Include id and PR URL in output
351+
352+
#### `metrics` - Queue Statistics
353+
354+
Show queue statistics and processing metrics.
355+
356+
```bash
357+
bin/github-review metrics
358+
bin/github-review metrics --json
359+
```
360+
361+
#### `submit` - Submit PR for Review
362+
363+
Submit a Pull Request for code review analysis.
364+
365+
```bash
366+
bin/github-review submit owner/repo --pr 42
367+
bin/github-review submit owner/repo 42 # Short form
368+
bin/github-review submit owner/repo --all # All open PRs
369+
bin/github-review submit owner/repo --pr 42 --audit-types security,performance
370+
bin/github-review submit owner/repo --pr 42 --severity error
371+
```
372+
373+
Options:
374+
- `repo` — Repository in owner/repo format (first argument)
375+
- `pr` — PR number (second argument or `--pr` option)
376+
- `-t, --audit-types TYPES` — Comma-separated audit types (security,performance,documentation,logic,style,full)
377+
- `-s, --severity LEVEL` — Minimum severity (error, warning, info)
378+
- `--no-security`, `--no-performance`, `--no-documentation`, `--no-logic`, `--no-style` — Disable specific audits
379+
- `--post-diffs` — Post inline diff of suggested fixes as PR review comments
380+
- `--post-branch` — Create a branch with suggested fixes (mutually exclusive with --post-diffs)
381+
- `--split-changes` — Split changes into multiple PRs by file/audit-type
382+
- `--split-by STRATEGY` — Split strategy: file, audit, severity, size
383+
- `--dry-run` — Preview without submitting
384+
- `-w, --wait` — Wait for completion
385+
386+
#### `status` - Check Review Status
387+
388+
Check the status of a review job.
389+
390+
```bash
391+
bin/github-review status --id abc-123
392+
bin/github-review status --repo owner/repo --pr 42
393+
bin/github-review status --watch
394+
```
395+
396+
Options:
397+
- `-i, --id UUID` — Check specific job by ID
398+
- `-r, --repo OWNER/REPO` — Filter by repository
399+
- `-p, --pr NUMBER` — Filter by PR number
400+
- `--json` — Output as JSON
401+
- `-w, --watch` — Poll for updates continuously
402+
403+
#### `cancel` - Cancel Jobs
404+
405+
Cancel queued or processing review jobs.
406+
407+
```bash
408+
bin/github-review cancel --id abc-123
409+
bin/github-review cancel --all
410+
```
411+
412+
Options:
413+
- `-i, --id UUID` — Cancel specific job by ID
414+
- `--all` — Clear entire queue
415+
416+
#### `config` - Configuration Management
417+
418+
Manage CLI configuration.
419+
420+
```bash
421+
bin/github-review config --list
422+
bin/github-review config --add-repo owner/repo
423+
bin/github-review config --set-token
424+
```
425+
426+
Options:
427+
- `-l, --list` — List current configuration
428+
- `--add-repo OWNER/REPO` — Add repository to watch list
429+
- `--remove-repo OWNER/REPO` — Remove repository
430+
- `--set-token` — Set/update GitHub token
431+
- `--set-checkout-root PATH` — Set checkout directory
432+
- `--reset` — Reset to defaults
433+
434+
### Global Options
435+
436+
- `-h, --help` — Show help message
437+
- `-V, --version` — Show version
438+
- `-v, --verbose` — Increase verbosity (stackable: `-vvv`)
439+
- `-q, --quiet` — Suppress output
440+
- `--json` — Output as JSON (for scripting)
441+
- `--debug` — Show debug information
442+
- `-n, --non-interactive` — Non-interactive mode (disables prompting)
443+
444+
### Configuration
445+
446+
Configuration is loaded from multiple sources in order of priority (highest last):
447+
448+
1. **System config**`/etc/github-review/config.php`
449+
2. **User config**`~/.config/github-review/config.php`
450+
3. **Project config**`./config/review-cli.php`
451+
4. **Environment variables**
452+
5. **CLI arguments**
453+
454+
#### Configuration File Template
455+
456+
Copy `config/review-cli.php.dist` to `config/review-cli.php`:
457+
458+
```php
459+
<?php
460+
return [
461+
'github' => [
462+
'token' => 'ghp_xxxx', // Or use GITHUB_TOKEN env var
463+
],
464+
'redis' => [
465+
'host' => '67.217.60.234',
466+
'port' => 6379,
467+
],
468+
'checkout' => [
469+
'root' => '/tmp/pr-checkouts',
470+
'cleanup_after' => 3600,
471+
],
472+
'opencode' => [
473+
'analyze_cmd' => 'opencode analyze --dir {dir} --output json',
474+
'improve_cmd' => 'opencode improve --dir {dir} --file {file} --line {line} --output json',
475+
],
476+
'repositories' => [
477+
'owner/repo1',
478+
'owner/repo2',
479+
],
480+
'defaults' => [
481+
'audit_types' => 'full',
482+
'severity' => 'warning',
483+
'post_summary' => true,
484+
],
485+
];
486+
```
487+
488+
#### Environment Variables
489+
490+
Any config value can be overridden via environment variables:
491+
492+
| Variable | Description |
493+
|----------|-------------|
494+
| `GITHUB_TOKEN` | GitHub personal access token |
495+
| `REDIS_HOST` | Redis server host |
496+
| `REDIS_PORT` | Redis server port |
497+
| `CHECKOUT_ROOT` | Checkout directory for PRs |
498+
| `OPENCODE_ANALYZE_CMD` | OpenCode analyze command template |
499+
| `OPENCODE_IMPROVE_CMD` | OpenCode improve command template |
500+
| `CLI_NON_INTERACTIVE` | Force non-interactive mode |
501+
502+
### Interactive Mode
503+
504+
When running without a TTY (cron jobs, CI/CD pipelines) or with `--non-interactive` flag, the CLI:
505+
506+
- Requires all parameters via flags/arguments
507+
- Fails on first error
508+
- Uses JSON output for scripting
509+
- Disables progress bars
510+
511+
When running interactively, the CLI:
512+
513+
- Shows colored tables
514+
- Enables progress bars
515+
- Offers interactive prompts for missing arguments
516+
- Provides suggestions and defaults
517+
518+
### Exit Codes
519+
520+
| Code | Meaning |
521+
|------|---------|
522+
| 0 | Success |
523+
| 1 | General error |
524+
| 2 | Invalid arguments |
525+
| 3 | Not found |
526+
| 4 | Validation error |
527+
| 5 | Redis error |
528+
| 6 | GitHub API error |
529+
| 7 | Checkout error |
530+
| 8 | Timeout |
531+
532+
---
533+
243534
## GitHubWebhook Class
244535

245536
```php

0 commit comments

Comments
 (0)