@@ -454,16 +454,17 @@ function publishSplit(array $package, string $sha, ?string $tag, array &$errors)
454454{
455455 $ name = (string ) $ package ['name ' ];
456456 $ repository = (string ) $ package ['repository ' ];
457+ $ publishRepository = publishRepositoryUrl ($ repository );
457458
458459 if (null !== $ tag ) {
459- publishTag ($ name , $ repository , $ sha , $ tag , $ errors );
460+ publishTag ($ name , $ repository , $ publishRepository , $ sha , $ tag , $ errors );
460461
461462 return ;
462463 }
463464
464465 $ branch = (string ) $ package ['branch ' ];
465466 $ refspec = sprintf ('%s:refs/heads/%s ' , $ sha , $ branch );
466- $ command = sprintf ('git push %s %s 2>&1 ' , escapeshellarg ($ repository ), escapeshellarg ($ refspec ));
467+ $ command = sprintf ('git push %s %s 2>&1 ' , escapeshellarg ($ publishRepository ), escapeshellarg ($ refspec ));
467468 exec ($ command , $ output , $ exitCode );
468469 if (0 !== $ exitCode ) {
469470 $ errors [] = sprintf ('%s branch publish failed: %s ' , $ name , implode (PHP_EOL , $ output ));
@@ -474,12 +475,12 @@ function publishSplit(array $package, string $sha, ?string $tag, array &$errors)
474475 fwrite (STDOUT , sprintf (' pushed: %s -> %s:%s ' , $ sha , $ repository , $ branch ) . PHP_EOL );
475476}
476477
477- function publishTag (string $ name , string $ repository , string $ sha , string $ tag , array &$ errors ): void
478+ function publishTag (string $ name , string $ repository , string $ publishRepository , string $ sha , string $ tag , array &$ errors ): void
478479{
479480 $ remoteTagRef = 'refs/tags/ ' . $ tag ;
480481 $ lookupCommand = sprintf (
481482 'git ls-remote --tags --refs %s %s 2>&1 ' ,
482- escapeshellarg ($ repository ),
483+ escapeshellarg ($ publishRepository ),
483484 escapeshellarg ($ remoteTagRef ),
484485 );
485486 exec ($ lookupCommand , $ lookupOutput , $ lookupExitCode );
@@ -503,7 +504,7 @@ function publishTag(string $name, string $repository, string $sha, string $tag,
503504 }
504505
505506 $ refspec = sprintf ('%s:%s ' , $ sha , $ remoteTagRef );
506- $ pushCommand = sprintf ('git push %s %s 2>&1 ' , escapeshellarg ($ repository ), escapeshellarg ($ refspec ));
507+ $ pushCommand = sprintf ('git push %s %s 2>&1 ' , escapeshellarg ($ publishRepository ), escapeshellarg ($ refspec ));
507508 exec ($ pushCommand , $ pushOutput , $ pushExitCode );
508509 if (0 !== $ pushExitCode ) {
509510 $ errors [] = sprintf ('%s tag publish failed for %s: %s ' , $ name , $ tag , implode (PHP_EOL , $ pushOutput ));
@@ -514,6 +515,19 @@ function publishTag(string $name, string $repository, string $sha, string $tag,
514515 fwrite (STDOUT , sprintf (' pushed tag: %s -> %s:%s ' , $ sha , $ repository , $ tag ) . PHP_EOL );
515516}
516517
518+ function publishRepositoryUrl (string $ repository ): string
519+ {
520+ if (preg_match ('#^git@github\.com:([^/]+/[^/]+?)(?:\.git)?$# ' , $ repository , $ matches )) {
521+ return 'https://github.com/ ' . $ matches [1 ] . '.git ' ;
522+ }
523+
524+ if (preg_match ('#^ssh://git@github\.com/([^/]+/[^/]+?)(?:\.git)?$# ' , $ repository , $ matches )) {
525+ return 'https://github.com/ ' . $ matches [1 ] . '.git ' ;
526+ }
527+
528+ return $ repository ;
529+ }
530+
517531function commandExists (string $ command ): bool
518532{
519533 exec (sprintf ('command -v %s >/dev/null 2>&1 ' , escapeshellarg ($ command )), $ output , $ exitCode );
0 commit comments