Skip to content

Commit fd7a139

Browse files
committed
Revert mock changes
1 parent 6085f91 commit fd7a139

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1718
-2284
lines changed

.github/workflows/main.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ jobs:
4040
- name: Checkout code
4141
uses: actions/checkout@v4
4242

43+
- name: Setup Node.js
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: '20.x'
47+
48+
- name: Cache node_modules directory
49+
uses: actions/cache@v4
50+
id: node_modules-cache
51+
with:
52+
path: node_modules
53+
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
54+
55+
- name: Install NPM packages
56+
if: steps.node_modules-cache.outputs.cache-hit != 'true'
57+
run: npm ci --include=dev
58+
4359
- name: Install PHP versions
4460
uses: shivammathur/setup-php@v2
4561
with:
@@ -56,6 +72,8 @@ jobs:
5672
with:
5773
path: ${{ steps.composer-cache.outputs.dir }}
5874
key: ${{ runner.os }}-composer-laravel-10-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
75+
restore-keys: |
76+
${{ runner.os }}-composer-laravel-10-${{ matrix.php }}-
5977
6078
- name: Cache PHP dependencies (vendor)
6179
uses: actions/cache@v4
@@ -91,7 +109,7 @@ jobs:
91109
SESSION_DRIVER: array
92110
TTY: true
93111

94-
run: vendor/bin/pest --no-parallel
112+
run: vendor/bin/pest
95113

96114
- name: Execute Code Sniffer via Laravel Pint
97115
run: vendor/bin/pint --test src config
@@ -126,6 +144,22 @@ jobs:
126144
- name: Checkout code
127145
uses: actions/checkout@v4
128146

147+
- name: Setup Node.js
148+
uses: actions/setup-node@v4
149+
with:
150+
node-version: '20.x'
151+
152+
- name: Cache node_modules directory
153+
uses: actions/cache@v4
154+
id: node_modules-cache
155+
with:
156+
path: node_modules
157+
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
158+
159+
- name: Install NPM packages
160+
if: steps.node_modules-cache.outputs.cache-hit != 'true'
161+
run: npm ci --include=dev
162+
129163
- name: Install PHP versions
130164
uses: shivammathur/setup-php@v2
131165
with:
@@ -142,6 +176,8 @@ jobs:
142176
with:
143177
path: ${{ steps.composer-cache.outputs.dir }}
144178
key: ${{ runner.os }}-composer-laravel-11-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
179+
restore-keys: |
180+
${{ runner.os }}-composer-laravel-11-${{ matrix.php }}-
145181
146182
- name: Cache PHP dependencies (vendor)
147183
uses: actions/cache@v4

src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,11 @@ public function getDockerContainer(): string
198198
*/
199199
protected function analizeCommittedFiles(Collection $commitFiles): self
200200
{
201-
/**
202-
* @var Collection<int, ChangedFile> $chunk
203-
*/
201+
/** @var Collection<int, ChangedFile> $chunk */
204202
foreach ($commitFiles->chunk($this->chunkSize) as $chunk) {
205203
$filePaths = [];
206204

207-
/**
208-
* @var ChangedFile $file
209-
*/
205+
/** @var ChangedFile $file */
210206
foreach ($chunk as $file) {
211207
if (! $this->canFileBeAnalyzed($file)) {
212208
continue;
@@ -355,9 +351,9 @@ protected function suggestAutoFixOrExit(): bool
355351
return true;
356352
}
357353
} else {
358-
if (Terminal::hasSttyAvailable()
359-
&& $this->command->confirm('Would you like to attempt to correct files automagically?')
360-
&& $this->autoFixFiles()
354+
if (Terminal::hasSttyAvailable() &&
355+
$this->command->confirm('Would you like to attempt to correct files automagically?') &&
356+
$this->autoFixFiles()
361357
) {
362358
return true;
363359
}

src/Console/Commands/Hooks/ESLintPreCommitHook.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@ public function handle(ChangedFiles $files, Closure $next): mixed
3939
*/
4040
public function analyzerCommand(): string
4141
{
42-
return trim(
43-
implode(
44-
' ', [
45-
$this->getAnalyzerExecutable(),
46-
$this->configParam,
47-
$this->additionalParams(),
48-
]
49-
)
50-
);
42+
return trim(implode(' ', [
43+
$this->getAnalyzerExecutable(),
44+
$this->configParam,
45+
$this->additionalParams(),
46+
]));
5147
}
5248

5349
/**

src/Console/Commands/MakeHook.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@ public function handle()
4949
$supportedHooks = GitHooks::getSupportedHooks();
5050

5151
if (! in_array($this->argument('hookType'), $supportedHooks)) {
52-
$this->getOutput()->writeln(
53-
sprintf(
54-
'<bg=red;fg=white> ERROR </> Invalid hook type. Valid types are: <comment>%s</comment>',
55-
implode(', ', $supportedHooks)
56-
)
57-
);
52+
$this->getOutput()->writeln(sprintf(
53+
'<bg=red;fg=white> ERROR </> Invalid hook type. Valid types are: <comment>%s</comment>',
54+
implode(', ', $supportedHooks)
55+
));
5856

5957
return true;
6058
}

src/Git/Log.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,22 @@ public function __construct(protected string $log)
4141
*/
4242
private function parse(array $lines): void
4343
{
44-
$handlers = collect(
45-
[
46-
'commit' => function ($line): void {
47-
preg_match('/(?<hash>[a-z0-9]{40})/', $line, $matches);
48-
$this->hash = $matches['hash'] ?? null;
49-
},
50-
'Author' => function ($line): void {
51-
$this->author = substr($line, strlen('Author:') + 1);
52-
},
53-
'Date' => function ($line): void {
54-
$this->date = Carbon::parse(substr($line, strlen('Date:') + 3));
55-
},
56-
'Merge' => function ($line): void {
57-
$merge = substr($line, strlen('Merge:') + 1);
58-
$this->merge = explode(' ', $merge);
59-
},
60-
]
61-
);
44+
$handlers = collect([
45+
'commit' => function ($line): void {
46+
preg_match('/(?<hash>[a-z0-9]{40})/', $line, $matches);
47+
$this->hash = $matches['hash'] ?? null;
48+
},
49+
'Author' => function ($line): void {
50+
$this->author = substr($line, strlen('Author:') + 1);
51+
},
52+
'Date' => function ($line): void {
53+
$this->date = Carbon::parse(substr($line, strlen('Date:') + 3));
54+
},
55+
'Merge' => function ($line): void {
56+
$merge = substr($line, strlen('Merge:') + 1);
57+
$this->merge = explode(' ', $merge);
58+
},
59+
]);
6260

6361
foreach ($lines as $line) {
6462
$handler = $handlers->first(fn ($handler, $prefix) => Str::startsWith($line, $prefix));

src/GitHooksServiceProvider.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,20 @@ class GitHooksServiceProvider extends ServiceProvider
1414
public function boot(): void
1515
{
1616
if ($this->app->runningInConsole()) {
17-
$this->publishes(
18-
[
19-
__DIR__.'/../config/git-hooks.php' => $this->app->configPath('git-hooks.php'),
20-
], 'laravel-git-hooks'
21-
);
17+
$this->publishes([
18+
__DIR__.'/../config/git-hooks.php' => $this->app->configPath('git-hooks.php'),
19+
], 'laravel-git-hooks');
2220

2321
// Registering package commands.
24-
$this->commands(
25-
[
26-
\Igorsgm\GitHooks\Console\Commands\RegisterHooks::class,
27-
\Igorsgm\GitHooks\Console\Commands\CommitMessage::class,
28-
\Igorsgm\GitHooks\Console\Commands\PreCommit::class,
29-
\Igorsgm\GitHooks\Console\Commands\PrepareCommitMessage::class,
30-
\Igorsgm\GitHooks\Console\Commands\PostCommit::class,
31-
\Igorsgm\GitHooks\Console\Commands\PrePush::class,
32-
\Igorsgm\GitHooks\Console\Commands\MakeHook::class,
33-
]
34-
);
22+
$this->commands([
23+
\Igorsgm\GitHooks\Console\Commands\RegisterHooks::class,
24+
\Igorsgm\GitHooks\Console\Commands\CommitMessage::class,
25+
\Igorsgm\GitHooks\Console\Commands\PreCommit::class,
26+
\Igorsgm\GitHooks\Console\Commands\PrepareCommitMessage::class,
27+
\Igorsgm\GitHooks\Console\Commands\PostCommit::class,
28+
\Igorsgm\GitHooks\Console\Commands\PrePush::class,
29+
\Igorsgm\GitHooks\Console\Commands\MakeHook::class,
30+
]);
3531
}
3632
}
3733

src/Traits/GitHelper.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ public function updateCommitMessageContentInFile(string $path, string $message):
4848
*/
4949
public function isMergeInProgress(): bool
5050
{
51-
$command = $this->runCommands(
52-
'git merge HEAD', [
53-
'silent' => true,
54-
]
55-
);
51+
$command = $this->runCommands('git merge HEAD', [
52+
'silent' => true,
53+
]);
5654

5755
// If a merge is in progress, the process returns code 128
5856
return $command->getExitCode() === 128;

src/Traits/ProcessHelper.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ public function runCommands(string|array $commands, array $params = []): Process
4949
}
5050
}
5151

52-
$process->run(
53-
! $showOutput ? null : function (string $line) use ($output): void {
54-
if ($output !== null) {
55-
$output->write(' '.$line);
56-
}
52+
$process->run(! $showOutput ? null : function (string $line) use ($output): void {
53+
if ($output !== null) {
54+
$output->write(' '.$line);
5755
}
58-
);
56+
});
5957

6058
return $process;
6159
}
@@ -66,15 +64,13 @@ public function runCommands(string|array $commands, array $params = []): Process
6664
*/
6765
public function transformCommands(string|array $commands, callable $callback): array
6866
{
69-
return array_map(
70-
function ($value) use ($callback) {
71-
if (str_starts_with($value, 'chmod')) {
72-
return $value;
73-
}
74-
75-
return $callback($value);
76-
}, (array) $commands
77-
);
67+
return array_map(function ($value) use ($callback) {
68+
if (str_starts_with($value, 'chmod')) {
69+
return $value;
70+
}
71+
72+
return $callback($value);
73+
}, (array) $commands);
7874
}
7975

8076
/**

tests/Datasets/GitLogsDataset.php

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,51 @@
11
<?php
22

3-
dataset(
4-
'lastCommitLogText', [
5-
'Default Git Log' => sprintf(
6-
'commit %s
3+
dataset('lastCommitLogText', [
4+
'Default Git Log' => sprintf('commit %s
75
Author: Igor Moraes <[email protected]>
86
Date: Wed Nov 9 04:50:40 2022 -0800
97
108
wip
11-
', mockCommitHash()
12-
),
13-
]
14-
);
9+
', mockCommitHash()),
10+
]);
1511

16-
dataset(
17-
'mergeLogText', [
18-
'Merge Git Log' => sprintf(
19-
"commit %s
12+
dataset('mergeLogText', [
13+
'Merge Git Log' => sprintf("commit %s
2014
Merge: 123abc 456def
2115
Author: Igor Moraes <[email protected]>
2216
Date: Wed Nov 9 04:50:40 2022 -0800
2317
2418
Merge branch 'main' of github.com:igorsgm/laravel-git-hooks
2519
26-
", mockCommitHash()
27-
),
28-
]
29-
);
30-
31-
dataset(
32-
'listOfChangedFiles', [
33-
'List Of Changed Files' => 'AM src/ChangedFiles.php',
34-
]
35-
);
36-
37-
dataset(
38-
'listOfFixablePhpFiles', [
39-
'List of Fixable Files' => implode(
40-
PHP_EOL, [
41-
'AM temp/ClassWithFixableIssues.php',
42-
'AM temp/fixable-blade-file.blade.php',
43-
]
44-
),
45-
]
46-
);
47-
48-
dataset(
49-
'listOfRectorPhpFiles', [
50-
'List of Rector Files' => implode(
51-
PHP_EOL, [
52-
'AM temp/ClassWithRectorIssues.php',
53-
'AM temp/fixable-blade-file.blade.php',
54-
]
55-
),
56-
]
57-
);
58-
59-
dataset(
60-
'listOfFixableJSFiles', [
61-
'List of Fixable Files' => implode(
62-
PHP_EOL, [
63-
'AM temp/fixable-js-file.js',
64-
]
65-
),
66-
]
67-
);
68-
69-
dataset(
70-
'listOfNonFixableJSFiles', [
71-
'List of Fixable Files' => implode(
72-
PHP_EOL, [
73-
'AM temp/not-fully-fixable-js-file.js',
74-
]
75-
),
76-
]
77-
);
20+
", mockCommitHash()),
21+
]);
22+
23+
dataset('listOfChangedFiles', [
24+
'List Of Changed Files' => 'AM src/ChangedFiles.php',
25+
]);
26+
27+
dataset('listOfFixablePhpFiles', [
28+
'List of Fixable Files' => implode(PHP_EOL, [
29+
'AM temp/ClassWithFixableIssues.php',
30+
'AM temp/fixable-blade-file.blade.php',
31+
]),
32+
]);
33+
34+
dataset('listOfRectorPhpFiles', [
35+
'List of Rector Files' => implode(PHP_EOL, [
36+
'AM temp/ClassWithRectorIssues.php',
37+
'AM temp/fixable-blade-file.blade.php',
38+
]),
39+
]);
40+
41+
dataset('listOfFixableJSFiles', [
42+
'List of Fixable Files' => implode(PHP_EOL, [
43+
'AM temp/fixable-js-file.js',
44+
]),
45+
]);
46+
47+
dataset('listOfNonFixableJSFiles', [
48+
'List of Fixable Files' => implode(PHP_EOL, [
49+
'AM temp/not-fully-fixable-js-file.js',
50+
]),
51+
]);

0 commit comments

Comments
 (0)