public function updateCommits(Entity\Repo $repo) { $this->output->write(' commits'); try { $commits = $this->github->getCommitApi()->getBranchCommits($repo->getUsername(), $repo->getName(), 'master'); } catch (\Github_HttpClient_Exception $e) { if (404 == $e->getCode()) { return false; } throw $e; } if (empty($commits)) { return false; } $repo->setLastCommits(array_slice($commits, 0, 30)); return $repo; }
public function testGetCommits() { $username = '******'; $repo = 'php-github-api'; $branch = 'master'; $github = new Github_Client(); $commits = $github->getCommitApi()->getBranchCommits($username, $repo, $branch); $commit = array_pop($commits); $this->assertArrayHasKey('url', $commit); }
/** * Get last commit hash ID of branch * * @param string $project Name of the project in git * @param string $path Path to the project in the repository * @param string $host Type of hosting (Git or Local) * @param string $branch Name of the branch * * @return string $output Last commit hash ID */ function getLastCommitId($project, $path, $host, $branch) { if ($host == 'Github') { // Project hosted on Github $github = new Github_Client(); $commits = $github->getCommitApi()->getBranchCommits(Configure::read('Ballista.githubAccount'), $project, $branch); $output = $commits[0]['id']; } else { // Project hosted on local server if (chdir($path)) { exec('git rev-parse ' . $branch, $commit); } else { $this->cakeError('missingPath'); } $output = $commit[0]; } return $output; }