Browse Source

Added mirror sync

Joachim M. Giæver 6 years ago
parent
commit
dfef42f090
3 changed files with 22 additions and 6 deletions
  1. 11 2
      index.php
  2. 10 4
      src/API/Request/Repo.php
  3. 1 0
      src/Lib/Curl/Client.php

+ 11 - 2
index.php

@@ -134,8 +134,17 @@ try {
 
     echo "\nMigrate repo 'gogs-php-api-client.git'\n";
     $mrepo = $repos->create()->migrate("https://git.giaever.org/joachimmg/gogs-php-api-client.git", "gogs-php-api-client-migrate");
-    echo "Syncing repository '" . $mrepo->full_name . "'\n";
-    $mrepo->sync();
+    echo "Syncing repository '" . $mrepo->full_name . "': " . ($mrepo->sync() ? "true" : "false") . "\n";
+    echo sprintf("Delete migrated repo: %s\n", $mrepo->delete());
+
+    echo "\nMigrate repo (mirror) 'gogs-php-api-client.git'\n";
+    $mrepo = $repos->create()->migrate(
+        "https://git.giaever.org/joachimmg/gogs-php-api-client.git", 
+        "gogs-php-api-client-migrate-mirror",
+        null, null,
+        true
+    );
+    echo "Syncing repository '" . $mrepo->full_name . "': " . ($mrepo->sync() ? "true" : "false") . "\n";
     echo sprintf("Delete migrated repo: %s\n", $mrepo->delete());
 
     // Load all of my organizations.

+ 10 - 4
src/API/Request/Repo.php

@@ -65,7 +65,7 @@ namespace Gogs\API\Request {
         protected function set_scope(string $method) {
             switch ($method) {
             case "create":
-                if (!$this->owner->authenticated() && empty($this->owner->username))
+                if (empty($this->owner) || !$this->owner->authenticated() && empty($this->owner->username))
                     throw new Exception\RequestErrorException("Missing userdata of unauthorized user 'username'");
 
                 if ($this->owner instanceof Org)
@@ -76,14 +76,14 @@ namespace Gogs\API\Request {
                     $this->scope = "/admin/users/" . $this->owner->username . "/repos";
                 break;
             case "delete":
-                if (empty($this->owner->username))
+                if (empty($this->owner) || empty($this->owner->username))
                     throw new Exception\RequestErrorException("Missing userdata 'username'");
 
                 $this->scope = "/repos/" . $this->owner->username . "/" . $this->name;
                 break;
             case "get":
             case "load":
-                if (empty($this->owner->username) && empty($this->full_name))
+                if ((empty($this->owner) || empty($this->owner->username)) && empty($this->full_name))
                     throw new Exception\RequestErrorException("Missing userdata 'username' and/or 'full_name'");
 
                 $this->scope = "/repos/" . ($this->owner ? $this->owner->username . "/" . $this->name : $this->full_name);
@@ -91,6 +91,12 @@ namespace Gogs\API\Request {
             case "migrate":
                 $this->scope = "/repos/migrate";
                 break;
+            case "sync":
+                if (empty($this->owner) || empty($this->owner->username))
+                    throw new Exception\RequestErrorException("Missing userdata 'username'");
+
+                $this->scope = sprintf("/repos/%s/%s/mirror-sync", $this->owner->username, $this->name);
+                break;
             default:
                 return false;
             }
@@ -232,7 +238,7 @@ namespace Gogs\API\Request {
          */
         public function sync() {
             if ($this->mirror) {
-                $this->set_scope("mirror_sync");
+                $this->set_scope("sync");
                 $this->method_post();
                 return true;
             }

+ 1 - 0
src/Lib/Curl/Client.php

@@ -228,6 +228,7 @@ namespace Gogs\Lib\Curl {
             switch ($code) {
             case 200:
             case 201:
+            case 202:
                 return $req;
             case 400:
             case 401: