$deploy_message = $_POST['deploy_message']; // Prepare the slack payload as per: // https://api.slack.com/incoming-webhooks $text = $deploy_message; // Build an array of fields to be rendered with Slack Attachments as a table // attachment-style formatting: // https://api.slack.com/docs/attachments $fields[] = array('title' => 'Deploy Message', 'value' => $text, 'short' => 'false'); break; case 'sync_code': // Get the committer, hash, and message for the most recent commit. $committer = `git log -1 --pretty=%cn`; $email = `git log -1 --pretty=%ce`; $message = `git log -1 --pretty=%B`; $hash = `git log -1 --pretty=%h`; // Prepare the slack payload as per: // https://api.slack.com/incoming-webhooks $text = 'Code sync to the ' . $_ENV['PANTHEON_ENVIRONMENT'] . ' environment of ' . $_ENV['PANTHEON_SITE_NAME'] . ' by ' . $_POST['user_email'] . "!\n"; $text .= 'Most recent commit: ' . rtrim($hash) . ' by ' . rtrim($committer) . ': ' . $message; // Build an array of fields to be rendered with Slack Attachments as a table // attachment-style formatting: // https://api.slack.com/docs/attachments $fields += array(array('title' => 'Commit', 'value' => rtrim($hash), 'short' => 'true'), array('title' => 'Commit Message', 'value' => $message, 'short' => 'false')); break; default: $text = $_POST['qs_description']; break; } $attachment = array('fallback' => $text, 'color' => $pantheon_yellow, 'fields' => $fields); _slack_notification($secrets['slack_url'], $secrets['slack_channel'], $secrets['slack_username'], $text, $secrets['slack_icon'], false, $attachment);
$hash = `git log -1 --pretty=%h`; // Prepare the slack payload as per: // https://api.slack.com/incoming-webhooks $text = 'Code sync to the ' . $_ENV['PANTHEON_ENVIRONMENT'] . ' environment of ' . $_ENV['PANTHEON_SITE_NAME'] . ' by ' . $_POST['user_email'] . "!\n"; $text .= 'Most recent commit: ' . rtrim($hash) . ' by ' . rtrim($committer) . ': ' . $message; // Build an array of fields to be rendered with Slack Attachments as a table // attachment-style formatting: // https://api.slack.com/docs/attachments $fields += array(array('title' => 'Commit', 'value' => rtrim($hash), 'short' => 'true'), array('title' => 'Commit Message', 'value' => $message, 'short' => 'false')); break; default: $text = $_POST['qs_description']; break; } $attachment = array('fallback' => $text, 'pretext' => 'Deploying :rocket:', 'color' => $pantheon_yellow, 'fields' => $fields); _slack_notification($secrets['slack_url'], $secrets['slack_channel'], $secrets['slack_username'], $text, $attachment, $secrets['always_show_text']); /** * Get secrets from secrets file. * * @param array $requiredKeys List of keys in secrets file that must exist. */ function _get_secrets($requiredKeys, $defaults) { $secretsFile = $_SERVER['HOME'] . '/files/private/secrets.json'; if (!file_exists($secretsFile)) { die('No secrets file found. Aborting!'); } $secretsContents = file_get_contents($secretsFile); $secrets = json_decode($secretsContents, 1); if ($secrets == FALSE) { die('Could not parse json in secrets file. Aborting!');
/** * Helper Function to Alert Slack */ function _slack_tell($message, $slack_channel_name, $slack_user_name, $slack_icon_url, $left_color_bar = false, $attachment = false) { $defaults = array(); $secrets = _get_secrets(array('slack_url'), $defaults); _slack_notification($secrets['slack_url'], $slack_channel_name, $slack_user_name, $message, $slack_icon_url, $left_color_bar, $attachment); }