123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Gogs\API\Request {
- final class Repo extends Base {
-
- public $rid;
- public $rowner;
- public $rname;
- public $rfull_name;
- public $rdescription;
- public $rprivate;
- public $rfork;
- public $rparent;
- public $rempty;
- public $rmirror;
- public $rsize;
- public $rhtml_url;
- public $rssh_url;
- public $rclone_url;
- public $rwebsite;
- public $rstars_count;
- public $rforks_count;
- public $rwatchers_count;
- public $ropen_issues_count;
- public $rdefault_branch;
- public $rcreated_at;
- public $rupdated_at;
- public $rpermissions;
- public $radmin;
- public $rpush;
- public $rpull;
- public function __construct(string $api_url, string $api_token, User $owner = null, string $name = null) {
- $this->rowner = $owner;
- $this->rname = $name;
- parent::__construct($api_url, $api_token);
- }
- protected function set_scope(string $method) {
- switch ($method) {
- case "create":
- if ($this->rowner instanceof Org)
- $this->scope = "/org/" . $this->rowner->uusername . "/repos";
- elseif ($this->rowner->authenticated())
- $this->scope = "/user/repos";
- else
- $this->scope = "/admin/users/" . $this->rowner->uusername . "/repos";
- break;
- case "delete":
- $this->scope = "/repos/" . $this->rowner->uusername . "/" . $this->rname;
- break;
- case "get":
- $this->scope = "/repos/" . ($this->rowner ? $this->rowner->uusername . "/" . $this->rname : $this->rfull_name);
- break;
- default:
- return false;
- }
- return true;
- }
- protected function json_set_property($obj) {
- foreach($obj as $key => $val) {
- $key = 'r' . $key;
- if (property_exists($this, $key)) {
- switch ($key) {
- case 'rowner':
- if (!$this->rowner) {
- $user = new User($this->url, $this->token);
- $user->json_set_property($val);
- $this->{$key} = $user;
- }
- break;
- default:
- $this->{$key} = $val;
- }
- }
- }
- $this->loaded = true;
- }
- public function search(string $q) {
- $searchable = sprintf("%s %s", $this->rname, $this->rdescription);
- return stripos($searchable, $q) !== false;
- }
- 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;
- });
- parent::create($params);
- }
- }
- }
- ?>
|