diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 1371704..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..5c06f43 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,22 @@ +name: Static analysis + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + pint: + name: Pint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2 + with: + php-version: '8.4' + coverage: none + - run: composer update --prefer-dist --no-interaction + - run: vendor/bin/pint --test diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..90cba86 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,29 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['8.4', '8.5'] + stability: [prefer-lowest, prefer-stable] + + name: PHP ${{ matrix.php }} · ${{ matrix.stability }} + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2 + with: + php-version: ${{ matrix.php }} + coverage: none + - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + - run: vendor/bin/pest --ci diff --git a/CHANGELOG.md b/CHANGELOG.md index ff90bfb..d9792c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ -## 1.0.0 - 2023-03-25 +# Changelog -- First release. +All notable changes to `laranail/git-commit-checker` are documented in this file. + +The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +_Nothing yet._ + +## v0.1.0 + +### Changed + +- **Public names are vendor-scoped.** The config key is `laranail.git-commit-checker` and the view namespace + `laranail/git-commit-checker`, where both were the bare `git-commit-checker`. Publish tags were already scoped. + Breaking for anyone reading the old names. +- **PHP `>=8.0` → `^8.4.1 || ^8.5`**, the family floor. +- **Requires the `illuminate/*` components it uses** rather than `laravel/framework`. +- **`laravel/pint` moved to `require-dev`.** It was in `require`, forcing a dev tool into every + consuming application. + +### Added + +- A test suite and CI, neither of which this package had. +- `LICENSE` (MIT), and a `docs/` tree. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..940c789 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Simtabi LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 0356be2..1345655 100755 --- a/README.md +++ b/README.md @@ -1,68 +1,29 @@ -![banner](.github/assets/banner.png?raw=true) +# laranail/git-commit-checker -Git Commit Checker -============ -A highly opinionated Git pre-commit hooks for coding standards checking, and syntax fixing for the Laravel framework. +[![Packagist](https://img.shields.io/packagist/v/laranail/git-commit-checker.svg)](https://packagist.org/packages/laranail/git-commit-checker) +[![Tests](https://github.com/laranail/git-commit-checker/actions/workflows/tests.yml/badge.svg)](https://github.com/laranail/git-commit-checker/actions/workflows/tests.yml) +[![Static analysis](https://github.com/laranail/git-commit-checker/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/laranail/git-commit-checker/actions/workflows/static-analysis.yml) +[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) -Requirements -============ +> Git pre-commit hooks for coding-standard and syntax checks in Laravel projects. -To be able to use this package you need to meet the following minimum requirements: -1. Laravel framework >= v9 -2. PHP >= v8.0 +Requires PHP `^8.4.1 || ^8.5` and Laravel `^13.0`. -**** - -## Installation - -You can install the package via composer: - -```shell -composer require laranail/git-commit-checker -``` - -To publish views and config files for further manipulation, run the following commands: +## Install ```bash -php artisan vendor:publish laranail::git-commit-checker-config -php artisan vendor:publish laranail::git-commit-checker-views -``` - -### Install GIT hooks - -Run this command to install: - -```shell -php artisan git-commit-checker:install -``` - -Run test manually (made sure you've added all changed files to git stage): - -```shell -php artisan git-commit-checker:pre-commit-hook +composer require laranail/git-commit-checker ``` -### Changelog - -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. - -## Contributing - -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. - -### Security - -If you discover any security related issues, please email minhsang2603@gmail.com instead of using the issue tracker. +## Documentation -Credits -============ -This project wouldn't have been possible without the inspiration and ideas borrowed from many sources across the open source community, -we say thank you to the respective authors. +Full documentation is at +**[opensource.simtabi.com/documentation/laranail/git-commit-checker](https://opensource.simtabi.com/documentation/laranail/git-commit-checker/)**. -## Contributors +### Project -- [All Contributors](CONTRIBUTORS.md) +- [Architecture](docs/architecture.md) — what this package registers, and under which names. ## License -The MIT License (MIT). Please see [License File](LICENSE.md) for more information. +MIT. See [LICENSE](LICENSE). diff --git a/composer.json b/composer.json index 545ba75..c3439cd 100644 --- a/composer.json +++ b/composer.json @@ -1,57 +1,70 @@ { - "name": "laranail/git-commit-checker", - "description": "A highly opinionated Git pre-commit hooks for coding standards checking, and syntax fixing for the Laravel framework.", - "type": "package", - "license": "MIT", - "keywords": [ - "simtabi", - "simtabi cms", - "simtabi platform", - "simtabi git commit checker", - "git", - "commit checker" - ], - "homepage": "https://simtabi.com", - "authors": [ - { - "name": "Imani Manyara", - "role": "Developer", - "homepage": "https://simtabi.com" + "name": "laranail/git-commit-checker", + "description": "Git pre-commit hooks for coding-standard and syntax checks in Laravel projects.", + "type": "package", + "license": "MIT", + "keywords": [ + "simtabi", + "simtabi cms", + "simtabi platform", + "simtabi git commit checker", + "git", + "commit checker" + ], + "homepage": "https://opensource.simtabi.com/products/laranail/git-commit-checker", + "authors": [ + { + "name": "Imani Manyara", + "role": "Developer", + "homepage": "https://simtabi.com" + }, + { + "name": "Easter Mukora", + "role": "Developer", + "homepage": "https://simtabi.com" + } + ], + "autoload": { + "psr-4": { + "Simtabi\\Laranail\\GitCommitChecker\\": "src" + } }, - { - "name": "Easter Mukora", - "role": "Developer", - "homepage": "https://simtabi.com" - } - ], - "autoload": { - "psr-4": { - "Simtabi\\Laranail\\GitCommitChecker\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "Simtabi\\Laranail\\GitCommitChecker\\Tests\\": "tests" - } - }, - "require": { - "php": ">=8.0", - "laravel/framework": ">=9.32", - "laravel/pint": ">=1.4.0" - }, - "require-dev": { - "phpunit/phpunit": ">=9.0" - }, - "extra": { - "laravel": { - "providers": [ - "Simtabi\\Laranail\\GitCommitChecker\\Providers\\GitCommitCheckerServiceProvider" - ] - } - }, - - "config": { - "sort-packages": true - }, - "minimum-stability": "stable" + "autoload-dev": { + "psr-4": { + "Simtabi\\Laranail\\GitCommitChecker\\Tests\\": "tests/" + } + }, + "require": { + "php": "^8.4.1 || ^8.5", + "illuminate/console": "^13.0", + "illuminate/support": "^13.0" + }, + "require-dev": { + "laravel/pint": "^1.18", + "orchestra/testbench": "^11.1", + "pestphp/pest": "^4.6" + }, + "extra": { + "laravel": { + "providers": [ + "Simtabi\\Laranail\\GitCommitChecker\\Providers\\GitCommitCheckerServiceProvider" + ] + }, + "branch-alias": { + "dev-main": "0.1.x-dev" + } + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } + }, + "minimum-stability": "stable", + "support": { + "issues": "https://github.com/laranail/git-commit-checker/issues", + "source": "https://github.com/laranail/git-commit-checker", + "docs": "https://opensource.simtabi.com/documentation/laranail/git-commit-checker/" + }, + "prefer-stable": true } diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..58d1a49 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,42 @@ +# Architecture + +What this package registers, and the names it claims. + +## Public names + +Laravel keeps view namespaces and config keys in **flat global maps**. A second package claiming a +key does not collide loudly — it silently replaces the first, and the failure surfaces far away as a +missing view or the wrong config value. A bare slug like `git-commit-checker` is a plausible collision with a +sibling package, a third-party one, or the consuming application's own. + +| Surface | Name | +|---|---| +| Config key | `laranail.git-commit-checker` | +| View namespace | `laranail/git-commit-checker` | +| Publish tags | `laranail::git-commit-checker-*` | + +Views take the slash form because Laravel interpolates the namespace into the override path, so a +published override lands in `resources/views/vendor/laranail/git-commit-checker` — one directory per vendor +rather than thirty siblings flat in the `vendor` root. + +**This package previously claimed the bare `git-commit-checker` for both the config key and the view namespace.** +Its publish tags were already vendor-scoped, which is what made the gap easy to miss by eye: two of +the four names were right. + +`tests/Feature/NamingConventionTest.php` asserts this against the **live registries** — +`View::getFinder()->getHints()` and the config repository — rather than by grepping the provider, so +the guard survives a refactor of the registration code. + +## Modernisation + +This package predates the family conventions. Adopting it moved: + +- PHP `>=8.0` → `^8.4.1 || ^8.5`, the family floor. +- `laravel/framework >=9.x` → the individual `illuminate/*` components it actually uses. A package + should not require the whole framework. +- `laravel/pint` out of `require` and into `require-dev`. It is a dev tool, and requiring it forced + it into every consuming application. + +--- + +[← Docs index](../README.md#documentation) diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index 86720d2..0000000 Binary files a/src/.DS_Store and /dev/null differ diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index c5a6d43..8a0a70b 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -1,4 +1,6 @@ -components->error("Class [$class] is not instance of " . Command::class . '.'); + $this->components->error("Class [$class] is not instance of ".Command::class.'.'); abort(1); } $script = $this->generateHookScript($command->getName()); - $path = $this->laravel->basePath('.git/hooks/' . $hook); + $path = $this->laravel->basePath('.git/hooks/'.$hook); $relativePath = ltrim(str_replace($this->laravel->basePath(), '', $path), DIRECTORY_SEPARATOR); if ( $this->laravel['files']->exists($path) && - ! $this->confirmToProceed($relativePath . ' already exists, do you want to overwrite it?', true) + ! $this->confirmToProceed($relativePath.' already exists, do you want to overwrite it?', true) ) { return false; } @@ -104,9 +106,9 @@ protected function generatePintConfiguration(string $path): void ? ['preset' => $preset] : $this->laravel['config']->get('git-commit-checker.pint.recommended_preset'), JSON_PRETTY_PRINT - ) . PHP_EOL + ).PHP_EOL )) { - $this->components->error('Unable to write ' . $path); + $this->components->error('Unable to write '.$path); abort(1); } diff --git a/src/Commands/PreCommitHookCommand.php b/src/Commands/PreCommitHookCommand.php index 07f4c04..4857c9a 100644 --- a/src/Commands/PreCommitHookCommand.php +++ b/src/Commands/PreCommitHookCommand.php @@ -1,4 +1,6 @@ -getOutput(), true); render( - view('git-commit-checker::summary', [ + view('laranail/git-commit-checker::summary', [ 'result' => $result, 'isSuccessful' => $process->isSuccessful(), ]) diff --git a/src/Providers/CommandServiceProvider.php b/src/Providers/CommandServiceProvider.php index 3bbd5a1..116bd35 100644 --- a/src/Providers/CommandServiceProvider.php +++ b/src/Providers/CommandServiceProvider.php @@ -1,10 +1,12 @@ -mergeConfigFrom(__DIR__ . '/../../config/config.php', 'git-commit-checker'); + $this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'laranail.git-commit-checker'); } + public function boot() { $this->app->register(CommandServiceProvider::class); - $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'git-commit-checker'); + $this->loadViewsFrom(__DIR__.'/../../resources/views', 'laranail/git-commit-checker'); if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__ . '/../../config/config.php' => config_path('git-commit-checker.php'), + __DIR__.'/../../config/config.php' => config_path('git-commit-checker.php'), ], 'laranail::git-commit-checker-config'); $this->publishes([ - __DIR__ . '/../../resources/views' => resource_path('views/vendor/git-commit-checker') + __DIR__.'/../../resources/views' => resource_path('views/vendor/laranail/git-commit-checker'), ], 'laranail::git-commit-checker-views'); } } diff --git a/tests/Feature/NamingConventionTest.php b/tests/Feature/NamingConventionTest.php new file mode 100644 index 0000000..f5cdbad --- /dev/null +++ b/tests/Feature/NamingConventionTest.php @@ -0,0 +1,29 @@ +toBeArray() + ->and(Config::get('git-commit-checker'))->toBeNull(); +}); + +it('registers its views under vendor and slug, never a bare one', function (): void { + $hints = View::getFinder()->getHints(); + + expect($hints)->toHaveKey('laranail/git-commit-checker') + ->and($hints)->not->toHaveKey('git-commit-checker'); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..2d4d1f8 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,6 @@ +in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..60f8855 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,16 @@ +