user()->load(); $user_search = $client->users()->search(array( "name" => "tester2" )); if ($user_search->len() > 0) echo " * Found user(s) " . var_export($user_search, true); else echo " * User 'tester2' not found"; try { echo " * Creating new repo under autorized user: " . $me->username; // Create new repo under authorized user $repo = $me->repos()->create( /*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->full_name . "' created!\n"; } catch(ApiException\HTTPUnexpectedResponse $e) { // Repo exists, get it! $repo = $me->repo("gogs-php-api-client-test"); // Delete it (it will now be created again on reload!) $repo->delete(); echo "Repo '" . $repo->full_name . "' deleted\n"; } // Loop through organizations foreach($me->organizations()->load()->all() as $org) var_dump("ORG", $org->username); echo sprintf( "org->username: %s\norg->org_username: %s\norg->user_username: %s\n", $org->username, $org->org_username, $org->user_username ); // 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); } ?>