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

Github Laravel Package

graham-campbell/github

Laravel bridge to the KnpLabs PHP GitHub API. Provides a configurable GitHub client via a manager, with Laravel-friendly service container integration, facades, and multi-connection support for GitHub authentication and requests.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Integration: The package leverages Laravel’s service provider and facade patterns, aligning seamlessly with Laravel’s architecture (e.g., GitHubServiceProvider, GitHubManager). This reduces boilerplate and adheres to Laravel’s conventions (e.g., dependency injection, configuration publishing).
  • Manager Pattern: Built atop Laravel-Manager, it supports multi-connection setups (e.g., GitHub::connection('alternative')), enabling modularity for environments like staging/production or per-tenant GitHub APIs.
  • Facade Abstraction: The GitHub facade simplifies API calls (e.g., GitHub::me()->organizations()), abstracting the underlying KnpLabs/php-github-api client. This lowers the cognitive load for developers unfamiliar with the GitHub API.
  • Caching Layer: Optional HTTP caching (via graham-campbell/bounded-cache) reduces API rate limits and improves performance for repetitive calls (e.g., fetching the same repo metadata).

Integration Feasibility

  • Composer Dependency: Zero-configuration installation via Composer (composer require graham-campbell/github) with automatic service provider registration (Laravel 5.5+). Manual registration is only needed for older Laravel versions or custom setups.
  • Configuration Flexibility: Supports 5 authentication methods (application, jwt, none, private, token), accommodating OAuth apps, CI/CD pipelines, or personal access tokens. Configuration is published via php artisan vendor:publish, centralizing credentials.
  • Backward Compatibility: Supports Laravel 10–13 and PHP 8.1–8.5, with a clear migration path for older versions (e.g., Laravel 8+ required for v9.x+). The changelog highlights breaking changes (e.g., dropped Laravel 5 in v9.0).
  • Dependency Stability: Relies on KnpLabs/php-github-api (v3.x), a mature, actively maintained library with comprehensive GitHub API coverage. Version pinning in composer.json mitigates risk.

Technical Risk

  • Authentication Complexity:
    • JWT/OAuth: Requires additional setup (e.g., generating private keys, configuring OAuth apps in GitHub). Risk of misconfiguration (e.g., expired tokens, incorrect scopes).
    • Private Key Auth: Sensitive keys must be securely stored (e.g., Laravel’s env() or a secrets manager). Hardcoding keys in config/github.php is discouraged.
    • Mitigation: Use Laravel’s .env for credentials and restrict file permissions.
  • Caching Overhead:
    • Optional but enabled by default. Cache invalidation (e.g., after API changes) requires manual handling (e.g., Cache::forget()).
    • Mitigation: Disable caching in config/github.php if not needed or use graham-campbell/bounded-cache for TTL management.
  • Rate Limiting:
    • GitHub’s API enforces rate limits. Caching helps, but burst traffic may still trigger limits.
    • Mitigation: Implement exponential backoff (e.g., via KnpLabs/php-github-api’s built-in retry logic) or upgrade to a GitHub Enterprise plan.
  • Deprecation Risk:
    • Underlying php-github-api may deprecate endpoints. The package abstracts this but requires updates (e.g., v13.1 dropped PHP 8.0 support).
    • Mitigation: Monitor php-github-api’s changelog and test upgrades in staging.

Key Questions

  1. Authentication Strategy:
    • Which auth method fits your use case (e.g., token for CI/CD, application for OAuth apps)?
    • How will you secure credentials (e.g., .env, AWS Secrets Manager)?
  2. Performance Needs:
    • Do you need caching? If so, what TTLs (e.g., 5m for repos, 1h for user profiles)?
    • Will you handle cache invalidation manually or rely on GitHub’s ETag/Last-Modified headers?
  3. Error Handling:
    • How will you handle GitHub API errors (e.g., 403 Forbidden, 429 Too Many Requests)?
    • Should you extend the facade to add custom error responses?
  4. Multi-Connection Use Cases:
    • Do you need multiple GitHub connections (e.g., org vs. personal account)?
    • How will you manage connection-specific configurations (e.g., different tokens per connection)?
  5. Testing:
    • Will you mock the GitHub API in tests (e.g., using Mockery or Vcr)?
    • How will you test authentication failures (e.g., expired tokens)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Service Provider: Registers the GitHubManager and GitHub facade, integrating with Laravel’s IoC container.
    • Configuration: Publishes config/github.php, aligning with Laravel’s config-first approach.
    • Facades: Provides a fluent interface (e.g., GitHub::repo()->show()), reducing boilerplate for API calls.
  • PHP-GitHub-API:
    • Underlying client (KnpLabs/php-github-api) supports all GitHub REST API v3 endpoints (e.g., repos, issues, actions). The package adds Laravel-specific features (e.g., caching, multi-connection).
  • Authentication Methods:
    • Token: Simple for personal access tokens (e.g., CI/CD).
    • Application: OAuth apps (e.g., webhooks, user authorization).
    • JWT: For machine accounts (e.g., GitHub Apps).
    • Private Key: For GitHub Apps with private keys.
    • None: For public data (e.g., reading repo contents without auth).

Migration Path

  1. Assess Current GitHub API Usage:
    • Audit existing GitHub API calls (e.g., direct HTTP requests, Guzzle, or other libraries).
    • Identify authentication methods and endpoints used.
  2. Update Dependencies:
    • Ensure PHP 8.1+ and Laravel 10+ compatibility.
    • Update composer.json:
      "require": {
          "graham-campbell/github": "^13.1",
          "knplabs/github-api": "^3.16"
      }
      
  3. Install and Configure:
    • Run composer require graham-campbell/github.
    • Publish config: php artisan vendor:publish --provider="GrahamCampbell\GitHub\GitHubServiceProvider".
    • Configure config/github.php with your auth method (e.g., token):
      'connections' => [
          'main' => [
              'auth' => 'token',
              'token' => env('GITHUB_TOKEN'),
          ],
      ],
      
  4. Replace API Calls:
    • Old: Direct HTTP requests or Guzzle.
    • New: Use the facade or manager:
      // Old: Guzzle
      $client = new \GuzzleHttp\Client();
      $response = $client->get('https://api.github.com/user/orgs', [
          'auth' => [env('GITHUB_TOKEN'), 'x-oauth-basic']
      ]);
      
      // New: Facade
      $orgs = GitHub::me()->organizations();
      
    • For complex queries, use the underlying client:
      $client = GitHub::connection()->getClient();
      $issues = $client->api('issue')->all('GrahamCampbell', 'Laravel-GitHub');
      
  5. Test Incrementally:
    • Start with non-critical endpoints (e.g., public repo data).
    • Gradually migrate auth-sensitive endpoints (e.g., issues, PRs).
    • Test error cases (e.g., 401 Unauthorized, 404 Not Found).

Compatibility

  • Laravel Versions:
    • v13.1 supports Laravel 10–13. For older versions, use a compatible release (e.g., v12.8 for Laravel 11).
  • PHP Versions:
    • PHP 8.1–8.5. Avoid PHP 8.0 or below due to deprecations (e.g., lcobucci/jwt v4+).
  • GitHub API:
    • Uses php-github-api v3.x, which supports GitHub REST API v3. For GraphQL, use the underlying client directly.
  • Caching:
    • Defaults to graham-campbell/bounded-cache. For custom caching, extend the CacheFactory or disable caching in config.

Sequencing

  1. Phase 1: Setup and Configuration
    • Install the package and configure auth.
    • Set up .env for credentials (e.g., GITHUB_TOKEN).
  2. Phase 2: Core Integration
    • Replace direct API calls with the facade/manager.
    • Test basic endpoints (e.g
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky