Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clone progress bar #1

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Scripts/GitScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Ochorocho\Tdk\Scripts;

use Composer\Script\Event;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Filesystem\Filesystem;

class GitScript
{
private static string $coreDevFolder = 'typo3-core';

public static function setGerritPushUrl(Event $event)
{
$typo3AccountUsername = $event->getIO()->askAndValidate('What is your TYPO3/Gerrit Account Username? ', '', 2);
if(!empty($typo3AccountUsername)) {
$pushUrl = '"ssh://' . $typo3AccountUsername . '@review.typo3.org:29418/Packages/TYPO3.CMS.git"';
$process = new ProcessExecutor();
$command = 'git config remote.origin.pushurl ' . $pushUrl;
$status = $process->execute($command, $output, self::$coreDevFolder);

if($status) {
$event->getIO()->writeError('<error>Could not enable Git Commit Template!</error>');
} else {
$event->getIO()->write('<info>Set "remote.origin.pushurl" to ' . $pushUrl . ' </info>');
}
}
}

public static function setCommitTemplate(Event $event)
{
$process = new ProcessExecutor();
$template = realpath('./.gitmessage.txt');
$status = $process->execute('git config commit.template ' . $template, $output, self::$coreDevFolder);

if($status) {
$event->getIO()->writeError('<error>Could not enable Git Commit Template!</error>');
} else {
$event->getIO()->write('<info>Set "commit.template" to ' . $template . ' </info>');
}
}

public static function cloneRepository(Event $event)
{
$filesystem = new Filesystem();
if(!$filesystem->exists(static::$coreDevFolder)) {
$process = new ProcessExecutor();
$gitRemoteUrl = 'git@github.com:TYPO3/typo3.git';
$command = sprintf('git clone %s %s', ProcessExecutor::escape($gitRemoteUrl), ProcessExecutor::escape(static::$coreDevFolder));
$event->getIO()->write('<info>Cloning TYPO3 repository. This may take a while depending on your internet connection!</info>');
$status = $process->executeTty($command);

if($status) {
$event->getIO()->write('<warning>Could not download git repository ' . $gitRemoteUrl . ' </warning>');
}
} else {
$event->getIO()->write('Repository exists! Therefore no download required.');
}
}
}
54 changes: 0 additions & 54 deletions Scripts/InitializeScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

namespace Ochorocho\Tdk\Scripts;

use Composer\Util\Git;
use Composer\Script\Event;
use Composer\Util\Filesystem as ComposerFilesystem;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;

Expand Down Expand Up @@ -87,36 +84,6 @@ private static function enablePreCommitHook(Event $event)
}
}

public static function setGerritPushUrl(Event $event)
{
$typo3AccountUsername = $event->getIO()->askAndValidate('What is your TYPO3/Gerrit Account Username? ', '', 2);
if(!empty($typo3AccountUsername)) {
$pushUrl = '"ssh://' . $typo3AccountUsername . '@review.typo3.org:29418/Packages/TYPO3.CMS.git"';
$process = new ProcessExecutor();
$command = 'git config remote.origin.pushurl ' . $pushUrl;
$status = $process->execute($command, $output, self::$coreDevFolder);

if($status) {
$event->getIO()->writeError('<error>Could not enable Git Commit Template!</error>');
} else {
$event->getIO()->write('<info>Set "remote.origin.pushurl" to ' . $pushUrl . ' </info>');
}
}
}

public static function setCommitTemplate(Event $event)
{
$process = new ProcessExecutor();
$template = realpath('./.gitmessage.txt');
$status = $process->execute('git config commit.template ' . $template, $output, self::$coreDevFolder);

if($status) {
$event->getIO()->writeError('<error>Could not enable Git Commit Template!</error>');
} else {
$event->getIO()->write('<info>Set "commit.template" to ' . $template . ' </info>');
}
}

public static function createDdevConfig(Event $event)
{
// Only ask for ddev config if ddev command is available
Expand Down Expand Up @@ -158,27 +125,6 @@ public static function createDdevConfig(Event $event)
}
}

public static function cloneRepo(Event $event)
{
$filesystem = new Filesystem();

if(!$filesystem->exists(static::$coreDevFolder)) {
$process = new ProcessExecutor();
$composerFilesystem = new ComposerFilesystem();
$gitRemoteUrl = 'git@github.com:TYPO3/typo3.git';

$git = new Git($event->getIO(), $event->getComposer()->getConfig(), $process, $composerFilesystem);
$commandCallable = function ($gitRemoteUrl) {
return sprintf('git clone %s %s', ProcessExecutor::escape($gitRemoteUrl), ProcessExecutor::escape(static::$coreDevFolder));
};

$event->getIO()->write('Cloning TYPO3 repository. This may take a while depending on your internet connection!');
$git->runCommand($commandCallable, $gitRemoteUrl, static::$coreDevFolder, true);
} else {
$event->getIO()->write('Repository exists! Therefore no download required.');
}
}

public static function removeFilesAndFolders(Event $event)
{
$filesToDelete = [
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
"post-root-package-install": "@tdk:setup",
"post-create-project-cmd": "@tdk:help",
"tdk:setup": [
"Ochorocho\\Tdk\\Scripts\\InitializeScript::cloneRepo",
"Ochorocho\\Tdk\\Scripts\\GitScript::cloneRepository",
"@tdk:set-push-url",
"@tdk:enable-hooks",
"@tdk:ddev-config"
],
"tdk:clear": "Ochorocho\\Tdk\\Scripts\\InitializeScript::removeFilesAndFolders",
"tdk:remove-hooks": "Ochorocho\\Tdk\\Scripts\\InitializeScript::removeHooks",
"tdk:enable-hooks": "Ochorocho\\Tdk\\Scripts\\InitializeScript::enableHooks",
"tdk:set-commit-template": "Ochorocho\\Tdk\\Scripts\\InitializeScript::setCommitTemplate",
"tdk:set-push-url": "Ochorocho\\Tdk\\Scripts\\InitializeScript::setGerritPushUrl",
"tdk:ddev-config": "Ochorocho\\Tdk\\Scripts\\InitializeScript::createDdevConfig",
"tdk:help": "Ochorocho\\Tdk\\Scripts\\InitializeScript::showSummary",
"tdk:set-commit-template": "Ochorocho\\Tdk\\Scripts\\GitScript::setCommitTemplate",
"tdk:set-push-url": "Ochorocho\\Tdk\\Scripts\\GitScript::setGerritPushUrl",
"typo3": "./vendor/bin/typo3 --"
},
"repositories": {
Expand Down