|
@@ -13,10 +13,10 @@ use Gogs\Lib\Curl\Exception as ApiException;
|
|
|
|
|
|
define('API_URL', 'https://git.giaever.org/api/v1');
|
|
|
define('API_TOKEN', '142efbfd6fbdf147f03d289f8b22a438eaa1b5d1');
|
|
|
-
|
|
|
+
|
|
|
+$client = new Gogs\API\Client(API_URL, API_TOKEN);
|
|
|
|
|
|
try {
|
|
|
- $client = new Gogs\API\Client(API_URL, API_TOKEN);
|
|
|
|
|
|
$me = $client->user()->load();
|
|
|
|
|
@@ -26,7 +26,6 @@ try {
|
|
|
|
|
|
$repos = $me->repos()->load();
|
|
|
|
|
|
-
|
|
|
echo "\nNormal repo\n";
|
|
|
foreach($repos->all() as $key => $repo)
|
|
|
echo sprintf("* %s: %s\n", $key, $repo->name);
|
|
@@ -80,29 +79,66 @@ try {
|
|
|
foreach($org->repos()->load()->all() as $key => $repo)
|
|
|
echo sprintf("#### %s: %s\n", $key, $repo->name);
|
|
|
}
|
|
|
- */
|
|
|
- echo "Create data under specified user";
|
|
|
|
|
|
+ echo "Create data under specified user";
|
|
|
$repo = $repos->create(
|
|
|
- "test-test-test-" . $repos->load()->len(),
|
|
|
- "This is repo #" . $repos->load()->len(),
|
|
|
+ "test-gogs-api-repo-" . $repos->load()->len(),
|
|
|
+ "This is test repo #" . $repos->load()->len() . " created with Gogs PHP API Client",
|
|
|
false,
|
|
|
true
|
|
|
);
|
|
|
|
|
|
- echo sprintf("* Created repo: '%s'", $repo->name);
|
|
|
+ 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 "\nNow having repos\n";
|
|
|
- foreach($repos->load()->sort_by()->all() as $key => $repo)
|
|
|
- $repo->delete();
|
|
|
|
|
|
|
|
|
echo "\n\n\nLOG:\n" . join("\n", $client->get_log());
|
|
|
- die();
|
|
|
|
|
|
} catch (ApiException\NotAuthorizedException $e) {
|
|
|
- die("NOT AUTH: " . $e->getMessage());
|
|
|
+ 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);
|