in src/shipit/ShipItGitHubUtils.php [35:83]
public abstract static function genCredentialsForProject(
string $organization,
string $project,
): Awaitable<ShipItGitHubCredentials>;
/**
* Configure the user and origin for a repository, cloning if necessary.
*
* - requires getCredentialsForProject() to be implemented
* - configures 'origin' to be authenticated HTTPS
*/
final public static async function genInitializeRepo(
string $organization,
string $project,
string $local_path,
ShipItTransport $transport,
?ShipItGitHubCredentials $credentials,
): Awaitable<void> {
$git_config = (string $key, string $value) ==>
new ShipItShellCommand($local_path, 'git', 'config', $key, $value);
switch ($transport) {
case ShipItTransport::SSH:
invariant(
$credentials === null,
'Credentials should not be specified for SSH transport',
);
$origin =
Str\format('git@github.com:%s/%s.git', $organization, $project);
await self::genCloneAndVerifyRepo($origin, $local_path);
break;
case ShipItTransport::HTTPS:
$origin =
Str\format('https://github.com/%s/%s.git', $organization, $project);
if ($credentials === null) {
await self::genCloneAndVerifyRepo($origin, $local_path);
break;
}
$origin = self::authHttpsRemoteUrl($origin, $transport, $credentials);
await self::genCloneAndVerifyRepo($origin, $local_path);
await $git_config('user.name', $credentials['name'])->genRun();
await $git_config('user.email', $credentials['email'])->genRun();
break;
}
await $git_config('remote.origin.url', $origin)->genRun();
}