### Install with Composer Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-github-contributions ``` -------------------------------- ### Development commands for tests, static analysis, and formatting Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Run these commands to execute the test suite, run PHPStan static analysis, and format code with Pint. ```bash # Run tests vendor/bin/pest # Run static analysis vendor/bin/phpstan analyse # Format code vendor/bin/pint ``` -------------------------------- ### Run Tests Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Run the test suite. ```bash composer test ``` -------------------------------- ### Service provider configurePackage method Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Registers the package name and config file using spatie/laravel-package-tools. The shortName() strips the 'laravel-' prefix, so the config key is 'github-contributions'. ```php public function configurePackage(Package $package): void { $package ->name('laravel-github-contributions') ->hasConfigFile(); } ``` -------------------------------- ### Publish Config File Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Publish the optional configuration file. ```bash php artisan vendor:publish --tag="laravel-github-contributions-config" ``` -------------------------------- ### Publish the package config file Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Run this Artisan command to publish the configuration file to config/github-contributions.php. ```bash php artisan vendor:publish --tag=laravel-github-contributions-config ``` -------------------------------- ### Run Static Analysis Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Run static analysis with PHPStan. ```bash composer analyse ``` -------------------------------- ### Config Options in config/github-contributions.php Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Configuration options for the package. The token falls back to services.github.token when empty. Cache TTL defaults to 3600 seconds; set to 0 to disable caching. ```php // config/github-contributions.php return [ // Falls back to config('services.github.token') when empty. 'token' => env('GITHUB_TOKEN'), 'user_agent' => env('GITHUB_CONTRIBUTIONS_USER_AGENT', 'laravel-github-contributions'), 'timeout' => (int) env('GITHUB_CONTRIBUTIONS_TIMEOUT', 8), // Cache responses (keyed by login) to stay under the 5000/hr API limit. // Set ttl to 0 to disable caching entirely. 'cache' => [ 'ttl' => (int) env('GITHUB_CONTRIBUTIONS_CACHE_TTL', 3600), ], ]; ``` -------------------------------- ### Environment variables for GitHub token, user agent, and timeout Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Set these environment variables to configure the package. GITHUB_TOKEN is required; the others have defaults. ```env GITHUB_TOKEN=ghp_your_personal_access_token GITHUB_CONTRIBUTIONS_USER_AGENT=laravel-github-contributions GITHUB_CONTRIBUTIONS_TIMEOUT=8 ``` -------------------------------- ### Run Code Formatting Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Run code formatting. ```bash composer format ``` -------------------------------- ### Package configuration file Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md The published config file with token, user_agent, and timeout settings. The user_agent defaults to 'laravel-github-contributions' and timeout to 8 seconds. ```php // config/github-contributions.php return [ 'token' => env('GITHUB_TOKEN'), 'user_agent' => env('GITHUB_CONTRIBUTIONS_USER_AGENT', 'laravel-github-contributions'), 'timeout' => (int) env('GITHUB_CONTRIBUTIONS_TIMEOUT', 8), ]; ``` -------------------------------- ### Namespace structure of the package Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Shows the main classes in the JeffersonGoncalves\GitHubContributions namespace: the service provider and the static fetch method. ```text JeffersonGoncalves\GitHubContributions\ GitHubContributionsServiceProvider # Registers the config file GitHubContributions # Static fetch(string $login): array ``` -------------------------------- ### Resolve GitHub token from config Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Uses the package config token as primary, falling back to services.github.token. This allows integration with apps that already configure the GitHub service. ```php $token = config('github-contributions.token') ?: config('services.github.token'); ``` -------------------------------- ### Test no-token path returns empty Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Pest test that clears both token configs, fakes HTTP, and asserts fetch returns empty cells and total 0, and that no HTTP request is sent. ```php it('returns empty when no token is configured', function () { config()->set('github-contributions.token', null); config()->set('services.github.token', null); Http::fake(); expect(GitHubContributions::fetch('testuser'))->toBe(['cells' => [], 'total' => 0]); Http::assertNothingSent(); }); ``` -------------------------------- ### Set GITHUB_TOKEN in .env Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Add your GitHub Personal Access Token to the .env file. The token requires the read:user scope. ```env GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx ``` -------------------------------- ### Fetch GitHub Contributions Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/README.md Fetch the contribution calendar for a GitHub login. Returns an array with 'cells' (flat 0-4 heatmap array, column-major, 7 per week) and 'total'. If no token is configured or the API request fails, returns ['cells' => [], 'total' => 0]. ```php use JeffersonGoncalves\GitHubContributions\GitHubContributions; $data = GitHubContributions::fetch('jeffersongoncalves'); // [ // 'cells' => [0, 1, 0, 2, 4, 3, 0, ...], // list, 7 per week, column-major // 'total' => 1234, // total contributions in the calendar window // ] ``` -------------------------------- ### Mock GraphQL endpoint and test level mapping Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Pest test that fakes the GitHub GraphQL API and asserts the cells array is correctly mapped. The fake response includes a week with two days. ```php use Illuminate\Support\Facades\Http; use JeffersonGoncalves\GitHubContributions\GitHubContributions; it('maps contribution levels to cells', function () { Http::fake([ 'api.github.com/graphql' => Http::response([ 'data' => ['user' => ['contributionsCollection' => ['contributionCalendar' => [ 'totalContributions' => 28, 'weeks' => [[ 'contributionDays' => [ ['contributionCount' => 0, 'contributionLevel' => 'NONE', 'weekday' => 0], ['contributionCount' => 1, 'contributionLevel' => 'FIRST_QUARTILE', 'weekday' => 1], ], ]], ]]]], ]]), ]); expect(GitHubContributions::fetch('testuser')['cells']) ->toBe([0, 1, 0, 0, 0, 0, 0]); }); ``` -------------------------------- ### Map GitHub contributionLevel enum to integer Source: https://github.com/jeffersongoncalves/laravel-github-contributions/blob/master/resources/boost/skills/github-contributions-development/SKILL.md Maps the GitHub contributionLevel enum values to integers 1-4. NONE or any other value maps to 0. ```php // GitHub contributionLevel enum -> int 'FIRST_QUARTILE' => 1, 'SECOND_QUARTILE' => 2, 'THIRD_QUARTILE' => 3, 'FOURTH_QUARTILE' => 4, // NONE / anything else => 0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.