/** * Determines if a build needs to be notify * based on his status and his predecessor's one * * @param Commit $commit The commit to analyse * @return Boolean whether the commit need notification or not */ protected function commitNeedNotification(Commit $commit) { if (!$commit->isSuccessful()) { return true; } //getProject()->getLatestCommit() actually contains the previous build $previousCommit = $commit->getProject()->getLatestCommit(); return !$previousCommit || $previousCommit->getStatusCode() != $commit->getStatusCode(); }
public function notify(Commit $commit) { if (!$this->notifier) { return; } $notification = new Notification(); $notification->setTitle($commit->getProject()->getName()); $notification->setBody($this->format($this->format, $commit)); $this->notifier->send($notification); }
public function notify(Commit $commit) { // first, try with the notify-send program $process = new Process(sprintf('notify-send "%s" "%s"', $commit->getProject()->getName(), $this->format($this->format, $commit))); $process->setTimeout(2); $process->run(); if ($process->getExitCode() <= 0) { return; } // then, try dbus-send? $process = new Process(sprintf('dbus-send --print-reply --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.Notify string:"sismo" int32:0 string:"" string:"%s" string:"%s" array:string:"" dict:string:"" int32:-1', $commit->getProject()->getName(), $this->format($this->format, $commit))); $process->setTimeout(2); $process->run(); if ($process->getExitCode() <= 0) { return; } }
public function notify(Commit $commit) { $slug = $commit->getProject()->getSlug(); $status = 'succeeded' == strtolower($commit->getStatus()) ? 'ok' : 'ko'; $data = unserialize(file_get_contents($this->log)); $data['last_update'] = date('Y-M-j H:i:s'); $data['projects'][$slug][] = $status; // image will only show `max_number_bars` builds per project $data['projects'][$slug] = array_slice($data['projects'][$slug], -$this->get('max_number_bars')); file_put_contents($this->log, serialize($data)); // if the last image was generated less than 15 seconds ago, don't generate // another image. This prevents collisions when building a lot of projects if (null != $this->updatedAt && microtime(true) - $this->updatedAt < 15) { return; } $this->updateBackground($data); }
/** * Notify a project commit * * @param Sismo\Commit $commit The latest project commit * * @return bool TRUE on a succesfull notification, FALSE on failure */ public function notify(Commit $commit) { try { $this->growl->register(); $name = $commit->isSuccessful() ? self::NOTIFY_SUCCESS : self::NOTIFY_FAILURE; $notifications = $this->growl->getApplication()->getGrowlNotifications(); $this->growl->publish($name, $commit->getProject()->getName(), $this->format($this->format, $commit), $notifications[$name]); } catch (\Net_Growl_Exception $e) { return false; } return true; }
public function updateCommit(Commit $commit) { $stmt = $this->db->prepare('UPDATE `commit` SET status = :status, output = :output, build_date = CURRENT_TIMESTAMP WHERE slug = :slug AND sha = :sha'); $stmt->bindValue(':slug', $commit->getProject()->getSlug(), SQLITE3_TEXT); $stmt->bindValue(':sha', $commit->getSha(), SQLITE3_TEXT); $stmt->bindValue(':status', $commit->getStatusCode(), SQLITE3_TEXT); $stmt->bindValue(':output', $commit->getOutput(), SQLITE3_TEXT); if (false === $stmt->execute()) { throw new \RuntimeException(sprintf('Unable to save build "%s@%s".', $commit->getProject()->getName(), $commit->getSha())); } }
public function testProject() { $commit = new Commit($project = new Project('Twig'), '7d78d5f7a8c039059046d6c5e1d7f66765bd91c7'); $this->assertEquals($project, $commit->getProject()); }
/** * Update the commits information. * * The commit is identified by its sha hash. * * @param Commit $commit * * @return StorageInterface $this */ public function updateCommit(Commit $commit) { $stmt = $this->db->prepare('UPDATE `commit` SET status = :status, output = :output, build_date = :current_date WHERE slug = :slug AND sha = :sha'); $stmt->bindValue(':slug', $commit->getProject()->getSlug(), \PDO::PARAM_STR); $stmt->bindValue(':sha', $commit->getSha(), \PDO::PARAM_STR); $stmt->bindValue(':status', $commit->getStatusCode(), \PDO::PARAM_STR); $stmt->bindValue(':output', $commit->getOutput(), \PDO::PARAM_STR); $stmt->bindValue(':current_date', date('Y-m-d H:i:s'), \PDO::PARAM_STR); if (false === $stmt->execute()) { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to save build "%s@%s".', $commit->getProject()->getName(), $commit->getSha())); // @codeCoverageIgnoreEnd } }
public function notify(Commit $commit) { $this->register(); return $this->doNotify($commit->isSuccessful() ? 'Success' : 'Fail', $commit->getProject()->getName(), $this->format($this->format, $commit)); }
protected function getPlaceholders(Commit $commit) { $project = $commit->getProject(); return array('%slug%' => $project->getSlug(), '%name%' => $project->getName(), '%status%' => $commit->getStatus(), '%status_code%' => $commit->getStatusCode(), '%STATUS%' => strtoupper($commit->getStatus()), '%sha%' => $commit->getSha(), '%short_sha%' => $commit->getShortSha(), '%author%' => $commit->getAuthor(), '%message%' => $commit->getMessage(), '%output%' => $commit->getOutput()); }