Ejemplo n.º 1
0
 public function testStatus()
 {
     $commit = new Commit(new Project('Twig'), '7d78d5f7a8c039059046d6c5e1d7f66765bd91c7');
     $this->assertEquals('building', $commit->getStatusCode());
     $this->assertEquals('building', $commit->getStatus());
     $commit->setStatusCode('failed');
     $this->assertEquals('failed', $commit->getStatusCode());
     $this->assertEquals('failed', $commit->getStatus());
     $commit->setStatusCode('success');
     $this->assertEquals('success', $commit->getStatusCode());
     $this->assertEquals('succeeded', $commit->getStatus());
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 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()));
     }
 }
Ejemplo n.º 4
0
 /**
  * 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
     }
 }
Ejemplo n.º 5
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';
     }
 }
Ejemplo n.º 6
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());
 }