Esempio n. 1
0
 /**
  * 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();
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 public function testUpdateCommit()
 {
     $project = $this->getProject();
     $storage = $this->getStorage();
     $storage->initCommit($project, '7d78d5', 'fabien', new \DateTime(), 'foo');
     $commit = new Commit($project, '7d78d5');
     $commit->setOutput('foo');
     $commit->setStatusCode('success');
     $storage->updateCommit($commit);
     $this->assertEquals('foo', $commit->getOutput());
     $this->assertEquals('success', $commit->getStatusCode());
     $commit = $storage->getCommit($project, '7d78d5');
     $this->assertNotNull($commit->getBuildDate());
 }
Esempio n. 5
0
 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;
     }
 }
Esempio n. 6
0
 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);
 }
Esempio n. 7
0
 public function testFormat()
 {
     $notifier = $this->getMock('Sismo\\Notifier\\Notifier');
     $r = new \ReflectionObject($notifier);
     $m = $r->getMethod('format');
     $m->setAccessible(true);
     $project = new Project('Twig');
     $commit = new Commit($project, '123456');
     $commit->setAuthor('Fabien');
     $commit->setMessage('Foo');
     $this->assertEquals('twig', $m->invoke($notifier, '%slug%', $commit));
     $this->assertEquals('Twig', $m->invoke($notifier, '%name%', $commit));
     $this->assertEquals('building', $m->invoke($notifier, '%status%', $commit));
     $this->assertEquals('building', $m->invoke($notifier, '%status_code%', $commit));
     $this->assertEquals('123456', $m->invoke($notifier, '%sha%', $commit));
     $this->assertEquals('Fabien', $m->invoke($notifier, '%author%', $commit));
     $this->assertEquals('Foo', $m->invoke($notifier, '%message%', $commit));
 }
 public function testNotify()
 {
     $project = new Project('Twig');
     $failedCommit = new Commit($project, '123456');
     $failedCommit->setAuthor('Fabien');
     $failedCommit->setMessage('Foo');
     $successCommit = new Commit($project, '123455');
     $successCommit->setAuthor('Fabien');
     $successCommit->setMessage('Bar');
     $successCommit->setStatusCode('success');
     $baseNotifier = $this->getMock('Sismo\\Notifier\\Notifier');
     $baseNotifier->expects($this->once())->method('notify')->will($this->returnValue('foo'));
     $notifier = new CrossFingerNotifier(array($baseNotifier));
     //a failed commit should call notify on real notifier
     $this->assertTrue($notifier->notify($failedCommit));
     $project->setCommits(array($successCommit));
     //a success commit should not call notify on real notifier
     $this->assertFalse($notifier->notify($successCommit));
 }
Esempio n. 9
0
 public function testNotify()
 {
     $project = new Project('Twig');
     $successCommit = new Commit($project, '123455');
     $successCommit->setAuthor('Fabien');
     $successCommit->setMessage('Bar');
     $successCommit->setStatusCode('success');
     $failedCommit = new Commit($project, '123456');
     $failedCommit->setAuthor('Fabien');
     $failedCommit->setMessage('Foo');
     $failedCommit->setStatusCode('failed');
     $project->setCommits(array($failedCommit, $successCommit));
     $logger = $this->getMock('Psr\\Log\\NullLogger');
     $logger->expects($this->once())->method('info');
     $logger->expects($this->once())->method('critical');
     $notifier = new LoggerNotifier($logger);
     //notify success commit
     $notifier->notify($successCommit);
     //notify failed commit
     $notifier->notify($failedCommit);
 }
Esempio n. 10
0
 private function createCommit($project, $result)
 {
     $commit = new Commit($project, $result['sha']);
     $commit->setAuthor($result['author']);
     $commit->setMessage($result['message']);
     $commit->setDate(\DateTime::createFromFormat('Y-m-d H:i:s', $result['date']));
     if ($result['build_date']) {
         $commit->setBuildDate(\DateTime::createFromFormat('Y-m-d H:i:s', $result['build_date']));
     }
     $commit->setStatusCode($result['status']);
     $commit->setOutput($result['output']);
     return $commit;
 }
Esempio n. 11
0
 public function testBuildDate()
 {
     $commit = new Commit(new Project('Twig'), '7d78d5f7a8c039059046d6c5e1d7f66765bd91c7');
     $commit->setBuildDate($date = new \DateTime());
     $this->assertEquals($date, $commit->getBuildDate());
 }
Esempio n. 12
0
 public function notify(Commit $commit)
 {
     $this->register();
     return $this->doNotify($commit->isSuccessful() ? 'Success' : 'Fail', $commit->getProject()->getName(), $this->format($this->format, $commit));
 }
Esempio n. 13
0
 /**
  * @param Commit $commit
  *
  * @return string
  */
 protected function getGitHubState(Commit $commit)
 {
     switch ($commit->getStatusCode()) {
         case 'building':
             return 'pending';
         case 'success':
             return 'success';
         case 'failed':
             return 'failure';
         default:
             return 'error';
     }
 }
Esempio n. 14
0
 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());
 }