Skip to content

Commit 723162c

Browse files
authored
Fix output render, make sure it can be run on Windows (#10)
resolved #9
1 parent e76fc87 commit 723162c

7 files changed

Lines changed: 101 additions & 22 deletions

File tree

.gitattributes

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
/.gitattributes export-ignore
2-
/.gitignore export-ignore
3-
/phpunit.xml.dist export-ignore
4-
/tests export-ignore
5-
/.github export-ignore
6-
/.editorconfig export-ignore
7-
/pint.json export-ignore
1+
* text=auto
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.gitattributes export-ignore
10+
/.gitignore export-ignore
11+
/.github export-ignore
12+
/.editorconfig export-ignore
13+
/art export-ignore
14+
/phpunit.xml.dist export-ignore
15+
/pint.json export-ignore
16+
/tests export-ignore

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Laravel GIT Commit Checker
22

3-
[![Latest Version](https://img.shields.io/packagist/v/botble/git-commit-checker.svg?style=flat-square)](https://github.com/botble/git-commit-checker/releases)
4-
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
5-
[![Total Downloads](https://img.shields.io/packagist/dt/botble/git-commit-checker.svg?style=flat-square)](https://packagist.org/packages/botble/git-commit-checker)
6-
[![Maintainability](https://api.codeclimate.com/v1/badges/a6e4612307e3b3bf8252/maintainability)](https://codeclimate.com/github/botble/git-commit-checker/maintainability)
3+
<p align="center">
4+
<img src="/art/overview.png" alt="Overview Git Commit Checker" style="width:70%;">
5+
</p>
6+
7+
<p align="center">
8+
<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>
9+
<a href="/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="Software License"></a>
10+
<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>
11+
<a href="https://codeclimate.com/github/botble/git-commit-checker/maintainability"><img src="https://api.codeclimate.com/v1/badges/a6e4612307e3b3bf8252/maintainability" alt="Maintainability"></a>
12+
</p>
713

814
## Requirement
915

art/overview.png

239 KB
Loading

resources/views/summary.blade.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<div class="mx-2">
2+
@if(! $isSuccessful)
3+
@foreach($result['files'] as $file)
4+
<div class="mb-1 mt-2">
5+
<span class="px-1 bg-red text-white uppercase">File</span>
6+
<span class="ml-1">{{ ltrim(str_replace(base_path(), '', $file['name']), '/') }}</span>
7+
</div>
8+
9+
<div class="flex max-w-150">
10+
<span>Rules</span>
11+
<span class="flex-1 content-repeat-[.] text-gray ml-1"></span>
12+
<span class="ml-1">
13+
@foreach($file['appliedFixers'] as $fixer)
14+
<span class="text-red ml-1">{{ $fixer . ($loop->last ? '' : ', ') }}</span>
15+
@endforeach
16+
</span>
17+
</div>
18+
19+
<div class="flex space-x-1 mt-1">
20+
<span class="flex-1 content-repeat-[─] text-gray"></span>
21+
</div>
22+
@endforeach
23+
24+
<div class="mb-2"></div>
25+
@endif
26+
27+
<div class="flex space-x-1 mb-2">
28+
<span class="font-bold">
29+
Checked <span class="text-yellow">{{ count($result['files']) }}</span> files in <span class="text-yellow">{{ $result['time']['total'] ?? 0 }}</span> seconds.
30+
Using memory <span class="text-yellow">{{ $result['memory'] }}</span> MB.
31+
</span>
32+
</div>
33+
34+
@if(! $isSuccessful)
35+
<div class="mb-1">
36+
<span class="px-1 bg-yellow text-white uppercase">Warn</span>
37+
<span class="ml-1">
38+
Run <span class="text-yellow">./vendor/bin/pint --dirty --test -v</span> to see coding standard detail issues.
39+
</span>
40+
</div>
41+
<div class="mb-1">
42+
<span class="px-1 bg-yellow text-white uppercase">Warn</span>
43+
<span class="ml-1">
44+
Run <span class="text-yellow">./vendor/bin/pint --dirty</span> to fix coding standard issues.
45+
</span>
46+
</div>
47+
@else
48+
<div class="mb-1">
49+
<span class="px-1 bg-green text-white uppercase">Success</span>
50+
<span class="ml-1">Your code is perfect, no syntax error found!</span>
51+
</div>
52+
@endif
53+
</div>

src/Commands/InstallCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Botble\GitCommitChecker\Commands;
44

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

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

4243
return self::SUCCESS;
4344
}
4445

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

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

8081
protected function generateHookScript(string $signature): string
8182
{
82-
$artisan = addslashes($this->laravel->basePath('artisan'));
83-
84-
return "#!/bin/sh\n\nphp $artisan $signature\n";
83+
return sprintf("#!/bin/sh\n\n%s\n", Application::formatCommandString($signature));
8584
}
8685

8786
protected function generatePintConfiguration(string $path): void
@@ -110,7 +109,9 @@ protected function generatePintConfiguration(string $path): void
110109
abort(1);
111110
}
112111

113-
$this->components->info("Created [$path] using $presets[$preset] preset successfully");
112+
$this->components->info(
113+
"Created <comment>$path</comment> using <comment>$presets[$preset]</comment> preset successfully"
114+
);
114115
}
115116

116117
protected function writeHookScript(string $path, string $script): bool

src/Commands/PreCommitHookCommand.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Symfony\Component\Console\Attribute\AsCommand;
88
use Symfony\Component\Process\Process;
99

10+
use function Termwind\render;
11+
1012
#[AsCommand('git-commit-checker:pre-commit-hook', 'Git hook before commit')]
1113
class PreCommitHookCommand extends Command
1214
{
@@ -31,20 +33,26 @@ public function handle(): int
3133
$command = [
3234
$this->laravel->basePath('vendor/bin/pint'),
3335
'--test',
36+
'--format=json',
37+
'-v',
3438
];
3539

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

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

40-
$process->setTty(true);
41-
4244
$process->run();
4345

44-
if (! $process->isSuccessful()) {
45-
$this->components->warn('Run <comment>./vendor/bin/pint --dirty --test -v</comment> to see coding standard detail issues');
46-
$this->components->warn('Run <comment>./vendor/bin/pint --dirty</comment> to fix coding standard issues');
46+
$result = json_decode($process->getOutput(), true);
47+
48+
render(
49+
view('git-commit-checker::summary', [
50+
'result' => $result,
51+
'isSuccessful' => $process->isSuccessful(),
52+
])
53+
);
4754

55+
if ($process->isSuccessful()) {
4856
return self::FAILURE;
4957
}
5058

src/Providers/GitCommitCheckerServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function boot()
1717
{
1818
$this->app->register(CommandServiceProvider::class);
1919

20+
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'git-commit-checker');
21+
2022
if ($this->app->runningInConsole()) {
2123
$this->publishes([
2224
__DIR__ . '/../../config/git-commit-checker.php' => config_path('git-commit-checker.php'),

0 commit comments

Comments
 (0)