123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?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', 'ccc9a0ea6fefa8df558f4994e8c8ada2efa97f12');
- //define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
- try {
- $client = new Gogs\API\Client(API_URL, API_TOKEN);
- $users = $client->users()->search(array("name" => "bje007"));
- $me = $client->user()->load();
- var_dump($me, $users);
-
- #try {
- # // Create new repo under authorized user
- # $repo = $me->repos()->new(
- # /*name*/ "gogs-php-api-client-test",
- # /*desc*/ "Repository created from test file.",
- # /*private*/ false,
- # /*auto init*/ true,
- # /*git ignore*/ "Vim",
- # /*license*/ "MIT License"
- # /* default read me */
- # );
-
- # echo "New repo '" . $repo->rfull_name . "' created!\n";
- #} catch(\Lib\HTTPUnexpectedResponse $e) {
- # // Repo exists, get it!
- # $repo = $me->repo("gogs-php-api-client-test");
- # // Delete it (it will now be created on reload!)
- # $repo->delete();
- # echo "Repo '" . $repo->rfull_name . "' deleted\n";
- #}
- //$orgs = $me->organizations();
- // Requires ADMIN rights to the authenticated user
- #try {
- // Create new user "tester2"
- # $user = $client->users()->new("tester2", "git@git.giaever.org");
- # echo "New user '" . $user->uusername . "' created!\n";
- // And a new repository under this user
- # $repo = $user->repos()->new(
- # /*name*/ "gogs-php-api-client-auth-test",
- # /*desc*/ "Repository created from test file.",
- # /*private*/ false,
- # /*auto init*/ true,
- # /*git ignore*/ "Vim",
- # /*license*/ "MIT License"
- # /* default read me */
- # );
-
- # echo "New repo '" . $repo->rfull_name . "' created\n";
- # $org = $user->organizations()->new(
- # /*username*/ "tester-org",
- # /*full name*/ "Tester's organization",
- # /*desc*/ "Just a test organization",
- # /*website*/ "https://git.giaever.org/",
- # /*location*/ "Norway"
- # );
- #}catch (\Lib\NotAuthorizedException $e) {
- # echo "User (me) '" . $me->uusername . "' not authorized for this action: " . $e->getMessage();
- #} catch (\Lib\HTTPUnexpectedResponse $e) {
-
- // Most likely user exist; then delete it
- # $user = $client->users()->get("tester2");
- // Delete it's repositories
- # foreach ($user->repos()->load()->all() as $repo)
- # $repo->delete();
- # foreach ($user->organizations()->load()->all() as $org)
- # $org->delete();
- # $user->delete();
- # echo "User '" . $user->uusername . "' deleted!\n";
- #}
- var_dump($me->organizations()->load()->all()["FlyViking"]->repos()->create(
- "test-repo-for-org",
- "this is desc."
- ));
- } catch (ApiException\NotAuthorizedException $e) {
- die("NOT AUTH: " . $e->getMessage());
- } catch (ApiException\HTTPUnexpectedResponse $e) {
- die($e);
- } catch (Exception $e) {
- die($e);
- }
- ?>
|