123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- /*
- * TODO:
- *
- * Rewrite this. Shouldnt be a test file, like its now.
- *
- * */
- require "./src/gpac.php";
- use Gogs\Lib\Curl\Exception as ApiException;
- define('API_URL', 'https://git.giaever.org/api/v1');
- //define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
- define('API_TOKEN', 'e14b9eff0749b6f0c4cadf4bb72b83d44578ae28');
- $client = new Gogs\API\Client(API_URL, API_TOKEN);
- try {
- $me = $client->user()->load();
- $tester = "tester";
- if (API_TOKEN == "142efbfd6fbdf147f03d289f8b22a438eaa1b5d1")
- $tester = "joachimmg";
- $repos = $me->repos()->load();
- $me->orgs()->load();
- /*
- $repo = $repos->get("gogs-php-api-client");
- var_dump($repo->branches()->load());
- */
- echo "\nNormal repo\n";
- foreach($repos->all() as $key => $repo)
- echo sprintf("* %s: %s\n", $key, $repo->name);
- echo "\nSorted created\n";
- foreach($repos->sort_by(Gogs\API\Request\Repos::SORT_CREATED)->all() as $key => $repo)
- echo sprintf("* %s: %s - %s\n", $repo->created_at, $key, $repo->name);
- echo "\nSorted created, then reversed\n";
- foreach($repos->sort_by(Gogs\API\Request\Repos::SORT_CREATED, true)->all() as $key => $repo)
- echo sprintf("* %s: %s - %s\n", $repo->created_at, $key, $repo->name);
- echo "\nSorted Normal, offset 1, limit 10\n";
- foreach($repos->offset(1)->limit(10)->all() as $key => $repo)
- echo sprintf("* %s: %s\n", $key, $repo->name);
- echo "\nNormal repo\n";
- foreach($repos->all() as $key => $repo)
- echo sprintf("* %s: %s\n", $key, $repo->name);
- echo "\nSearch for in loaded data for 'dns', limit 10\n";
- foreach($repos->search(array("name" => "dns", "limit" => 3))->all() as $key => $repo)
- echo sprintf("* %s: %s\n", $key, $repo->name);
- echo "\nSearch for in new data for 'dns', limit 10\n";
- foreach($me->repos()->search(array("name" => "dns", "limit" => 3))->all() as $key => $repo)
- echo sprintf("* %s: %s\n", $key, $repo->name);
- echo "\nUsers->search name 't', offset 1:\n";
- foreach($client->users()->search(array("name" => "to"))->offset(1)->all() as $key => $user)
- echo sprintf("* %s: %s\n", $key, $user->full_name);
- $user = $client->users()->get($tester);
- echo "\nUser '" . $user->username . "' public repos\n";
- foreach($user->repos()->load()->all() as $key => $repo)
- echo sprintf("* %s: %s\n", $key, $repo->name);
- echo "\nUser '" . $me->username . "' public repos \n";
- foreach($client->users()->get($me->username)->repos()->load()->all() as $key => $repo)
- echo sprintf("* %s: %s\n", $key, $repo->name);
- echo "\nUsers '" . $me->username . "' organizations\n";
- foreach($me->organizations()->load()->all() as $key => $org)
- echo sprintf("* %s: %s\n", $key, $org->full_name);
- echo "\nUser '" . $user->username . "' public organizations\n";
- foreach($user->organizations()->load()->all() as $key => $org) {
- echo sprintf("* %s: %s\n* Repositories:\n", $key, $org->full_name);
-
- foreach($org->repos()->load()->all() as $key => $repo)
- echo sprintf("#### %s: %s\n", $key, $repo->name);
- }
- echo "Create data under specified user";
- $repo = $repos->create(
- "test-gogs-api-repo-" . $repos->load()->len(),
- "This is test repo #" . $repos->load()->len() . " created with Gogs PHP API Client",
- false,
- true
- );
- echo "Created repo " . $repo->name . "\n";
- echo "\nLooking up repos of test-test-test-#\n";
- foreach($repos->search(array("name" => "test-gogs-api-repo-"))->sort_by()->all() as $key => $repo)
- echo sprintf("Deleting: '%s' %s\n", $repo->name, $repo->delete() ? "true" : "false");
- $orgs = $me->orgs()->load();
- /*
- try {
- echo "\nCreate organization\n";
- $org = $orgs->create(
- "test-" . $me->username . "-organization",
- $me->full_name . " Testing Organization"
- );
- echo "Organization '" . $org->username . "' created!";
- } catch (ApiException\NotAuthorizedException $e) {
- throw new ApiException\NotAuthorizedException("Creating organization", $e->getCode(), $e);
- } catch (ApiException\HTTPUnexpectedResponse $e) {
- echo $e->getResponse();
- }
- */
- echo "\nLooking up organizations of test-" . $me->username . "\n";
- foreach($orgs->search(array("name" => "test-" . $me->username))->all() as $key => $org)
- echo sprintf("* '%s': %s\n", $key, $org->username);
- $users = $client->users()->search(array("name" => "test-user"));
- $users->create(
- "test-user-" . $users->len(),
- "mytestuser" . $users->len() . "@gogitservice.joke"
- );
- foreach ($users->all() as $key => $user)
- echo sprintf("%s: delete %s\n", $key, $user->delete() ? "true" : "false");
- echo "\n\n\nLOG:\n" . join("\n", $client->get_log());
- } catch (ApiException\NotAuthorizedException $e) {
- echo "\n\n\nLOG:\n" . join("\n", $client->get_log());
- die("NOT AUTH: " . $e->getMessage() . "\nResponse: " . $e->getResponse() . "\n" . <<<EOF
- POSSIBLY WHAT YOU WANTED, CAUSE IT SEEMS LIKE YOUR
- AUTHORIZED USER IS TRYIGN TO PROCESS PARTS OF THE
- INDEX THAT ITS NOT AUTHORIZED TO DO, SUCH AS
- * Creating organizations
- * Creating users
- * More? Sure!
- EOF
- );
- } catch (ApiException\HTTPUnexpectedResponse $e) {
- echo "\n\n\nLOG:\n" . join("\n", $client->get_log());
- die($e);
- } catch (Exception $e) {
- die($e);
- }
- ?>
|