private function readBranchFromRepository($userName, $repository, $branch) { $page = 1; $gotResultsLastTime = false; while ($gotResultsLastTime || $page == 1) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://github.com/api/v2/json/commits/list/" . $userName . "/" . $repository . "/" . $branch . "?page=" . $page); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $data = json_decode($output); $page++; if ($data->commits && count($data->commits) > 0) { $gotResultsLastTime = true; foreach ($data->commits as $idx => $commit) { if (is_null($this->authors) || in_array($commit->author->email, $this->authors)) { $data = new GitCommitAction(); $data->setDateTime(new DateTime($commit->authored_date)); $this->dataManager->addData($data); } } } else { $gotResultsLastTime = false; } } }
public function process() { $commits = array(); ################# Find all commits $out = array(); exec("cd " . $this->directory . "; git branch", $out); foreach ($out as $line) { $line = trim($line); if (substr($line, 0, 1) == '*') { $line = substr($line, 1); } $log = array(); exec("cd " . $this->directory . "; git log " . $line, $log); $lastCommit = $lastEmail = $lastDate = null; foreach ($log as $logLine) { if (substr($logLine, 0, 7) == 'commit ') { if ($lastCommit && $lastDate && $lastEmail) { $commits[$lastCommit] = array('date' => $lastDate, 'email' => $lastEmail); } $lastCommit = trim(substr($logLine, 8)); } else { if (substr($logLine, 0, 7) == 'Author:') { $bits = explode('<', $logLine); $bits = explode('>', $bits[1]); $lastEmail = $bits[0]; } else { if (substr($logLine, 0, 5) == 'Date:') { $lastDate = substr($logLine, 5); } } } } } //var_dump($commits); ######### now push commits to data manager foreach ($commits as $commit) { if (in_array($commit['email'], $this->authors)) { $data = new GitCommitAction(); $data->setDateTime(new DateTime($commit['date'])); $this->dataManager->addData($data); } } }