/** * Send a message to the configured slack channel * @param $message * @return null */ protected function send($message) { $chan = is_null($this->channel) ? $this->config['slack']['channel'] : '#' . $this->channel; $settings = ['username' => $this->config['slack']['username'], 'channel' => $chan]; $client = new Maknz\Slack\Client($this->config['slack']['endpoint'], $settings); $client->send($message); }
/** * Check if slack is enabled, if so send the snapshot to the relevant * channel. * * @param EventInterface $event * @throws EndPointNotSetException */ public function handle(EventInterface $event) { if ($this->config['slack']['enabled']) { if (empty($this->config['slack']['endpoint'])) { throw new EndPointNotSetException("You must set the endpoint for your slack channel."); } $client = new Client($this->config['slack']['endpoint'], $this->config['slack']['settings']); $client->send($this->getMessage($event->getSnapshot())); } }
/** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * * @param \Exception $e * @return void */ public function report(Exception $e) { if (true === env('SLACK_NOTIFY') && $e) { $settings = ['username' => env('SLACK_USERNAME'), 'channel' => env('SLACK_CHANNEL'), 'link_names' => true]; $client = new Client(env('SLACK_WEBHOOKS'), $settings); $msgArr = ['From' => env('APP_ENV'), 'url' => Request::url(), 'Type' => get_class($e), 'ip' => Request::ip(), 'Username' => urlencode(Auth::check() ? Auth::user()->username : '******'), 'Message' => $e->getMessage(), 'File' => $e->getFile(), 'Line' => $e->getLine()]; $client->send(urldecode(json_encode($msgArr, JSON_PRETTY_PRINT))); } return parent::report($e); }
/** * Send the message * * @param $message */ protected function send($message) { $this->client->send($message); $this->client = null; }
public function doRun(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $archive = null; $fatalError = []; $errorJS = 0; $errorPHP = 0; $warningPHP = 0; $output->writeln('<fg=white;options=bold;bg=red>Code Quality Tool Note</fg=white;options=bold;bg=red>'); $output->writeln('<info>Fetching files</info>'); $files = $this->extractCommitedFiles(); $output->writeln('<info>Running PHPLint</info>'); $phpLint = $this->phpLint($files); if ($phpLint !== true) { $this->output->writeln(sprintf('<error>%s</error>', $phpLint['line'])); $this->output->writeln(sprintf('<error>%s</error>', $phpLint['error'])); $fatalError[] = $phpLint['error']; $errorPHP += count($phpLint['error']); } if (!isset($this->config->run->phpcsfix) || $this->config->run->phpcsfix == 'true') { $output->writeln('<info>Checking code style</info>'); $codeStyle = $this->codeStyle($files); if ($codeStyle !== true) { $this->output->writeln(sprintf('<error>%s</error>', $codeStyle)); } } $output->writeln('<info>Checking code style with PHPCS</info>'); $codeStylePsr = $this->codeStylePsr($files); if ($codeStylePsr !== true) { $this->output->writeln(sprintf('<error>%s</error>', $codeStylePsr)); $pos = strpos($codeStylePsr, 'FOUND'); $rest = substr($codeStylePsr, $pos, 100); $explode = explode(' ', $rest); $errorPHP += $explode[1]; $warningPHP += $explode[4]; } $output->writeln('<info>Checking code style with PHPCS JS</info>'); $codeStyleJS = $this->codeStyleJS($files); if ($codeStyleJS !== true) { $this->output->writeln(sprintf('<error>%s</error>', $codeStyleJS)); $pos = strpos($codeStyleJS, 'FOUND'); $rest = substr($codeStyleJS, $pos, 30); $explode = explode(' ', $rest); $errorJS = $explode[1]; } $output->writeln('<info>Checking code mess with PHPMD</info>'); $phpmd = $this->phPmd($files); if ($phpmd !== true) { $this->output->writeln(sprintf('<error>%s</error>', $phpmd['file'])); $this->output->writeln(sprintf('<error>%s</error>', $phpmd['errorOutput'])); $this->output->writeln(sprintf('<error>%s</error>', $phpmd['error'])); //count line erros $explode = array_filter(explode("\n", $phpmd['error'])); $warningPHP += count($explode); } if (!isset($this->config->run->phpunit) || $this->config->run->phpunit == 'true') { $output->writeln('<info>Running unit tests</info>'); if (!$this->unitTests()) { throw new \Exception('Fix the f*****g unit tests!'); } } $author = null; exec('git config --get user.name', $author); $message = 'Rating *A*. Good work!'; if ($errorPHP >= 1 || $errorJS >= 1 || $warningPHP >= 1) { $message = 'Rating *B*. warnings (`' . $warningPHP . '` in PHP) errors (`' . $errorJS . '` in JS, `' . $errorPHP . '` in PHP)'; } if (count($fatalError) >= 1) { $message = 'Rating *C*. warnings (`' . $warningPHP . '` in PHP) errors (`' . $errorJS . '` in JS, `' . $errorPHP . '` in PHP)'; } if (preg_match("/(\\*B\\*)|(\\*C\\*)/", $message)) { $output->write('<question>There were some errors in the test, do you still want to commit? (Y/n)</question>: '); do { set_time_limit(0); @ob_end_flush(); ob_implicit_flush(true); $cmdline = new Prompt(); $return = strtoupper($cmdline->get()); if ($return !== 'N' || $return !== 'Y') { $output->write('<bg=red>Invalid response! Y for yes, N for no</>: '); } if ($return === 'N') { throw new \Exception("\n###### Commit Aborted! #######\n"); } } while ($return !== 'Y'); } $msgOut = str_replace('`', '', str_replace('*', '', $message)); $output->writeln('<info>Commit ' . $author[0] . ':' . $msgOut . '</info>'); if (isset($this->config->run->slack) && $this->config->run->slack == 'true' && isset($this->config->slackConfig)) { $settings = ['username' => strval($this->config->slackConfig->username), 'channel' => strval($this->config->slackConfig->channel), 'icon' => strval($this->config->slackConfig->icon)]; $client = new Client(strval($this->config->slackConfig->url), $settings); $client->send('Commit *' . $author[0] . '*: ' . $message . ''); } }
/** * @param Release $release * @param string $channel * @param string $title * @param array $message */ protected function sendNotification(Release $release, $channel, $title, array $message) { $message = $this->slack->createMessage()->to($channel)->attach($message + ['fallback' => $title, 'fields' => $this->describeCommitFields($release, $release->commit())]); $this->slack->send($message); }
protected function sendToSlack($message) { $this->client->send($message); }