Esempio n. 1
0
 /**
  * Retrieves the commits since the given revision and populates a set of Commit Models.
  *
  * By default the commit models are not saved unless the $save parameter is set to true.
  *
  * @param mixed $since the revision where to start retrieving objects
  * @param boolean $save
  *
  * @return array of Commit objects
  */
 public function getCommits($since = null, $save = false)
 {
     // first, load the most recent version
     $this->pull();
     // retrieve commits
     if (!is_null($since)) {
         $parameters = array($since . '..');
     } else {
         $parameters = array();
     }
     $cwd = getcwd();
     chdir($this->getLocalRepoPath());
     $content = $this->execute('log', $parameters, array('raw' => ''));
     chdir($cwd);
     $changes = $this->parseGitLogRawOutput($content);
     // generate commit objects with changes
     $commits = array();
     foreach ($changes as $revision => $change) {
         $commit = new Commit();
         $commit->setRevision($revision);
         $commit->setScmId($this->getScm()->getId());
         $commit->setAuthor($change['author']);
         $commit->setTimestamp(date("Y-m-d H:i:s", strtotime($change['timestamp'])));
         $commit->setMessage($change['message']);
         foreach ($change['filechanges'] as $path => $action) {
             $change = new FileChange();
             $change->setCommit($commit);
             $change->setFilePath($path);
             switch ($action) {
                 case 'A':
                     $change->setFileChangeTypeId(1);
                     break;
                 case 'M':
                     $change->setFileChangeTypeId(2);
                     break;
                 case 'D':
                     $change->setFileChangeTypeId(3);
                     break;
                 default:
                     $change->setFileChangeTypeId(4);
                     break;
             }
             $commit->getFileChange()->add($change);
         }
         if ($save) {
             $commit->save();
         }
         echo '.';
         $commits[] = $commit;
     }
     return $commits;
 }
Esempio n. 2
0
 public function testJsonSerialize()
 {
     $commit = new Commit();
     $commit->setMessage('Message');
     $this->assertInternalType('array', $commit->jsonSerialize());
 }
Esempio n. 3
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;
 }