From f38fedc99427791071a06f4dc331599e01638944 Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Thu, 9 Jun 2022 16:52:27 +0000 Subject: [PATCH 1/8] Add Progress Bar to upload output --- .../ArtifactoryProvider.php | 32 +++++++++++++++++++ src/RepositoryProvider/NexusProvider.php | 31 ++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/RepositoryProvider/ArtifactoryProvider.php b/src/RepositoryProvider/ArtifactoryProvider.php index 364d3cb..faa3f0c 100644 --- a/src/RepositoryProvider/ArtifactoryProvider.php +++ b/src/RepositoryProvider/ArtifactoryProvider.php @@ -39,6 +39,38 @@ protected function apiCall($file, $options) { $options['debug'] = $this->getIO()->isVeryVerbose(); $options['body'] = fopen($file, 'r'); + + $io = $this->getIO(); + + if(method_exists($io, 'getProgressBar')) { + /** @var \Symfony\Component\Console\Helper\ProgressBar */ + $progress = $io->getProgressBar(); + $options['progress'] = function ( + $downloadTotal, + $downloadedBytes, + $uploadTotal, + $uploadedBytes, + ) use ($progress) { + if ($uploadTotal === 0) { + return; + } + if ($uploadedBytes === 0) { + $progress->start(100); + return; + } + + if ($uploadedBytes === $uploadTotal) { + if ($progress->getProgress() != 100) { + $progress->finish(); + $this->getIO()->write(''); + } + return; + } + + $progress->setProgress(($uploadedBytes / $uploadTotal) * 100); + }; + } + $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..85db64e 100644 --- a/src/RepositoryProvider/NexusProvider.php +++ b/src/RepositoryProvider/NexusProvider.php @@ -66,6 +66,37 @@ protected function apiCall($file, $options) $options['body'] = fopen($file, 'r'); } + $io = $this->getIO(); + + if(method_exists($io, 'getProgressBar')) { + /** @var \Symfony\Component\Console\Helper\ProgressBar */ + $progress = $io->getProgressBar(); + $options['progress'] = function ( + $downloadTotal, + $downloadedBytes, + $uploadTotal, + $uploadedBytes, + ) use ($progress) { + if ($uploadTotal === 0) { + return; + } + if ($uploadedBytes === 0) { + $progress->start(100); + return; + } + + if ($uploadedBytes === $uploadTotal) { + if ($progress->getProgress() != 100) { + $progress->finish(); + $this->getIO()->write(''); + } + return; + } + + $progress->setProgress(($uploadedBytes / $uploadTotal) * 100); + }; + } + $this->getClient()->request('PUT', $url, $options); } } From 5e0f112685f79df779f475ababe661e402e71ead Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Thu, 9 Jun 2022 16:56:39 +0000 Subject: [PATCH 2/8] fix pre php 8.0 --- src/RepositoryProvider/ArtifactoryProvider.php | 2 +- src/RepositoryProvider/NexusProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RepositoryProvider/ArtifactoryProvider.php b/src/RepositoryProvider/ArtifactoryProvider.php index faa3f0c..bbb72bf 100644 --- a/src/RepositoryProvider/ArtifactoryProvider.php +++ b/src/RepositoryProvider/ArtifactoryProvider.php @@ -49,7 +49,7 @@ protected function apiCall($file, $options) $downloadTotal, $downloadedBytes, $uploadTotal, - $uploadedBytes, + $uploadedBytes ) use ($progress) { if ($uploadTotal === 0) { return; diff --git a/src/RepositoryProvider/NexusProvider.php b/src/RepositoryProvider/NexusProvider.php index 85db64e..63ea418 100644 --- a/src/RepositoryProvider/NexusProvider.php +++ b/src/RepositoryProvider/NexusProvider.php @@ -75,7 +75,7 @@ protected function apiCall($file, $options) $downloadTotal, $downloadedBytes, $uploadTotal, - $uploadedBytes, + $uploadedBytes ) use ($progress) { if ($uploadTotal === 0) { return; From 9428afbb22b5487b4fa0b6c8c347037e9bd57099 Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Thu, 9 Jun 2022 16:58:08 +0000 Subject: [PATCH 3/8] cs fixer --- src/RepositoryProvider/ArtifactoryProvider.php | 2 +- src/RepositoryProvider/NexusProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RepositoryProvider/ArtifactoryProvider.php b/src/RepositoryProvider/ArtifactoryProvider.php index bbb72bf..7c52271 100644 --- a/src/RepositoryProvider/ArtifactoryProvider.php +++ b/src/RepositoryProvider/ArtifactoryProvider.php @@ -42,7 +42,7 @@ protected function apiCall($file, $options) $io = $this->getIO(); - if(method_exists($io, 'getProgressBar')) { + if (method_exists($io, 'getProgressBar')) { /** @var \Symfony\Component\Console\Helper\ProgressBar */ $progress = $io->getProgressBar(); $options['progress'] = function ( diff --git a/src/RepositoryProvider/NexusProvider.php b/src/RepositoryProvider/NexusProvider.php index 63ea418..3e0d648 100644 --- a/src/RepositoryProvider/NexusProvider.php +++ b/src/RepositoryProvider/NexusProvider.php @@ -68,7 +68,7 @@ protected function apiCall($file, $options) $io = $this->getIO(); - if(method_exists($io, 'getProgressBar')) { + if (method_exists($io, 'getProgressBar')) { /** @var \Symfony\Component\Console\Helper\ProgressBar */ $progress = $io->getProgressBar(); $options['progress'] = function ( From 348e88f349cd7075223d02dd65be7a18e7fa4a5f Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Thu, 9 Jun 2022 16:59:17 +0000 Subject: [PATCH 4/8] add commands to scripts --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) 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": "*" }, From 90d706e31779a3a662d40414e7d4c8dc0ca33eb7 Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Fri, 24 Jun 2022 18:02:53 +0000 Subject: [PATCH 5/8] put functionality inside of AbstractProvider --- src/RepositoryProvider/AbstractProvider.php | 52 +++++++++++++++++++ .../ArtifactoryProvider.php | 33 +----------- src/RepositoryProvider/NexusProvider.php | 31 +---------- 3 files changed, 54 insertions(+), 62 deletions(-) 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 7c52271..ac155a4 100644 --- a/src/RepositoryProvider/ArtifactoryProvider.php +++ b/src/RepositoryProvider/ArtifactoryProvider.php @@ -39,38 +39,7 @@ protected function apiCall($file, $options) { $options['debug'] = $this->getIO()->isVeryVerbose(); $options['body'] = fopen($file, 'r'); - - $io = $this->getIO(); - - if (method_exists($io, 'getProgressBar')) { - /** @var \Symfony\Component\Console\Helper\ProgressBar */ - $progress = $io->getProgressBar(); - $options['progress'] = function ( - $downloadTotal, - $downloadedBytes, - $uploadTotal, - $uploadedBytes - ) use ($progress) { - if ($uploadTotal === 0) { - return; - } - if ($uploadedBytes === 0) { - $progress->start(100); - return; - } - - if ($uploadedBytes === $uploadTotal) { - if ($progress->getProgress() != 100) { - $progress->finish(); - $this->getIO()->write(''); - } - return; - } - - $progress->setProgress(($uploadedBytes / $uploadTotal) * 100); - }; - } - + $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 3e0d648..28c2986 100644 --- a/src/RepositoryProvider/NexusProvider.php +++ b/src/RepositoryProvider/NexusProvider.php @@ -66,36 +66,7 @@ protected function apiCall($file, $options) $options['body'] = fopen($file, 'r'); } - $io = $this->getIO(); - - if (method_exists($io, 'getProgressBar')) { - /** @var \Symfony\Component\Console\Helper\ProgressBar */ - $progress = $io->getProgressBar(); - $options['progress'] = function ( - $downloadTotal, - $downloadedBytes, - $uploadTotal, - $uploadedBytes - ) use ($progress) { - if ($uploadTotal === 0) { - return; - } - if ($uploadedBytes === 0) { - $progress->start(100); - return; - } - - if ($uploadedBytes === $uploadTotal) { - if ($progress->getProgress() != 100) { - $progress->finish(); - $this->getIO()->write(''); - } - return; - } - - $progress->setProgress(($uploadedBytes / $uploadTotal) * 100); - }; - } + $options['progress'] =$this->getProgressCallback(); $this->getClient()->request('PUT', $url, $options); } From 57964b770cae5e373f05cba7f759e29cb5b91d9e Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Fri, 24 Jun 2022 18:03:20 +0000 Subject: [PATCH 6/8] fix spacing --- src/RepositoryProvider/ArtifactoryProvider.php | 2 +- src/RepositoryProvider/NexusProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RepositoryProvider/ArtifactoryProvider.php b/src/RepositoryProvider/ArtifactoryProvider.php index ac155a4..e0dd973 100644 --- a/src/RepositoryProvider/ArtifactoryProvider.php +++ b/src/RepositoryProvider/ArtifactoryProvider.php @@ -39,7 +39,7 @@ protected function apiCall($file, $options) { $options['debug'] = $this->getIO()->isVeryVerbose(); $options['body'] = fopen($file, 'r'); - $options['progress'] =$this->getProgressCallback(); + $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 28c2986..6392992 100644 --- a/src/RepositoryProvider/NexusProvider.php +++ b/src/RepositoryProvider/NexusProvider.php @@ -66,7 +66,7 @@ protected function apiCall($file, $options) $options['body'] = fopen($file, 'r'); } - $options['progress'] =$this->getProgressCallback(); + $options['progress'] = $this->getProgressCallback(); $this->getClient()->request('PUT', $url, $options); } From 5293305293cb264fa8868c8b6ca7dd52bc304aba Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Fri, 24 Jun 2022 18:05:26 +0000 Subject: [PATCH 7/8] fix wordage of sentance --- src/PushCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PushCommand.php b/src/PushCommand.php index bbf76b3..934a1b6 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 server: ' . $provider->getUrl() . '...', true ); From 206b18d08ce8f817953fcb0847012b590ad0dc9b Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Fri, 24 Jun 2022 18:06:01 +0000 Subject: [PATCH 8/8] its more of a url in this instance --- src/PushCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PushCommand.php b/src/PushCommand.php index 934a1b6..0c973a0 100644 --- a/src/PushCommand.php +++ b/src/PushCommand.php @@ -139,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->getIO() ->write( - 'Pushing archive to server: ' . $provider->getUrl() . '...', + 'Pushing archive to URL: ' . $provider->getUrl() . '...', true );