Skip to content

feat: add Laravel service provider for zero-config setup#9

Merged
jordanpartridge merged 2 commits intomasterfrom
feature/issue-3-service-provider
Dec 12, 2025
Merged

feat: add Laravel service provider for zero-config setup#9
jordanpartridge merged 2 commits intomasterfrom
feature/issue-3-service-provider

Conversation

@jordanpartridge
Copy link
Copy Markdown
Contributor

@jordanpartridge jordanpartridge commented Dec 12, 2025

Fixes #3

Summary

  • Adds PrServiceProvider with Laravel package auto-discovery
  • Creates publishable config/pr.php configuration file
  • Auto-configures PullRequests facade on Laravel boot
  • Reads token from config('services.github.token') or GITHUB_TOKEN env variable

Implementation Details

Service Provider (src/PrServiceProvider.php)

  • Registers PrServiceInterface and GitHubPrService as singletons
  • Merges package config on register
  • Auto-configures the PullRequests facade via setService() on boot
  • Publishes config file when running in console

Configuration (config/pr.php)

  • Publishable config file with GitHub token setting
  • Supports GITHUB_TOKEN environment variable
  • Falls back to config('services.github.token')

Auto-Discovery

  • Added extra.laravel.providers to composer.json for automatic service provider registration
  • No manual registration needed in Laravel applications

PHPStan

  • Excluded PrServiceProvider.php from static analysis since Laravel is an optional dependency

Usage in Laravel

After installing, Laravel users get zero-config setup:

use ConduitUI\Pr\PullRequests;

// Just set GITHUB_TOKEN in .env and start using:
$prs = PullRequests::for('owner/repo')->get();
$pr = PullRequests::find('owner/repo', 123);

Users can optionally publish the config:

php artisan vendor:publish --tag=pr-config

Test Plan

  • All existing tests pass: ✓
  • PHPStan analysis passes: ✓
  • Code style checks pass: ✓

Summary by CodeRabbit

  • Chores
    • Added framework service provider registration to enable GitHub PR integration.
    • Introduced configuration management for GitHub authentication.
    • Updated development tooling to exclude service components from analysis.

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes #3

- Add PrServiceProvider with auto-discovery support
- Create publishable config/pr.php configuration file
- Auto-configure PullRequests facade on Laravel boot
- Read token from config('services.github.token') or GITHUB_TOKEN env
- Exclude service provider from PHPStan analysis (Laravel not required)
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 12, 2025

Warning

Rate limit exceeded

@jordanpartridge has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a4c8e0b and 6adaa47.

📒 Files selected for processing (2)
  • phpstan.neon (1 hunks)
  • src/PrServiceProvider.php (1 hunks)

Walkthrough

Introduces Laravel service provider integration for automatic dependency injection setup. Registers PrServiceProvider via composer.json, creates a configuration file for GitHub credentials, and implements the provider to bind PrServiceInterface to the container with automatic facade initialization.

Changes

Cohort / File(s) Summary
Service Provider Registration
composer.json
Added extra.laravel.providers entry specifying ConduitUI\\Pr\\PrServiceProvider for automatic package discovery
Configuration Setup
config/pr.php
New configuration file defining GitHub token retrieval from environment variable via env('GITHUB_TOKEN')
Service Provider Implementation
src/PrServiceProvider.php
New PrServiceProvider class with register() method binding PrServiceInterface to GitHubPrService singleton, and boot() method publishing config and auto-configuring PullRequests facade
Analysis Configuration
phpstan.neon
Added exclusion path for src/PrServiceProvider.php to skip static analysis on the new provider file

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Token configuration retrieval: Verify config key path (config('pr.github.token') or fallback to env) matches application setup and aligns with linked issue proposal
  • RuntimeException handling: Confirm error message and conditions are appropriate when GitHub token is unavailable
  • Facade auto-wiring: Review PullRequests::setService() method invocation in boot() context
  • PHPStan exclusion rationale: Validate why this specific file requires static analysis exclusion

Poem

🐰 A service provider hops into place,
With Laravel's conventions—no wiring to face!
GitHub tokens flow, facades sing bright,
Zero-config magic makes integration light! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: adding a Laravel service provider that enables zero-config setup by implementing auto-discovery and automatic wiring.
Linked Issues check ✅ Passed All coding requirements from issue #3 are met: PrServiceProvider reads GitHub token from config/environment, binds PrService as singleton, and supports Laravel auto-discovery via composer.json.
Out of Scope Changes check ✅ Passed All changes align with the scope of issue #3: service provider implementation, configuration file, composer.json setup, and PHPStan configuration for optional Laravel dependency.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
phpstan.neon (1)

5-6: Excluding src/PrServiceProvider.php is pragmatic, but it also blinds static analysis for shipped code.
If Laravel integration is important, consider analyzing it with a separate PHPStan config that includes Laravel stubs/deps (while keeping the default config framework-agnostic), rather than excluding entirely.

composer.json (1)

46-52: Laravel auto-discovery provider registration looks right; consider adding a Composer suggest for Laravel/Illuminate.
Since src/PrServiceProvider.php depends on Laravel, adding something like "illuminate/support": "Required for Laravel service provider integration" under suggest helps non-Laravel consumers understand the optional dependency.

src/PrServiceProvider.php (1)

38-40: Consider removing (or rethinking) the GitHubPrService::class singleton binding.
Binding GitHubPrService::class to whatever PrServiceInterface resolves to can become misleading if you ever swap implementations; consumers asking for GitHubPrService generally expect the concrete type.

-        $this->app->singleton(GitHubPrService::class, function ($app) {
-            return $app->make(PrServiceInterface::class);
-        });
+        // Optional: only bind the interface; consumers should depend on PrServiceInterface.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4c4afa and a4c8e0b.

📒 Files selected for processing (4)
  • composer.json (1 hunks)
  • config/pr.php (1 hunks)
  • phpstan.neon (1 hunks)
  • src/PrServiceProvider.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.php

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.php: Use declare(strict_types=1) at the top of all PHP files
Apply Laravel Pint with laravel preset for code formatting

Files:

  • src/PrServiceProvider.php
  • config/pr.php
src/**/*.php

📄 CodeRabbit inference engine (CLAUDE.md)

Use namespace ConduitUI\Pr for all classes in the library

Files:

  • src/PrServiceProvider.php
🧠 Learnings (2)
📚 Learning: 2025-12-12T15:34:14.754Z
Learnt from: CR
Repo: conduit-ui/pr PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-12T15:34:14.754Z
Learning: Applies to src/**/*.php : Use namespace `ConduitUI\Pr` for all classes in the library

Applied to files:

  • composer.json
  • src/PrServiceProvider.php
📚 Learning: 2025-12-12T15:34:14.754Z
Learnt from: CR
Repo: conduit-ui/pr PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-12T15:34:14.754Z
Learning: Require connector setup via `PullRequests::setConnector()` with a `ConduitUi\GitHubConnector\Connector` instance before using static methods

Applied to files:

  • src/PrServiceProvider.php
🔇 Additional comments (2)
config/pr.php (1)

1-20: LGTM: strict types + simple config surface.
The config file is minimal and matches the “zero-config via GITHUB_TOKEN” story; fallback to services.github.token can remain provider-driven.

src/PrServiceProvider.php (1)

19-22: Config merge path looks correct for a package layout (src/../config).
No changes requested here.

Comment on lines +48 to +57
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/pr.php' => config_path('pr.php'),
], 'pr-config');
}

// Auto-configure the PullRequests facade
$service = $this->app->make(PrServiceInterface::class);
PullRequests::setService($service);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid eager resolution in boot()—missing token shouldn’t break the whole Laravel app / artisan.
Right now boot() always resolves PrServiceInterface, so a missing token throws during app boot, even if the package isn’t used. Prefer lazy configuration (or only set up the facade when token is present).

     public function boot(): void
     {
         if ($this->app->runningInConsole()) {
             $this->publishes([
                 __DIR__.'/../config/pr.php' => config_path('pr.php'),
             ], 'pr-config');
         }
 
-        // Auto-configure the PullRequests facade
-        $service = $this->app->make(PrServiceInterface::class);
-        PullRequests::setService($service);
+        // Auto-configure the PullRequests facade (lazy / non-fatal if unconfigured)
+        $token = $this->app['config']->get('pr.github.token')
+            ?: $this->app['config']->get('services.github.token')
+            ?: env('GITHUB_TOKEN');
+
+        if ($token) {
+            PullRequests::setService($this->app->make(PrServiceInterface::class));
+        }
     }
🤖 Prompt for AI Agents
In src/PrServiceProvider.php around lines 48 to 57, boot() eagerly resolves
PrServiceInterface which throws if the token is missing; instead avoid calling
$this->app->make() during boot — either guard resolution with a config/token
check (e.g. if (config('pr.token')) {
PullRequests::setService($this->app->make(PrServiceInterface::class)); }) or
defer wiring by using the container hooks (e.g.
$this->app->afterResolving(PrServiceInterface::class, fn($service) =>
PullRequests::setService($service)); or $this->app->resolving(...)) so the
service is only resolved when available and the app can boot without the token.

- Extract token resolution to helper method that properly handles
  empty strings (trim + explicit check instead of ?? operator)
- Make boot() lazy - only configures facade if token is available,
  preventing app crashes when PR package is installed but not used
- Add explanatory comment for PHPStan exclusion

Addresses CodeRabbit review comments on empty string handling and
eager resolution in boot().
@jordanpartridge jordanpartridge merged commit 673ccce into master Dec 12, 2025
3 checks passed
@jordanpartridge jordanpartridge deleted the feature/issue-3-service-provider branch December 12, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Laravel service provider for zero-config setup

1 participant