From bbfbc93545bff1a116ea4ce85731e11e650f868a Mon Sep 17 00:00:00 2001 From: Mihai Mazuro Date: Tue, 13 Aug 2024 14:41:29 +0300 Subject: [PATCH 1/2] #759 cli notifications email --- README.md | 13 ++++++++++++- src/Commands/DiffCommand.php | 11 ++++++----- src/Commands/ProjectCommand.php | 10 +++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9ea801f..ef45016 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,16 @@ As a result you will get an ID of the screenshot. diffy diff:create PROJECT_ID SCREENSHOT_ID1 SCREENSHOT_ID2 ``` -Also, you can create diff with custom name: +or create diff with custom name: ```shell script diffy diff:create PROJECT_ID SCREENSHOT_ID1 SCREENSHOT_ID2 --name="custom" ``` +or create diff with custom email notification: +```shell script +diffy diff:create PROJECT_ID SCREENSHOT_ID1 SCREENSHOT_ID2 --notifications="test@icloud.com,test@gmail.com" +``` + Compare screenshots with id SCREENSHOT_ID1 and SCREENSHOT_ID2 ```shell script @@ -88,6 +93,12 @@ or with existing screenshots diffy project:compare PROJECT_ID existing existing --screenshot1=100 --screenshot2=101 ``` +or with custom email notification + +```shell script +diffy project:compare PROJECT_ID baseline staging --notifications="test@icloud.com,test@gmail.com" +``` + Allowed environments are: prod, stage, dev, custom (long options: production, staging, development). #### Update project(s) diff --git a/src/Commands/DiffCommand.php b/src/Commands/DiffCommand.php index d812d5b..8aec238 100644 --- a/src/Commands/DiffCommand.php +++ b/src/Commands/DiffCommand.php @@ -26,25 +26,26 @@ class DiffCommand extends Tasks * @option wait Wait for the diff to be completed * @option max-wait Maximum number of seconds to wait for the diff to be completed. * @option name Custom diff name + * @option notifications Send an email notification when the diff is completed * * @usage diff:create 342 1221 1223 * Compare screenshots 1221 and 1223. * @usage diff:create --wait --name="custom name" 342 1221 1223 - * Compare screenshots 1221 and 1223 and wait for the diff to be completed and set the name for the diff "custom name". + * Compare screenshots 1221 and 1223 and wait for the diff to be completed and set the name for the diff "custom name".] + * @usage diff:create 342 1221 1223 --notifications="test@icloud.com,test@gmail.com" + * Compare screenshots 1221 and 1223. When the comparison is completed, send a notification with the comparison to test@icloud.com and test@gmail.com. */ public function createDiff( int $projectId, int $screenshotId1, int $screenshotId2, - array $options = ['wait' => false, 'max-wait' => 1200, 'name' => ''] + array $options = ['wait' => false, 'max-wait' => 1200, 'name' => '', 'notifications' => ''] ) { $apiKey = Config::getConfig()['key']; Diffy::setApiKey($apiKey); - $name = $options['name'] ?? ''; - - $diffId = Diff::create($projectId, $screenshotId1, $screenshotId2, $name); + $diffId = Diff::create($projectId, $screenshotId1, $screenshotId2, $options); if (!empty($options['wait']) && $options['wait'] == true) { $sleep = 10; diff --git a/src/Commands/ProjectCommand.php b/src/Commands/ProjectCommand.php index a487fd0..876e63f 100644 --- a/src/Commands/ProjectCommand.php +++ b/src/Commands/ProjectCommand.php @@ -76,6 +76,7 @@ private function isValidJsonConfig(string $configurationPath): array * @option commit-sha GitHub commit SHA. * @option screenshot1 First existing screenshot * @option screenshot2 Second existing screenshot + * @option notifications Send an email notification when the diff is completed * * @usage project:compare 342 prod stage * Compare production and stage environments. @@ -83,6 +84,8 @@ private function isValidJsonConfig(string $configurationPath): array * Compare production environment with https://custom-environment.example.com and set diff name "custom-environment" * @usage project:compare custom custom --env1Url="http://site.com" --env2Url="http://site2.com" --commit-sha="29b872765b21387b7adfd67fd16b7f11942e1a56" * Compare http://site.com with http://site2.com with github check by commit-sha. + * @usage project:compare 342 prod stage --notifications="test@icloud.com,test@gmail.com" + * Compare production and stage environments. When the comparison is completed, send a notification with the comparison to test@icloud.com and test@gmail.com. */ public function createCompare( int $projectId, @@ -91,7 +94,7 @@ public function createCompare( array $options = [ 'wait' => false, 'max-wait' => 1200, 'commit-sha' => null, 'env1Url' => '', 'env1User' => null, 'env1Pass' => null, 'env2Url' => '', 'env2User' => null, 'env2Pass' => null, 'name' => '', - 'screenshot1' => null, 'screenshot2' => null, + 'screenshot1' => null, 'screenshot2' => null, 'notifications' => '', ] ) { Diffy::setApiKey(Config::getConfig()['key']); @@ -104,7 +107,8 @@ public function createCompare( 'env1Pass' => $options['env1Pass'], 'env2Url' => $options['env2Url'], 'env2User' => $options['env2User'], - 'env2Pass' => $options['env2Pass'] + 'env2Pass' => $options['env2Pass'], + 'notifications' => $options['notifications'], ]; if (!empty($options['commit-sha']) && $options['commit-sha']) { @@ -146,7 +150,7 @@ public function createCompare( $screenshot2 = Screenshot::create($projectId, $env2); } - $diffId = Diff::create($projectId, $screenshot1, $screenshot2, $options['name']); + $diffId = Diff::create($projectId, $screenshot1, $screenshot2, $options['name'], $options['notifications']); } else { $diffId = Project::compare($projectId, $params); } From 6bd4f5b0f5889ee84fad607c10262eae5b89c4ac Mon Sep 17 00:00:00 2001 From: Mihai Mazuro Date: Tue, 13 Aug 2024 14:44:57 +0300 Subject: [PATCH 2/2] #759 use options --- src/Commands/ProjectCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/ProjectCommand.php b/src/Commands/ProjectCommand.php index 876e63f..fcac281 100644 --- a/src/Commands/ProjectCommand.php +++ b/src/Commands/ProjectCommand.php @@ -150,7 +150,7 @@ public function createCompare( $screenshot2 = Screenshot::create($projectId, $env2); } - $diffId = Diff::create($projectId, $screenshot1, $screenshot2, $options['name'], $options['notifications']); + $diffId = Diff::create($projectId, $screenshot1, $screenshot2, $options); } else { $diffId = Project::compare($projectId, $params); }