Skip to content

Fix output render, make sure it can be run on Windows #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/.github export-ignore
/.editorconfig export-ignore
/pint.json export-ignore
* text=auto

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/.editorconfig export-ignore
/art export-ignore
/phpunit.xml.dist export-ignore
/pint.json export-ignore
/tests export-ignore
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Laravel GIT Commit Checker

[![Latest Version](https://img.shields.io/packagist/v/botble/git-commit-checker.svg?style=flat-square)](https://github.com/botble/git-commit-checker/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Total Downloads](https://img.shields.io/packagist/dt/botble/git-commit-checker.svg?style=flat-square)](https://packagist.org/packages/botble/git-commit-checker)
[![Maintainability](https://api.codeclimate.com/v1/badges/a6e4612307e3b3bf8252/maintainability)](https://codeclimate.com/github/botble/git-commit-checker/maintainability)
<p align="center">
<img src="/art/overview.png" alt="Overview Git Commit Checker" style="width:70%;">
</p>

<p align="center">
<a href="https://packagist.org/packages/botble/git-commit-checker"><img src="https://img.shields.io/packagist/v/botble/git-commit-checker.svg?style=flat-square" alt="Latest Version"></a>
<a href="/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="Software License"></a>
<a href="https://packagist.org/packages/botble/git-commit-checker"><img src="https://img.shields.io/packagist/dt/botble/git-commit-checker.svg?style=flat-square" alt="Total Downloads"></a>
<a href="https://codeclimate.com/github/botble/git-commit-checker/maintainability"><img src="https://api.codeclimate.com/v1/badges/a6e4612307e3b3bf8252/maintainability" alt="Maintainability"></a>
</p>

## Requirement

Expand Down
Binary file added art/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions resources/views/summary.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<div class="mx-2">
@if(! $isSuccessful)
@foreach($result['files'] as $file)
<div class="mb-1 mt-2">
<span class="px-1 bg-red text-white uppercase">File</span>
<span class="ml-1">{{ ltrim(str_replace(base_path(), '', $file['name']), '/') }}</span>
</div>

<div class="flex max-w-150">
<span>Rules</span>
<span class="flex-1 content-repeat-[.] text-gray ml-1"></span>
<span class="ml-1">
@foreach($file['appliedFixers'] as $fixer)
<span class="text-red ml-1">{{ $fixer . ($loop->last ? '' : ', ') }}</span>
@endforeach
</span>
</div>

<div class="flex space-x-1 mt-1">
<span class="flex-1 content-repeat-[─] text-gray"></span>
</div>
@endforeach

<div class="mb-2"></div>
@endif

<div class="flex space-x-1 mb-2">
<span class="font-bold">
Checked <span class="text-yellow">{{ count($result['files']) }}</span> files in <span class="text-yellow">{{ $result['time']['total'] ?? 0 }}</span> seconds.
Using memory <span class="text-yellow">{{ $result['memory'] }}</span> MB.
</span>
</div>

@if(! $isSuccessful)
<div class="mb-1">
<span class="px-1 bg-yellow text-white uppercase">Warn</span>
<span class="ml-1">
Run <span class="text-yellow">./vendor/bin/pint --dirty --test -v</span> to see coding standard detail issues.
</span>
</div>
<div class="mb-1">
<span class="px-1 bg-yellow text-white uppercase">Warn</span>
<span class="ml-1">
Run <span class="text-yellow">./vendor/bin/pint --dirty</span> to fix coding standard issues.
</span>
</div>
@else
<div class="mb-1">
<span class="px-1 bg-green text-white uppercase">Success</span>
<span class="ml-1">Your code is perfect, no syntax error found!</span>
</div>
@endif
</div>
13 changes: 7 additions & 6 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Botble\GitCommitChecker\Commands;

use Illuminate\Console\Application;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down Expand Up @@ -35,14 +36,14 @@ public function handle(): int
$pintConfigFilePath = $this->laravel->basePath('pint.json');

if ($this->laravel['files']->exists($pintConfigFilePath)) {
if ($this->components->confirm('A pint.json exists. Do you want to overwrite this file?')) {
if ($this->components->confirm('A <comment>pint.json</comment> exists. Do you want to overwrite this file?')) {
$this->generatePintConfiguration($pintConfigFilePath);
}

return self::SUCCESS;
}

if ($this->components->confirm('A pint.json does not exists. Do you want to create this file?')) {
if ($this->components->confirm('A <comment>pint.json</comment> does not exists. Do you want to create this file?')) {
$this->generatePintConfiguration($pintConfigFilePath);
}

Expand Down Expand Up @@ -79,9 +80,7 @@ protected function install(string $hook, string $class): bool

protected function generateHookScript(string $signature): string
{
$artisan = addslashes($this->laravel->basePath('artisan'));

return "#!/bin/sh\n\nphp $artisan $signature\n";
return sprintf("#!/bin/sh\n\n%s\n", Application::formatCommandString($signature));
}

protected function generatePintConfiguration(string $path): void
Expand Down Expand Up @@ -110,7 +109,9 @@ protected function generatePintConfiguration(string $path): void
abort(1);
}

$this->components->info("Created [$path] using $presets[$preset] preset successfully");
$this->components->info(
"Created <comment>$path</comment> using <comment>$presets[$preset]</comment> preset successfully"
);
}

protected function writeHookScript(string $path, string $script): bool
Expand Down
18 changes: 13 additions & 5 deletions src/Commands/PreCommitHookCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Process\Process;

use function Termwind\render;

#[AsCommand('git-commit-checker:pre-commit-hook', 'Git hook before commit')]
class PreCommitHookCommand extends Command
{
Expand All @@ -31,20 +33,26 @@ public function handle(): int
$command = [
$this->laravel->basePath('vendor/bin/pint'),
'--test',
'--format=json',
'-v',
];

$command = array_merge($command, $uncommittedFiles);

$process = $this->getProcess($command);

$process->setTty(true);

$process->run();

if (! $process->isSuccessful()) {
$this->components->warn('Run <comment>./vendor/bin/pint --dirty --test -v</comment> to see coding standard detail issues');
$this->components->warn('Run <comment>./vendor/bin/pint --dirty</comment> to fix coding standard issues');
$result = json_decode($process->getOutput(), true);

render(
view('git-commit-checker::summary', [
'result' => $result,
'isSuccessful' => $process->isSuccessful(),
])
);

if ($process->isSuccessful()) {
return self::FAILURE;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Providers/GitCommitCheckerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function boot()
{
$this->app->register(CommandServiceProvider::class);

$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'git-commit-checker');

if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/../../config/git-commit-checker.php' => config_path('git-commit-checker.php'),
Expand Down