From 00dcc7e004476d2154952fcc8c3bf85adba2475d Mon Sep 17 00:00:00 2001 From: Netkas Date: Sat, 19 Aug 2023 12:52:39 -0400 Subject: [PATCH] - Removed unused exception `GitCloneException` in `\ncc\Exceptions` in favor of `GitException` - Removed unused exception `GitCheckoutException` in `\ncc\Exceptions` in favor of `GitException` - Removed unused exception `GithubServiceException` in `\ncc\Exceptions` in favor of `GitException` - Updated `\ncc\Classes > GitClient > cloneRepository()` to throw `GitException` instead of `GitCloneException` - Updated `\ncc\Classes > GitClient > checkout()` to throw `GitException` instead of `GitCheckoutException` - Added new exception `GitException` in `\ncc\Exceptions` to replace all git related exceptions --- CHANGELOG.md | 6 ++ scratch/exceptions_plan.txt | 6 +- src/ncc/Classes/GitClient.php | 57 +++++++++--------- .../Classes/GithubExtension/GithubService.php | 60 +++++++++---------- src/ncc/Enums/ExceptionCodes.php | 26 +++----- src/ncc/Exceptions/GitCheckoutException.php | 39 ------------ ...GitCloneException.php => GitException.php} | 12 ++-- 7 files changed, 78 insertions(+), 128 deletions(-) delete mode 100644 src/ncc/Exceptions/GitCheckoutException.php rename src/ncc/Exceptions/{GitCloneException.php => GitException.php} (83%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba82f0e..2b5099c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ features. - Added new exception `PathNotFoundException` and implemented it in replacement for `DirectoryNotFoundException` and `FileNotFoundException` in `\ncc\Exceptions` - Added a new interface class `BytecodeObjectInterface` which will be used to implement object types for compiled assets + - Added new exception `GitException` in `\ncc\Exceptions` to replace all git related exceptions ### Fixed - Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()` @@ -107,6 +108,8 @@ features. - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandle` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandlers` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\Build > BuildConfiguration` + - Updated `\ncc\Classes > GitClient > cloneRepository()` to throw `GitException` instead of `GitCloneException` + - Updated `\ncc\Classes > GitClient > checkout()` to throw `GitException` instead of `GitCheckoutException` ### Removed - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` @@ -114,6 +117,9 @@ features. - Removed references of Win32 from the project as Windows is not going supported - Removed unused exception `FileNotFoundException` in `\ncc\CLI > HelpMenu` - Removed unused class `\ncc\Objects > SymlinkDictionary` + - Removed unused exception `GitCloneException` in `\ncc\Exceptions` in favor of `GitException` + - Removed unused exception `GitCheckoutException` in `\ncc\Exceptions` in favor of `GitException` + - Removed unused exception `GithubServiceException` in `\ncc\Exceptions` in favor of `GitException` diff --git a/scratch/exceptions_plan.txt b/scratch/exceptions_plan.txt index 4b7fbf7..3246b94 100644 --- a/scratch/exceptions_plan.txt +++ b/scratch/exceptions_plan.txt @@ -26,7 +26,6 @@ ResourceNotFoundException PACKAGE_NOT_FOUND VERSION_NOT_FOUND NO_AVAILABLE_UNITS - PATH_NOT_FOUND PackageException UNSUPPORTED_PACKAGE @@ -53,8 +52,9 @@ ComposerException COMPOSER_EXCEPTION GitException - GIT_CLONE_EXCEPTION - GIT_CHECKOUT_EXCEPTION + * GIT_CLONE_EXCEPTION + * GIT_CHECKOUT_EXCEPTION + * GITHUB_SERVICE_EXCEPTION GITLAB_SERVICE_EXCEPTION GIT_TAGS_EXCEPTION diff --git a/src/ncc/Classes/GitClient.php b/src/ncc/Classes/GitClient.php index 9929f7b..2fa57ae 100644 --- a/src/ncc/Classes/GitClient.php +++ b/src/ncc/Classes/GitClient.php @@ -1,31 +1,29 @@ isSuccessful()) { - throw new GitCloneException($process->getErrorOutput()); + throw new GitException(sprintf('Failed to clone repository %s: %s', $url, $process->getErrorOutput())); } Console::outVerbose('Repository cloned to: ' . $path); @@ -72,7 +69,7 @@ namespace ncc\Classes; * * @param string $path * @param string $branch - * @throws GitCheckoutException + * @throws GitException */ public static function checkout(string $path, string $branch): void { @@ -93,7 +90,7 @@ namespace ncc\Classes; if (!$process->isSuccessful()) { - throw new GitCheckoutException($process->getErrorOutput()); + throw new GitException(sprintf('Failed to checkout branch %s in repository %s: %s', $branch, $path, $process->getErrorOutput())); } Console::outVerbose('Checked out branch: ' . $branch); @@ -115,7 +112,7 @@ namespace ncc\Classes; if (!$process->isSuccessful()) { - throw new GitCheckoutException($process->getErrorOutput()); + throw new GitException(sprintf('Failed to update submodules in repository %s: %s', $path, $process->getErrorOutput())); } Console::outVerbose('Submodules updated'); diff --git a/src/ncc/Classes/GithubExtension/GithubService.php b/src/ncc/Classes/GithubExtension/GithubService.php index 6c97eab..746d387 100644 --- a/src/ncc/Classes/GithubExtension/GithubService.php +++ b/src/ncc/Classes/GithubExtension/GithubService.php @@ -1,32 +1,32 @@ StatusCode !== 200) { - throw new GithubServiceException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode)); + throw new GitException(sprintf('Github returned an error (%s): %s', $response->StatusCode, $response->Body)); } return Functions::loadJson($response->Body, Functions::FORCE_ARRAY); @@ -220,7 +220,7 @@ namespace ncc\Classes\GithubExtension; * @param Entry|null $entry * @return mixed * @throws AuthenticationException - * @throws GithubServiceException + * @throws GitException * @throws GitlabServiceException * @throws HttpException * @throws MalformedJsonException diff --git a/src/ncc/Enums/ExceptionCodes.php b/src/ncc/Enums/ExceptionCodes.php index 2f595e7..2d67772 100644 --- a/src/ncc/Enums/ExceptionCodes.php +++ b/src/ncc/Enums/ExceptionCodes.php @@ -22,6 +22,7 @@ namespace ncc\Enums; + use ncc\Exceptions\GitException; use ncc\Exceptions\InvalidDependencyConfiguration; use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\SymlinkException; @@ -283,16 +284,6 @@ namespace ncc\Enums; */ public const UNSUPPORTED_REMOTE_SOURCE_TYPE = -1753; - /** - * @see GitCloneException - */ - public const GIT_CLONE_EXCEPTION = -1754; - - /** - * @see GitCheckoutException - */ - public const GIT_CHECKOUT_EXCEPTION = -1755; - /** * @see GitlabServiceException */ @@ -308,11 +299,6 @@ namespace ncc\Enums; */ public const GIT_TAGS_EXCEPTION = -1758; - /** - * @see GithubServiceException - */ - public const GITHUB_SERVICE_EXCEPTION = -1759; - /** * @see AuthenticationException */ @@ -363,6 +349,11 @@ namespace ncc\Enums; */ public const PATH_NOT_FOUND = -1769; + /** + * @see GitException + */ + public const GIT_EXCEPTION = -1770; + /** * All the exception codes from NCC */ @@ -416,8 +407,6 @@ namespace ncc\Enums; self::MISSING_DEPENDENCY, self::HTTP_EXCEPTION, self::UNSUPPORTED_REMOTE_SOURCE_TYPE, - self::GIT_CLONE_EXCEPTION, - self::GIT_CHECKOUT_EXCEPTION, self::GITLAB_SERVICE_EXCEPTION, self::GIT_TAGS_EXCEPTION, self::AUTHENTICATION_EXCEPTION, @@ -429,6 +418,7 @@ namespace ncc\Enums; self::INVALID_BUILD_CONFIGURATION, self::INVALID_DEPENDENCY_CONFIGURATION, self::SYMLINK_EXCEPTION, - self::PATH_NOT_FOUND + self::PATH_NOT_FOUND, + self::GIT_EXCEPTION ]; } \ No newline at end of file diff --git a/src/ncc/Exceptions/GitCheckoutException.php b/src/ncc/Exceptions/GitCheckoutException.php deleted file mode 100644 index 04aa4f3..0000000 --- a/src/ncc/Exceptions/GitCheckoutException.php +++ /dev/null @@ -1,39 +0,0 @@ -