Created
November 18, 2022 23:41
-
-
Save ygerasimov/17b494dbf1a09376087ce2e3a02d39c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Diffy\Diffy; | |
use Diffy\Screenshot; | |
use Diffy\Diff; | |
// https://pantheon.io/docs/guides/quicksilver/variables | |
$pantheon_environment = $_ENV['environment']; | |
// Not sure how these are build for your site. | |
$pentheon_multidev_env_url = $pantheon_environment . '-some-domain.pantheon.io'; | |
$secrets = $this->get_secrets(['token', 'project_id']); | |
$project_id = $secrets['project_id']; | |
Diffy::setApiKey($secrets['token']); | |
$list = Screenshot::all($project_id); | |
$screenshots = $list['screenshotsForDiff']; | |
$previous_screenshot_found = FALSE; | |
foreach ($screenshots as $screenshot) { | |
if (strpos($screenshot['name'], $pantheon_environment) !== FALSE) { | |
$previous_screenshot_found = TRUE; | |
break; | |
} | |
} | |
$previous_screenshot_id = NULL; | |
if ($previous_screenshot_found) { | |
$previous_screenshot_id = $screenshot['id']; | |
} | |
// Create new screenshot and rename it. | |
$new_screenshot_id = Screenshot::create($project_id, 'custom', ['baseUrl' => $pentheon_multidev_env_url]); | |
$screenshot = new Screenshot($new_screenshot_id); | |
$screenshot->setName($pantheon_environment . ' ' . date('M d')); | |
// Create the diff if found previous screenshot. | |
if ($previous_screenshot_id && $new_screenshot_id) { | |
Diff::create($project_id, $previous_screenshot_id, $new_screenshot_id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment