Skip to content

Commit 7dc3c52

Browse files
Fix styling
1 parent a653d44 commit 7dc3c52

File tree

2 files changed

+53
-54
lines changed

2 files changed

+53
-54
lines changed

packages/monorepo/src/Commands/CreateRelease.php

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use App\Models\User;
66
use Illuminate\Console\Command;
77
use Moox\Monorepo\Services\GitHubService;
8-
use Moox\Monorepo\Services\ReleaseService;
98
use Moox\Monorepo\Services\PackageComparisonService;
9+
use Moox\Monorepo\Services\ReleaseService;
1010

1111
class CreateRelease extends Command
1212
{
@@ -15,40 +15,43 @@ class CreateRelease extends Command
1515
protected $description = 'Create a release for the monorepo';
1616

1717
protected PackageComparisonService $packageComparisonService;
18+
1819
protected GitHubService $githubService;
1920

20-
//TODO
21-
// 1. Check the current version of this monorepo from GitHub API ✓
22-
// 2. Ask the user for the new version, e.g. 4.2.11 ✓
23-
// 3. Read directory of all packages (also private) ✓
24-
// 4. If repos do not exist, create them (2nd iteration)
25-
// 5. For each new repo, add it to devlink.php (2nd iteration)
26-
// 6. Read the DEVLOG.md file ✓
27-
// 7. Suggest contents from the DEVLOG.md file ✓
28-
// 8. New packages without DEVLOG-entry are "Initial release"
29-
// 9. Otherwise, "Compatibility release" for all other packages
30-
// 10. Split all packages
31-
// Core version in composer schreiben!
32-
// 11. Create a new tag and release in all repos
33-
// 12. Create a new Packagist.org package or Satis (3rd iteration)
34-
// 13. Update the packages in the packages table (3rd iteration)
35-
// 14. Webplate für translation release! And look at the translation commit from webplate (3rd iteration)
21+
// TODO
22+
// 1. Check the current version of this monorepo from GitHub API ✓
23+
// 2. Ask the user for the new version, e.g. 4.2.11 ✓
24+
// 3. Read directory of all packages (also private) ✓
25+
// 4. If repos do not exist, create them (2nd iteration)
26+
// 5. For each new repo, add it to devlink.php (2nd iteration)
27+
// 6. Read the DEVLOG.md file ✓
28+
// 7. Suggest contents from the DEVLOG.md file ✓
29+
// 8. New packages without DEVLOG-entry are "Initial release"
30+
// 9. Otherwise, "Compatibility release" for all other packages
31+
// 10. Split all packages
32+
// Core version in composer schreiben!
33+
// 11. Create a new tag and release in all repos
34+
// 12. Create a new Packagist.org package or Satis (3rd iteration)
35+
// 13. Update the packages in the packages table (3rd iteration)
36+
// 14. Webplate für translation release! And look at the translation commit from webplate (3rd iteration)
3637

3738
protected $devlog;
38-
public function __construct(){
39+
40+
public function __construct()
41+
{
3942
parent::__construct();
4043
$this->githubService = new GitHubService(User::first()?->github_token);
4144
$this->packageComparisonService = new PackageComparisonService($this->githubService, config('monorepo.organization', 'mooxphp'));
4245
}
46+
4347
public function handle(): int
4448
{
45-
4649
$token = User::first()?->github_token;
47-
if (! $token) {
48-
$this->error('No GitHub token found. Please link your GitHub account.');
49-
return 1;
50-
}
51-
50+
if (! $token) {
51+
$this->error('No GitHub token found. Please link your GitHub account.');
52+
53+
return 1;
54+
}
5255

5356
switch (true) {
5457
case $this->option('versions'):
@@ -63,7 +66,7 @@ public function handle(): int
6366

6467
$devlog = $this->parseDevlog($newVersion);
6568

66-
//TODO es soll nur erkennen, dass es neu ist
69+
// TODO es soll nur erkennen, dass es neu ist
6770
foreach ($devlog as $package => $messages) {
6871
if ($this->packageComparisonService->isNewPackage($package)) {
6972
$this->info("New package: {$package}");
@@ -75,7 +78,6 @@ public function handle(): int
7578

7679
protected function showVersions(GitHubService $github): int
7780
{
78-
7981
$mainRepo = config('monorepo.public_repo', 'mooxphp/moox');
8082
$org = 'mooxphp';
8183

@@ -106,27 +108,27 @@ protected function comparePackages(GitHubService $github): int
106108
$localPackages = collect(array_merge(
107109
\Illuminate\Support\Facades\File::directories(base_path($publicBasePath)),
108110
$privateBasePath !== 'disabled' ? \Illuminate\Support\Facades\File::directories(base_path($privateBasePath)) : []
109-
))->map(fn($dir) => basename($dir))
110-
->toArray();
111+
))->map(fn ($dir) => basename($dir))
112+
->toArray();
111113

112114
$devlogCommits = $this->parseDevlog();
113115

114116
$commitMessages = collect($localPackages)->mapWithKeys(function ($package) use ($devlogCommits) {
115117
if (isset($devlogCommits[$package])) {
116118
return [$package => $devlogCommits[$package]];
117119
}
120+
118121
return [$package => ['Compatibility release']];
119122
});
120123

121-
122-
123124
$this->packageComparisonService = new PackageComparisonService($github, config('monorepo.organization', 'mooxphp'));
124125
$devlinkPackages = $this->packageComparisonService->extractDevlinkPackages();
125126
$comparison = $this->packageComparisonService->comparePackagesWithRepositories($localPackages, $devlinkPackages);
126127
$this->table(
127-
['Org. Package', 'Has single Repo' , 'Is in Devlink Config', 'Commit Messages'],
128-
$comparison->map(function($exists, $package) use ($devlinkPackages, $commitMessages) {
128+
['Org. Package', 'Has single Repo', 'Is in Devlink Config', 'Commit Messages'],
129+
$comparison->map(function ($exists, $package) use ($devlinkPackages, $commitMessages) {
129130
$messages = $commitMessages[strtolower($package)] ?? ['Not in Monorepo'];
131+
130132
return [
131133
$package,
132134
$exists ? '' : '',
@@ -145,31 +147,30 @@ public function askForNewVersion(string $currentVersion): string
145147
$this->info('No existing release found. Starting with version 0.0.1.');
146148
$currentVersion = '0.0.1';
147149
$suggestedVersion = $currentVersion;
148-
149150
} else {
150151
$this->info("Current version: {$currentVersion}");
151152
[$major, $minor, $patch] = explode('.', $currentVersion);
152-
$suggestedVersion = "$major.$minor." . ((int)$patch + 1);
153+
$suggestedVersion = "$major.$minor.".((int) $patch + 1);
153154
}
154155

155-
156-
$version = $this->ask("Enter the new version:", $suggestedVersion);
157-
156+
$version = $this->ask('Enter the new version:', $suggestedVersion);
157+
158158
if (! $this->validateVersionFormat($version)) {
159159
$this->error('Invalid version format. Please use X.X.X format.');
160+
160161
return $this->askForNewVersion($currentVersion);
161162
}
162-
163+
163164
if (! $this->validateVersionOrder($version, $currentVersion)) {
164165
$this->error('New version cannot be smaller than the current version.');
166+
165167
return $this->askForNewVersion($currentVersion);
166168
}
167-
169+
168170
return $version;
169-
170171
}
171-
172-
//Helper methods
172+
173+
// Helper methods
173174
private function validateVersionFormat(string $version): bool
174175
{
175176
return preg_match('/^\\d+\\.\\d+\\.\\d+$/', $version);
@@ -192,7 +193,7 @@ protected function parseDevlog(): array
192193
foreach ($lines as $line) {
193194
if (preg_match('/^##\s+(.*)$/', $line, $matches)) {
194195
$currentPackage = trim($matches[1]);
195-
if (!isset($commits[strtolower($currentPackage)])) {
196+
if (! isset($commits[strtolower($currentPackage)])) {
196197
$commits[strtolower($currentPackage)] = [];
197198
}
198199
} elseif ($currentPackage && preg_match('/^-\s+(.*)$/', $line, $matches)) {

packages/monorepo/src/Services/PackageComparisonService.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class PackageComparisonService
88
{
99
protected GitHubService $githubService;
10+
1011
protected string $organization;
1112

1213
public function __construct(GitHubService $githubService, string $organization)
@@ -27,33 +28,30 @@ public function comparePackagesWithRepositories(array $localPackages, array $dev
2728

2829
return $comparison;
2930
}
30-
3131

3232
public function extractNotPublishedPackages(Collection $comparison): Collection
3333
{
34-
return $comparison->filter(fn($exists) => !$exists);
34+
return $comparison->filter(fn ($exists) => ! $exists);
3535
}
3636

3737
public function extractDevlinkPackages(): array
3838
{
3939
$devlinkConfig = config('devlink.packages');
40+
4041
return array_keys($devlinkConfig);
4142
}
4243

4344
public function isNewPackage(string $package): bool
4445
{
4546
$publicBasePath = config('devlink.public_base_path', '../moox/packages');
4647
$privateBasePath = config('devlink.private_base_path', 'disabled');
47-
48+
4849
$localPackages = collect(array_merge(
4950
\Illuminate\Support\Facades\File::directories(base_path($publicBasePath)),
5051
$privateBasePath !== 'disabled' ? \Illuminate\Support\Facades\File::directories(base_path($privateBasePath)) : []
51-
))->map(fn($dir) => basename($dir))
52-
->toArray();
53-
54-
return !in_array(strtolower($package), array_map('strtolower', $localPackages));
55-
56-
}
57-
52+
))->map(fn ($dir) => basename($dir))
53+
->toArray();
5854

59-
}
55+
return ! in_array(strtolower($package), array_map('strtolower', $localPackages));
56+
}
57+
}

0 commit comments

Comments
 (0)