index.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. * TODO:
  4. *
  5. * Rewrite this. Shouldnt be a test file, like its now.
  6. *
  7. * */
  8. require "./src/gpac.php";
  9. use Gogs\Lib\Curl\Exception as ApiException;
  10. define('API_URL', 'https://git.giaever.org/api/v1');
  11. define('API_TOKEN', 'ccc9a0ea6fefa8df558f4994e8c8ada2efa97f12');
  12. //define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
  13. try {
  14. $client = new Gogs\API\Client(API_URL, API_TOKEN);
  15. $users = $client->users()->search(array("name" => "bje007"));
  16. $me = $client->user()->load();
  17. var_dump($me, $users);
  18. #try {
  19. # // Create new repo under authorized user
  20. # $repo = $me->repos()->new(
  21. # /*name*/ "gogs-php-api-client-test",
  22. # /*desc*/ "Repository created from test file.",
  23. # /*private*/ false,
  24. # /*auto init*/ true,
  25. # /*git ignore*/ "Vim",
  26. # /*license*/ "MIT License"
  27. # /* default read me */
  28. # );
  29. # echo "New repo '" . $repo->rfull_name . "' created!\n";
  30. #} catch(\Lib\HTTPUnexpectedResponse $e) {
  31. # // Repo exists, get it!
  32. # $repo = $me->repo("gogs-php-api-client-test");
  33. # // Delete it (it will now be created on reload!)
  34. # $repo->delete();
  35. # echo "Repo '" . $repo->rfull_name . "' deleted\n";
  36. #}
  37. //$orgs = $me->organizations();
  38. // Requires ADMIN rights to the authenticated user
  39. #try {
  40. // Create new user "tester2"
  41. # $user = $client->users()->new("tester2", "git@git.giaever.org");
  42. # echo "New user '" . $user->uusername . "' created!\n";
  43. // And a new repository under this user
  44. # $repo = $user->repos()->new(
  45. # /*name*/ "gogs-php-api-client-auth-test",
  46. # /*desc*/ "Repository created from test file.",
  47. # /*private*/ false,
  48. # /*auto init*/ true,
  49. # /*git ignore*/ "Vim",
  50. # /*license*/ "MIT License"
  51. # /* default read me */
  52. # );
  53. # echo "New repo '" . $repo->rfull_name . "' created\n";
  54. # $org = $user->organizations()->new(
  55. # /*username*/ "tester-org",
  56. # /*full name*/ "Tester's organization",
  57. # /*desc*/ "Just a test organization",
  58. # /*website*/ "https://git.giaever.org/",
  59. # /*location*/ "Norway"
  60. # );
  61. #}catch (\Lib\NotAuthorizedException $e) {
  62. # echo "User (me) '" . $me->uusername . "' not authorized for this action: " . $e->getMessage();
  63. #} catch (\Lib\HTTPUnexpectedResponse $e) {
  64. // Most likely user exist; then delete it
  65. # $user = $client->users()->get("tester2");
  66. // Delete it's repositories
  67. # foreach ($user->repos()->load()->all() as $repo)
  68. # $repo->delete();
  69. # foreach ($user->organizations()->load()->all() as $org)
  70. # $org->delete();
  71. # $user->delete();
  72. # echo "User '" . $user->uusername . "' deleted!\n";
  73. #}
  74. var_dump($me->organizations()->load()->all()["FlyViking"]->repos()->create(
  75. "test-repo-for-org",
  76. "this is desc."
  77. ));
  78. } catch (ApiException\NotAuthorizedException $e) {
  79. die("NOT AUTH: " . $e->getMessage());
  80. } catch (ApiException\HTTPUnexpectedResponse $e) {
  81. die($e);
  82. } catch (Exception $e) {
  83. die($e);
  84. }
  85. ?>