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

#759 cli notifications email #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected],[email protected]"
```

Compare screenshots with id SCREENSHOT_ID1 and SCREENSHOT_ID2

```shell script
Expand Down Expand Up @@ -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="[email protected],[email protected]"
```

Allowed environments are: prod, stage, dev, custom (long options: production, staging, development).

#### Update project(s)
Expand Down
11 changes: 6 additions & 5 deletions src/Commands/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected],[email protected]"
* Compare screenshots 1221 and 1223. When the comparison is completed, send a notification with the comparison to [email protected] and [email protected].
*/
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;
Expand Down
10 changes: 7 additions & 3 deletions src/Commands/ProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ 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.
* @usage project:compare --wait 342 prod custom --env2Url="https://custom-environment.example.com" --name="custom-environment"
* 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="[email protected],[email protected]"
* Compare production and stage environments. When the comparison is completed, send a notification with the comparison to [email protected] and [email protected].
*/
public function createCompare(
int $projectId,
Expand All @@ -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']);
Expand All @@ -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']) {
Expand Down Expand Up @@ -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);
} else {
$diffId = Project::compare($projectId, $params);
}
Expand Down