Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Code Review Laravel Package

zirolab/code-review

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require vokhoalab/code-review
    

    Publish the config file (if available) and run migrations:

    php artisan vendor:publish --provider="Vokhoalab\CodeReview\CodeReviewServiceProvider"
    php artisan migrate
    
  2. First Use Case: Reviewing a Pull Request

    • Use the CodeReview facade to create a review:
      use Vokhoalab\CodeReview\Facades\CodeReview;
      
      $review = CodeReview::create([
          'pull_request_id' => 123,
          'user_id' => auth()->id(),
          'comments' => ['file1.php' => ['line 10: Fix this typo']],
          'status' => 'approved', // or 'changes_requested', 'commented'
      ]);
      
    • Attach comments to a file/line:
      $review->addComment('file2.php', 20, 'Improve this logic');
      
  3. Key Classes to Explore

    • Vokhoalab\CodeReview\Models\Review – Core model for storing reviews.
    • Vokhoalab\CodeReview\Models\Comment – Stores inline/file comments.
    • Vokhoalab\CodeReview\Services\ReviewService – Business logic for reviews.

Implementation Patterns

Workflow: Integrating with GitHub/GitLab Webhooks

  1. Listen for PR Events Configure a webhook endpoint in your Git provider to trigger Laravel events:
    // routes/web.php
    Route::post('/github-webhook', [CodeReviewWebhookController::class, 'handle']);
    
  2. Auto-Generate Review Templates Use the CodeReview::generateTemplate() method to scaffold common review patterns:
    $template = CodeReview::generateTemplate('backend-auth');
    $review = $template->fill(['user_id' => auth()->id()]);
    $review->save();
    

Workflow: Batch Processing Reviews

  • Use the CodeReview::batch() method to process multiple PRs:
    $reviews = CodeReview::batch([
        ['pull_request_id' => 1, 'user_id' => 1, 'status' => 'approved'],
        ['pull_request_id' => 2, 'user_id' => 2, 'status' => 'changes_requested'],
    ]);
    

Integration with Laravel Nova/Panel

  • Extend Nova with a custom CodeReviewResource to visualize reviews in the admin panel:
    namespace App\Nova;
    
    use Vokhoalab\CodeReview\Models\Review;
    use Laravel\Nova\Resource;
    
    class CodeReviewResource extends Resource
    {
        public static $model = Review::class;
        // Define fields, filters, and actions here
    }
    

Customizing Review Statuses

  • Override default statuses (approved, changes_requested, commented) by extending the Review model:
    namespace App\Models;
    
    use Vokhoalab\CodeReview\Models\Review as BaseReview;
    
    class Review extends BaseReview
    {
        protected $casts = [
            'status' => 'string',
        ];
    
        public static $statuses = [
            'approved',
            'needs_revision',
            'under_review',
            'rejected',
        ];
    }
    

Gotchas and Tips

Pitfalls

  1. Missing Webhook Configuration

    • If webhooks aren’t set up, PR events won’t trigger reviews. Test locally with php artisan code-review:test-webhook (if available).
    • Fix: Verify Git provider webhook URLs and secret keys in .env.
  2. Database Schema Mismatches

    • The package assumes default table names (reviews, comments). Customize via config:
      'tables' => [
          'reviews' => 'custom_reviews',
          'comments' => 'custom_comments',
      ],
      
    • Fix: Run php artisan vendor:publish --tag=code-review-migrations to update migrations.
  3. Permission Issues

    • Ensure the reviewing user has access to the PR. Add middleware:
      public function handle()
      {
          $this->authorize('review', $pullRequest);
          // ...
      }
      

Debugging Tips

  • Log Review Events Enable debug logging in config/code-review.php:

    'debug' => env('CODE_REVIEW_DEBUG', false),
    

    Check storage/logs/laravel.log for webhook payloads.

  • Validate Webhook Payloads Use dd($request->all()) in the webhook controller to inspect raw data.

Extension Points

  1. Custom Comment Types Extend the Comment model to add metadata (e.g., severity, type):

    namespace App\Models;
    
    use Vokhoalab\CodeReview\Models\Comment as BaseComment;
    
    class Comment extends BaseComment
    {
        protected $casts = [
            'severity' => 'string', // 'low', 'medium', 'high'
        ];
    }
    
  2. Slack/Email Notifications Hook into the review.created event to send alerts:

    // Event listener
    public function handle(ReviewCreated $event)
    {
        Notification::route('slack', config('services.slack.webhook'))
            ->notify(new ReviewApproved($event->review));
    }
    
  3. API Endpoints for Frontend Expose reviews via API:

    Route::get('/reviews/{pr_id}', [CodeReviewController::class, 'show']);
    

    Use CodeReview::findByPrId($pr_id) to fetch reviews.

Performance Considerations

  • Eager Load Relationships Avoid N+1 queries when fetching reviews:
    $reviews = Review::with('comments.user')->get();
    
  • Cache Review Templates Cache generated templates to avoid reprocessing:
    $template = Cache::remember("review_template_{$templateName}", now()->addHours(1), function () {
        return CodeReview::generateTemplate($templateName);
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver