|
@@ -14,7 +14,7 @@ namespace Gogs\API\Request {
|
|
|
* * DELETE `/repos/username/reponame`
|
|
|
*
|
|
|
* @author Joachim M. Giaever (joachim[]giaever.org)
|
|
|
- * @version 0.1.3
|
|
|
+ * @version 0.1.4
|
|
|
*/
|
|
|
final class Repo extends Base {
|
|
|
|
|
@@ -88,6 +88,9 @@ namespace Gogs\API\Request {
|
|
|
|
|
|
$this->scope = "/repos/" . ($this->owner ? $this->owner->username . "/" . $this->name : $this->full_name);
|
|
|
break;
|
|
|
+ case "migrate":
|
|
|
+ $this->scope = "/repos/migrate";
|
|
|
+ break;
|
|
|
default:
|
|
|
return false;
|
|
|
}
|
|
@@ -135,7 +138,7 @@ namespace Gogs\API\Request {
|
|
|
*
|
|
|
* Valid paramters:
|
|
|
*
|
|
|
- * 1. name
|
|
|
+ * 1. name, required
|
|
|
* 2. description
|
|
|
* 3. private (default: false)
|
|
|
* 4. auto_init (default: false)
|
|
@@ -147,25 +150,77 @@ namespace Gogs\API\Request {
|
|
|
* where the required fields are first.
|
|
|
*
|
|
|
* @param ...$args The parameter values
|
|
|
- * @return bool
|
|
|
+ * @return Repo
|
|
|
*/
|
|
|
public function create(...$args) {
|
|
|
|
|
|
- $params = array(
|
|
|
- "name" => isset($args[0]) && is_string($args[0]) ? $args[0] : null,
|
|
|
- "description" => isset($args[1]) && is_string($args[1]) ? $args[1] : null,
|
|
|
- "private" => isset($args[2]) && is_bool($args[2]) ? $args[2] : false,
|
|
|
- "auto_init" => isset($args[3]) && is_bool($args[3]) ? $args[3] : false,
|
|
|
- "gitignores" => isset($args[4]) && is_string($args[4]) ? $args[4] : null,
|
|
|
- "licence" => isset($args[5]) && is_string($args[5]) ? $args[5] : null,
|
|
|
- "readme" => isset($args[6]) && is_string($args[6]) ? $args[6] : "Default"
|
|
|
- );
|
|
|
-
|
|
|
- $params = array_filter($params, function($val) {
|
|
|
- return $val != null;
|
|
|
+ $params = array();
|
|
|
+
|
|
|
+ $this->set_param($params, "name", $args, 0, "string", null);
|
|
|
+ $this->set_param($params, "description", $args, 1, "string", null);
|
|
|
+ $this->set_param($params, "private", $args, 2, "bool", false);
|
|
|
+ $this->set_param($params, "auto_init", $args, 3, "bool", false);
|
|
|
+ $this->set_param($params, "gitignores", $args, 4, "string", null);
|
|
|
+ $this->set_param($params, "license", $args, 5, "string", null);
|
|
|
+ $this->set_param($params, "readme", $args, 6, "string", "Default");
|
|
|
+
|
|
|
+ $this->filter_params($params);
|
|
|
+
|
|
|
+ return parent::create($params);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Migrate a repository from other Git hosting sources.
|
|
|
+ *
|
|
|
+ * Valid parameters:
|
|
|
+ *
|
|
|
+ * 1. clone_addr, required
|
|
|
+ * 3. repo_name, required
|
|
|
+ * 4. auth_username
|
|
|
+ * 5. auth_password
|
|
|
+ * 6. mirror (default: false)
|
|
|
+ * 7. private (default: false)
|
|
|
+ * 8. description
|
|
|
+ *
|
|
|
+ * **UID** will be set to `owner`. Either a User or an Organization.
|
|
|
+ * **From API doc**: To migrate a repository for a organization,
|
|
|
+ * the authenticated user must be a owner of the specified organization.
|
|
|
+ *
|
|
|
+ * This reflects the API v1 documentation, but is in an order
|
|
|
+ * where the required fields as first.
|
|
|
+ *
|
|
|
+ * @throws Exception\RequestErrorException when owner not set
|
|
|
+ * @param ...$args The parameter values
|
|
|
+ * @return Repo
|
|
|
+ */
|
|
|
+
|
|
|
+ public function migrate(...$args) {
|
|
|
+
|
|
|
+ $params = array();
|
|
|
+
|
|
|
+ if (empty($this->owner))
|
|
|
+ throw new Exception\RequestErrorException("Missing required userdata 'uid' or owner must be set");
|
|
|
+
|
|
|
+ $this->set_param($params, "clone_addr", $args, 0, "string", null, function(string $url) {
|
|
|
+ // @todo: URL/PATH validation here?
|
|
|
});
|
|
|
+ $this->set_param($params, "repo_name", $args, 1, "string", null);
|
|
|
+ $this->set_param($params, "auth_username", $args, 2, "string", null);
|
|
|
+ $this->set_param($params, "auth_password", $args, 3, "string", null);
|
|
|
+ $this->set_param($params, "mirror", $args, 4, "bool", false);
|
|
|
+ $this->set_param($params, "private", $args, 5, "bool", false);
|
|
|
+ $this->set_param($params, "description", $args, 6, "string", null);
|
|
|
+
|
|
|
+ $this->set_param($params, "uid", array(), 0, "int", $this->owner->id);
|
|
|
+
|
|
|
+ $this->filter_params($params);
|
|
|
+
|
|
|
+ $this->set_scope("migrate");
|
|
|
+ $resp = parent::method_post($params);
|
|
|
+
|
|
|
+ $this->json_set_property($this->json_decode($resp));
|
|
|
|
|
|
- parent::create($params);
|
|
|
+ return $this;
|
|
|
}
|
|
|
}
|
|
|
|