@@ -62,14 +62,14 @@ public function handle(): int
6262 return $ this ->comparePackages ($ this ->githubService );
6363 }
6464 $ publicPackages = $ this ->githubService ->getMonorepoPackages (
65- config ('monorepo.github_org ' ),
65+ config ('monorepo.github_org ' ),
6666 config ('monorepo.public_repo ' ),
6767 config ('monorepo.packages_path ' )
6868 );
6969
7070 $ privatePackages = $ this ->githubService ->getMonorepoPackages (
7171 config ('monorepo.github_org ' ),
72- config ('monorepo.private_repo ' ),
72+ config ('monorepo.private_repo ' ),
7373 config ('monorepo.packages_path ' ),
7474 'private '
7575 );
@@ -83,18 +83,18 @@ public function handle(): int
8383 'public ' => $ publicPackages ,
8484 'private ' => $ privatePackages ,
8585 'org ' => array_fill_keys ($ orgPackages , ['type ' => 'org ' ]),
86- 'all ' => []
86+ 'all ' => [],
8787 ];
88-
88+
8989 // Merge all packages with type information
9090 foreach ($ publicPackages as $ package => $ info ) {
9191 $ packages ['all ' ][$ package ] = array_merge ($ info , ['type ' => 'public ' ]);
9292 }
9393 foreach ($ privatePackages as $ package => $ info ) {
94- $ packages ['all ' ][$ package ] = array_merge ($ info , ['type ' => 'private ' ]);
94+ $ packages ['all ' ][$ package ] = array_merge ($ info , ['type ' => 'private ' ]);
9595 }
9696 foreach ($ orgPackages as $ package ) {
97- if (!isset ($ packages ['all ' ][$ package ])) {
97+ if (! isset ($ packages ['all ' ][$ package ])) {
9898 $ packages ['all ' ][$ package ] = ['type ' => 'org ' ];
9999 }
100100 }
@@ -114,35 +114,33 @@ public function handle(): int
114114 // ->pluck('name')
115115 // ->toArray();
116116
117-
118117 $ currentVersion = $ this ->githubService ->getLatestReleaseTag (config ('monorepo.github_org ' ).'/ ' .config ('monorepo.public_repo ' ));
119118
120119 $ newVersion = $ this ->askForNewVersion ($ currentVersion );
121120 $ this ->info ("New version: {$ newVersion }\n" );
122121
123-
124122 $ missingPackagesResult = $ this ->packageComparisonService ->isNewOrgPackage (array_keys ($ packages ['public ' ]), array_keys ($ packages ['private ' ]), $ orgPackages );
125123
126124 // Flatten the missing packages result into a single array
127125 $ missingPackages = [];
128- if (!empty ($ missingPackagesResult ['public ' ])) {
126+ if (! empty ($ missingPackagesResult ['public ' ])) {
129127 foreach ($ missingPackagesResult ['public ' ] as $ package ) {
130128 $ missingPackages [$ package ] = ['minimum-stability ' => 'init ' , 'type ' => 'public ' ];
131129 }
132130 }
133- if (!empty ($ missingPackagesResult ['private ' ])) {
131+ if (! empty ($ missingPackagesResult ['private ' ])) {
134132 foreach ($ missingPackagesResult ['private ' ] as $ package ) {
135133 $ missingPackages [$ package ] = ['minimum-stability ' => 'init ' , 'type ' => 'private ' ];
136134 }
137135 }
138-
139- if (!empty ($ missingPackages )) {
136+
137+ if (! empty ($ missingPackages )) {
140138 $ this ->line ('Missing packages detected: ' );
141139 foreach ($ missingPackages as $ package => $ info ) {
142140 $ this ->line ("- {$ package } ( {$ info ['type ' ]}) " );
143141 }
144142 }
145-
143+
146144 // Process all packages with their messages (handled by the service)
147145 $ packagesWithMessages = $ this ->devlogService ->processAllPackagesForRelease (array_merge ($ packages ['public ' ], $ packages ['private ' ]));
148146
@@ -165,47 +163,46 @@ public function handle(): int
165163 // Extract and filter packages with messages for workflows
166164 $ publicPackagesWithMessages = [];
167165 $ privatePackagesWithMessages = [];
168-
169-
166+
170167 foreach ($ packagesWithMessages as $ packageName => $ packageInfo ) {
171168 if (array_key_exists ($ packageName , $ packages ['public ' ])) {
172169 $ publicPackagesWithMessages [$ packageName ] = $ packageInfo ;
173170 }
174-
171+
175172 if (array_key_exists ($ packageName , $ packages ['private ' ])) {
176173 $ privatePackagesWithMessages [$ packageName ] = $ packageInfo ;
177174 }
178175 }
179176
180177 // Trigger workflow for public packages
181- if (!empty ($ publicPackagesWithMessages )) {
182- $ this ->line (" 📦 Preparing public packages for workflow... " );
178+ if (! empty ($ publicPackagesWithMessages )) {
179+ $ this ->line (' 📦 Preparing public packages for workflow... ' );
183180 $ publicPackagesJson = $ this ->preparePackagesForWorkflow ($ publicPackagesWithMessages );
184-
181+
185182 $ this ->githubService ->triggerWorkflowDispatch (
186- config ('monorepo.github_org ' ),
187- config ('monorepo.public_repo ' ),
188- 'split.yml ' ,
189- 'main ' ,
183+ config ('monorepo.github_org ' ),
184+ config ('monorepo.public_repo ' ),
185+ 'split.yml ' ,
186+ 'main ' ,
190187 [
191188 'version ' => $ newVersion ,
192- 'packages ' => $ publicPackagesJson
189+ 'packages ' => $ publicPackagesJson,
193190 ]
194191 );
195192 }
196193
197- if (!empty ($ privatePackagesWithMessages )) {
198- $ this ->line (" 📦 Preparing private packages for workflow... " );
194+ if (! empty ($ privatePackagesWithMessages )) {
195+ $ this ->line (' 📦 Preparing private packages for workflow... ' );
199196 $ privatePackagesJson = $ this ->preparePackagesForWorkflow ($ privatePackagesWithMessages );
200-
197+
201198 $ this ->githubService ->triggerWorkflowDispatch (
202199 config ('monorepo.github_org ' ),
203200 config ('monorepo.private_repo ' ),
204201 'split.yml ' ,
205202 'main ' ,
206203 [
207- 'version ' => $ newVersion ,
208- 'packages ' => $ privatePackagesJson
204+ 'version ' => $ newVersion ,
205+ 'packages ' => $ privatePackagesJson,
209206 ]
210207 );
211208 }
@@ -228,53 +225,55 @@ protected function preparePackagesForWorkflow(array $packagesWithMessages, int $
228225 $ cleanMessage = $ this ->sanitizeMessage ($ message );
229226 $ sanitizedMessages [] = $ cleanMessage ;
230227 }
231-
228+
232229 // Keep all package info but sanitize the messages
233230 $ sanitizedPackages [$ package ] = array_merge ($ packageInfo , [
234- 'release-message ' => $ sanitizedMessages
231+ 'release-message ' => $ sanitizedMessages,
235232 ]);
236233 }
237-
234+
238235 $ packagesJson = json_encode ($ sanitizedPackages , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
239236 $ currentLength = strlen ($ packagesJson );
240-
237+
241238 if ($ currentLength <= $ maxLength ) {
242- $ this ->line ("✅ Packages JSON size: " . number_format ($ currentLength ) . " bytes (within limit) " );
239+ $ this ->line ('✅ Packages JSON size: ' .number_format ($ currentLength ).' bytes (within limit) ' );
240+
243241 return $ packagesJson ;
244242 }
245-
246- $ this ->warn (" ⚠️ Packages JSON too large: " . number_format ($ currentLength ) . " bytes (limit: " . number_format ($ maxLength ) . " ) " );
247- $ this ->line (" Truncating messages to fit GitHub workflow input limits... " );
248-
243+
244+ $ this ->warn (' ⚠️ Packages JSON too large: ' . number_format ($ currentLength ). ' bytes (limit: ' . number_format ($ maxLength ). ' ) ' );
245+ $ this ->line (' Truncating messages to fit GitHub workflow input limits... ' );
246+
249247 // Truncate messages to fit within limit
250248 $ truncatedPackages = [];
251249 foreach ($ sanitizedPackages as $ package => $ packageInfo ) {
252250 $ messages = $ packageInfo ['release-message ' ] ?? ['Release update ' ];
253251 // Keep only first message and truncate if needed
254- $ firstMessage = is_array ($ messages ) && !empty ($ messages ) ? $ messages [0 ] : 'Release update ' ;
255- $ truncatedMessage = strlen ($ firstMessage ) > 100 ? substr ($ firstMessage , 0 , 97 ) . '... ' : $ firstMessage ;
256-
252+ $ firstMessage = is_array ($ messages ) && ! empty ($ messages ) ? $ messages [0 ] : 'Release update ' ;
253+ $ truncatedMessage = strlen ($ firstMessage ) > 100 ? substr ($ firstMessage , 0 , 97 ). '... ' : $ firstMessage ;
254+
257255 $ truncatedPackages [$ package ] = array_merge ($ packageInfo , [
258- 'release-message ' => [$ truncatedMessage ]
256+ 'release-message ' => [$ truncatedMessage ],
259257 ]);
260258 }
261-
259+
262260 $ truncatedJson = json_encode ($ truncatedPackages , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
263261 $ newLength = strlen ($ truncatedJson );
264-
262+
265263 if ($ newLength > $ maxLength ) {
266264 // If still too large, just use package names with generic message
267- $ this ->error (" Still too large after truncation. Using generic messages. " );
265+ $ this ->error (' Still too large after truncation. Using generic messages. ' );
268266 $ genericPackages = [];
269267 foreach ($ packagesWithMessages as $ package => $ packageInfo ) {
270268 $ genericPackages [$ package ] = array_merge ($ packageInfo , [
271- 'release-message ' => ['Release update ' ]
269+ 'release-message ' => ['Release update ' ],
272270 ]);
273271 }
274272 $ truncatedJson = json_encode ($ genericPackages , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
275273 }
276-
277- $ this ->line ("✅ Truncated to: " . number_format (strlen ($ truncatedJson )) . " bytes " );
274+
275+ $ this ->line ('✅ Truncated to: ' .number_format (strlen ($ truncatedJson )).' bytes ' );
276+
278277 return $ truncatedJson ;
279278 }
280279
@@ -283,7 +282,7 @@ protected function sanitizeMessage(string $message): string
283282 // Remove or replace problematic characters for bash
284283 $ message = str_replace ([
285284 '( ' , ') ' , // Parentheses cause syntax errors
286- '` ' , // Backticks for command substitution
285+ '` ' , // Backticks for command substitution
287286 '$ ' , // Variable expansion
288287 '" ' , // Double quotes
289288 "' " , // Single quotes - replace with safe alternative
@@ -296,19 +295,19 @@ protected function sanitizeMessage(string $message): string
296295 '' , // Remove single quotes
297296 ' ' , ' ' , ' ' , // Replace whitespace with spaces
298297 ], $ message );
299-
298+
300299 // Trim and limit length
301300 $ message = trim ($ message );
302301 if (strlen ($ message ) > 200 ) {
303- $ message = substr ($ message , 0 , 197 ) . '... ' ;
302+ $ message = substr ($ message , 0 , 197 ). '... ' ;
304303 }
305-
304+
306305 return $ message ;
307306 }
308307
309308 protected function showVersions (GitHubService $ github ): int
310309 {
311- $ mainRepo = config ('monorepo.github_org ' ) . '/ ' . config ('monorepo.public_repo ' );
310+ $ mainRepo = config ('monorepo.github_org ' ). '/ ' . config ('monorepo.public_repo ' );
312311 $ org = config ('monorepo.github_org ' );
313312
314313 try {
@@ -634,22 +633,22 @@ protected function changeGithubWorkflow(array $newPackages, string $version): vo
634633 $ existingPackages = array_map (function ($ line ) {
635634 return trim (str_replace ('- ' , '' , $ line ));
636635 }, $ packageLines );
637-
636+
638637 // Filter out empty lines
639638 $ existingPackages = array_filter ($ existingPackages );
640-
639+
641640 // Add new packages that don't already exist
642641 $ packagesToAdd = [];
643642 foreach ($ newPackages as $ package => $ info ) {
644- if (!in_array ($ package , $ existingPackages )) {
643+ if (! in_array ($ package , $ existingPackages )) {
645644 $ packagesToAdd [] = $ package ;
646645 $ this ->line ("Adding package {$ package } to workflow file " );
647646 } else {
648647 $ this ->line ("Package {$ package } already exists in workflow file " );
649648 }
650649 }
651-
652- if (!empty ($ packagesToAdd )) {
650+
651+ if (! empty ($ packagesToAdd )) {
653652 // Merge and sort all packages
654653 $ allPackages = array_merge ($ existingPackages , $ packagesToAdd );
655654 sort ($ allPackages );
@@ -660,7 +659,7 @@ protected function changeGithubWorkflow(array $newPackages, string $version): vo
660659 }
661660
662661 $ content = preg_replace ('/package:\s*\n(\s+- .+\n)+/ ' , "package: \n{$ sortedPackageList }" , $ content );
663-
662+
664663 file_put_contents ($ workflowPath , $ content );
665664 $ this ->line ('✅ Updated GitHub workflow with ' .count ($ packagesToAdd ).' new packages ' );
666665 } else {
@@ -674,11 +673,11 @@ protected function changeGithubWorkflow(array $newPackages, string $version): vo
674673 protected function createRelease (string $ version ): void
675674 {
676675 $ repo = config ('monorepo.public_repo ' , 'mooxphp/moox ' );
677-
676+
678677 $ this ->line ("Creating monorepo release for version: {$ version }" );
679-
678+
680679 $ result = $ this ->githubService ->createRelease ($ repo , $ version , "Release version {$ version }, initial release " );
681-
680+
682681 if ($ result !== null ) {
683682 $ this ->line ('✅ Successfully created monorepo release ' );
684683 $ this ->line ("Release created: v {$ version }" );
@@ -691,23 +690,22 @@ protected function triggerMonorepoSplitWorkflow(string $version, array $packages
691690 {
692691 $ repo = config ('monorepo.public_repo ' , 'mooxphp/moox ' );
693692 $ workflowFile = 'monorepo-split-packages.yml ' ;
694-
693+
695694 $ this ->line ("Triggering monorepo split workflow for version: {$ version }" );
696-
695+
697696 $ inputs = [
698697 'version ' => $ version ,
699698 'packages ' => json_encode ($ packages ),
700699 ];
701-
700+
702701 $ result = $ this ->githubService ->triggerWorkflowDispatch ($ repo , $ workflowFile , 'main ' , $ inputs );
703-
702+
704703 if ($ result !== null ) {
705704 $ this ->line ('✅ Successfully triggered monorepo split workflow ' );
706- $ this ->line (" Packages to be split: " . implode (', ' , $ packages ));
705+ $ this ->line (' Packages to be split: ' . implode (', ' , $ packages ));
707706 $ this ->line ("You can monitor the workflow at: https://github.com/ {$ repo }/actions " );
708707 } else {
709708 $ this ->error ('❌ Failed to trigger monorepo split workflow ' );
710709 }
711710 }
712-
713711}
0 commit comments