// getUserRepos method
$t->comment('Search repos, specify user');
$repos = $github->getRepoApi()->getUserRepos('ornicar');
$t->ok(count($repos) > 20, 'Found ' . count($repos) . ' repos');
$t->ok(isset($repos[0]['name']), 'First repo name: ' . $repos[0]['name']);
// show method
$t->comment('Getting info on specific repository');
$repo = $github->getRepoApi()->show('ornicar', 'php-github-api');
$t->is($repo['name'], 'php-github-api', 'Found repo: ' . $repo['name']);
// getRepoCollaborators method
$t->comment('Finding the collaborators on a specific repository');
$collaborators = $github->getRepoApi()->getRepoCollaborators('ornicar', 'php-github-api');
$t->ok(count($collaborators) > 0, 'Found ' . count($collaborators) . ' collaborators');
// authenticate before repository management tests
$t->comment('Authentice to be able to test repository management');
$github->authenticate($username, $token, phpGitHubApi::AUTH_HTTP_TOKEN);
// getPushableRepos method
$t->comment('Find the repositories, the authenticated user can push to');
$repos = $github->getRepoApi()->getPushableRepos();
$t->ok(count($repos) > 0, 'Found ' . count($repos) . ' repos');
$t->ok(isset($repos[0]['name']), 'First repo name: ' . $repos[0]['name']);
// create method
$t->comment('Create a new repository');
$info = $github->getRepoApi()->create('NewRepo', 'new repo description', 'http://github.com', true);
$t->is($info['name'], 'NewRepo', 'Repo created with name "NewRepo"');
$t->is($info['description'], 'new repo description', 'Repo created with description "new repo description"');
$t->is($info['homepage'], 'http://github.com', 'Repo created with homepage "http://github.com"');
$t->is($info['private'], false, 'Repo created is public');
// setRepoInfo method
$t->comment('Changes an attribute of a repository');
$info = $github->getRepoApi()->setRepoInfo('ornicartest', 'NewRepo', array('description' => 'changed repo description'));
<?php

require_once dirname(__FILE__) . '/vendor/lime.php';
require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php';
$t = new lime_test(5);
$username = '******';
$token = 'fd8144e29b4a85e9487d1cacbcd4e26c';
$repo = 'php-github-api';
$api = new phpGitHubApi();
$t->comment('Get user with NO authentication');
$user = $api->getUserApi()->show($username);
$t->ok(!isset($user['plan']), 'User plan is not available');
$t->comment('Authenticate ' . $username . ' with default authentication method (should be username and token in URL)');
$api->authenticate($username, $token);
$t->comment('Get user with authentication');
$user = $api->getUserApi()->show($username);
$t->ok(isset($user['plan']), 'User plan is available');
$t->comment('Autentication: ' . $username . ' using HTTP Basic Authentication with token');
$api->authenticate($username, $token, phpGitHubApi::AUTH_HTTP_TOKEN);
$user = $api->getUserApi()->show($username);
$t->ok(isset($user['plan']), 'User plan is available');
$t->comment('Deauthenticate');
$api->deAuthenticate();
$user = $api->getUserApi()->show($username);
$t->ok(!isset($user['plan']), 'User plan is not available');
$t->comment('Authenticate ' . $username . ' with bad token');
$api->authenticate($username, 'bad-token');
$t->comment('Get user with bad authentication');
try {
    $user = $api->getUserApi()->show($username);
    $t->fail('Call with bad authentication throws a phpGitHubApiRequestException');
$issues = $github->getIssueApi()->getList($username, $repo, 'closed');
$t->is($issues[0]['state'], 'closed', 'Found closed issues');
$t->is_deeply($github->listIssues($username, $repo, 'closed'), $issues, 'Both new and BC syntax work');
$t->comment('Search issues');
$issues = $github->getIssueApi()->search($username, $repo, 'closed', 'documentation');
$t->is($issues[0]['state'], 'closed', 'Found closed issues matching "documentation"');
$t->is_deeply($github->searchIssues($username, $repo, 'closed', 'documentation'), $issues, 'Both new and BC syntax work');
$t->comment('Show issue');
$issue = $github->getIssueApi()->show($username, $repo, 1);
$t->is($issue['title'], 'Provide documentation', 'Found issue #1');
$t->is_deeply($github->showIssue($username, $repo, 1), $issue, 'Both new and BC syntax work');
$username = '******';
$token = 'fd8144e29b4a85e9487d1cacbcd4e26c';
$repo = 'php-github-api';
$t->comment('Authenticate ' . $username);
$github->authenticate($username, $token);
$t->comment('Open a new issue');
$issueTitle = 'Test new issue title ' . time();
$issue = $github->getIssueApi()->open($username, $repo, $issueTitle, 'Test new issue body');
$t->is($issue['title'], $issueTitle, 'Got the new issue');
$t->is($issue['state'], 'open', 'The new issue is open');
$issueNumber = $issue['number'];
$t->comment('Close the issue');
$issue = $github->getIssueApi()->close($username, $repo, $issueNumber);
$t->is($issue['state'], 'closed', 'The new issue is closed');
$t->comment('Reopen the issue');
$issue = $github->getIssueApi()->reOpen($username, $repo, $issueNumber);
$t->is($issue['state'], 'open', 'The new issue is open');
$t->comment('Update the issue');
$issue = $github->getIssueApi()->update($username, $repo, $issueNumber, array('body' => 'Test new issue body updated'));
$t->is($issue['body'], 'Test new issue body updated', 'The issue has been updated');
Example #4
0
<?php

if ($slug == "git") {
    Content::$forcedTitle = "Git Update";
    if (count($params) > 0) {
        chdir(HR_ROOT);
        Content::setContent("\n\t\t\t<h1>Updating website from git...</h1>\n\t\t\t<pre>" . `echo Running git reset --hard && git reset --hard 2>&1 && echo Running git pull && git pull` . "</pre><br />\n\t\t\t<h3>Now pulling latest commit information from Github...</h3>\n\t\t");
        inclib('github/lib/phpGitHubApi.php');
        $phpGH = new phpGitHubApi();
        $phpGH->authenticate('lukegb', '3b4e0c11ee0681db035b0e885147e236', phpGitHubAPI::AUTH_HTTP_TOKEN);
        $latestCommits = $phpGH->getCommitApi()->getBranchCommits('robbiet480', 'hRepo', 'master');
        $gitCommit = array('long' => $latestCommits[0]['id'], 'short' => substr($latestCommits[0]['id'], 0, 7), 'userid' => $latestCommits[0]['author']['login'], 'commitdate' => $latestCommits[0]['committed_date']);
        file_put_contents(HR_ROOT . '/gitcommit.txt', serialize($gitCommit));
        Content::append('<p>Last git commit: ' . $gitCommit['long'] . ' by ' . $gitCommit['userid'] . '</p>');
    } else {
        Content::setContent("\n\t\t\t<h1>Authorisation code incorrect or missing</h2>\n\t\t\t<p>Git update did not go through.</p>\n\t\t");
    }
}
Example #5
0
require_once './inc/autoloader.php';
if ($_POST['doCreate']) {
    if (!$_POST['username']) {
        throw new Exception('Forgot username.');
    }
    if (!$_POST['password']) {
        throw new Exception('Forgot password.');
    }
    if (!$_POST['repo']) {
        throw new Exception('Forgot repo.');
    }
    if (!is_array($_POST['hash']) || count($_POST['hash']) <= 0) {
        throw new Exception('No tags selected.');
    }
    $github = new phpGitHubApi();
    $github->authenticate($_POST['username'], $_POST['password'], phpGitHubApi::AUTH_HTTP_PASSWORD);
    $userInfo = $github->getUserApi()->show($_POST['username']);
    $github->deAuthenticate();
    //don't need to be auth'd any longer
    if (!isset($userInfo["private_gist_count"])) {
        throw new Exception('unauthorized');
    } else {
        try {
            $repoInfo = $github->getRepoApi()->show($_POST['username'], $_POST['repo']);
            if ($repoInfo['owner'] != $_POST['username']) {
                throw new Exception('You are not the owner of this repo.');
            }
            if ($repoInfo['fork'] || $repoInfo['parent']) {
                throw new Exception('You cannot add a forked repository.');
            }
            $availableTags = $github->getRepoApi()->getRepoTags($_POST['username'], $_POST['repo']);