diff --git a/composer.json b/composer.json index 869f39a..1cbbba4 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,11 @@ "phpunit/phpunit": "^8 || ^9 || ^10", "composer/composer": "^1.8 || ^2.0" }, + "scripts": { + "test": "phpunit tests", + "cs-fixer": "php-cs-fixer fix src" + + }, "replace": { "elendev/nexus-composer-push": "*" }, diff --git a/src/PushCommand.php b/src/PushCommand.php index bbf76b3..0c973a0 100644 --- a/src/PushCommand.php +++ b/src/PushCommand.php @@ -139,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->getIO() ->write( - 'Execute the push for the URL ' . $provider->getUrl() . '...', + 'Pushing archive to URL: ' . $provider->getUrl() . '...', true ); diff --git a/src/RepositoryProvider/AbstractProvider.php b/src/RepositoryProvider/AbstractProvider.php index 8392a09..6159a65 100644 --- a/src/RepositoryProvider/AbstractProvider.php +++ b/src/RepositoryProvider/AbstractProvider.php @@ -25,11 +25,19 @@ abstract class AbstractProvider */ private $io; + /** + * @var \Symfony\Component\Console\Helper\ProgressBar|null + */ + private $progress = null; + public function __construct(Configuration $configuration, IOInterface $io, Client $client = null) { $this->configuration = $configuration; $this->io = $io; $this->client = $client; + if (method_exists($io, 'getProgressBar')) { + $this->progress = $io->getProgressBar(); + } } /** @@ -228,4 +236,48 @@ protected function getClient() } return $this->client; } + + /** + * Return the Progress Callback for Guzzle + * + * @return callback + */ + protected function getProgressCallback() + { + if ($this->progress === null) { + return function ( + $downloadTotal, + $downloadedBytes, + $uploadTotal, + $uploadedBytes + ) { + //Do nothing + }; + } + return function ( + $downloadTotal, + $downloadedBytes, + $uploadTotal, + $uploadedBytes + ) { + if ($uploadTotal === 0) { + return; + } + if ($uploadedBytes === 0) { + $this->progress->start(100); + return; + } + + if ($uploadedBytes === $uploadTotal) { + if ($this->progress->getProgress() != 100) { + $this->progress->setProgress(100); + $this->progress->finish(); + $this->getIO()->write(''); + } + return; + } + + $this->progress->setProgress(($uploadedBytes / $uploadTotal) * 100); + }; + } } diff --git a/src/RepositoryProvider/ArtifactoryProvider.php b/src/RepositoryProvider/ArtifactoryProvider.php index 364d3cb..e0dd973 100644 --- a/src/RepositoryProvider/ArtifactoryProvider.php +++ b/src/RepositoryProvider/ArtifactoryProvider.php @@ -39,6 +39,7 @@ protected function apiCall($file, $options) { $options['debug'] = $this->getIO()->isVeryVerbose(); $options['body'] = fopen($file, 'r'); + $options['progress'] = $this->getProgressCallback(); $url = $this->getUrl() . '.' . pathinfo($file, PATHINFO_EXTENSION) . '?properties=composer.version=' . $this->getConfiguration()->getVersion(); $this->getClient()->request('PUT', $url, $options); } diff --git a/src/RepositoryProvider/NexusProvider.php b/src/RepositoryProvider/NexusProvider.php index d4932f2..6392992 100644 --- a/src/RepositoryProvider/NexusProvider.php +++ b/src/RepositoryProvider/NexusProvider.php @@ -66,6 +66,8 @@ protected function apiCall($file, $options) $options['body'] = fopen($file, 'r'); } + $options['progress'] = $this->getProgressCallback(); + $this->getClient()->request('PUT', $url, $options); } }