fix indenting

This commit is contained in:
James 2019-07-30 19:59:22 +01:00
parent 0207c9b4a3
commit c468275075
4 changed files with 90 additions and 90 deletions

View File

@ -3,12 +3,12 @@ class GiteaData{
protected $data=null; protected $data=null;
public function __construct($data=null){ public function __construct($data=null){
if(!$data){ if(!$data){
$data=new stdClass(); $data=new stdClass();
} }
$this->data=$data; $this->data=$data;
} }
public function __set($k,$v){ public function __set($k,$v){
$this->data->$k=$v; $this->data->$k=$v;

View File

@ -1,19 +1,19 @@
<?php <?php
class GiteaRepoData extends GiteaData{ class GiteaRepoData extends GiteaData{
private $repo; private $repo;
public function __construct(Repo $repo,$data){ public function __construct(Repo $repo,$data){
$this->repo=$repo; $this->repo=$repo;
parent::__construct($data); parent::__construct($data);
} }
public function getRepo(){ public function getRepo(){
return $this->repo; return $this->repo;
} }
public function save(){ public function save(){
return $this->repo->request($this->url,'PATCH',$this->data); return $this->repo->request($this->url,'PATCH',$this->data);
} }
} }

View File

@ -1,36 +1,36 @@
<?php <?php
class Issue extends GiteaRepoData{ class Issue extends GiteaRepoData{
public function __construct(Repo $repo,$data){ public function __construct(Repo $repo,$data){
parent::__construct($repo,$data); parent::__construct($repo,$data);
} }
public function request($url, $type='GET', $postFields = null){ public function request($url, $type='GET', $postFields = null){
return $this->getRepo()->request($url, $type, $postFields); return $this->getRepo()->request($url, $type, $postFields);
}
public function addLabel($label){
$args=['labels'=>[$label->id]];
return $this->request($this->url.'/labels','POST',$args);
}
public function removeLabel($label){
$id=$label->id;
return $this->request($this->url."/labels/$id",'DELETE');
}
public function addComment($body){
$args=['body'=>$body];
return $this->request($this->url.'/comments','POST',$args);
}
public function hasLabel($label){
$id=$label->id;
foreach($this->labels as $label){
if($label->id==$id){
return true;
}
} }
return false;
public function addLabel($label){ }
$args=['labels'=>[$label->id]];
return $this->request($this->url.'/labels','POST',$args);
}
public function removeLabel($label){
$id=$label->id;
return $this->request($this->url."/labels/$id",'DELETE');
}
public function addComment($body){
$args=['body'=>$body];
return $this->request($this->url.'/comments','POST',$args);
}
public function hasLabel($label){
$id=$label->id;
foreach($this->labels as $label){
if($label->id==$id){
return true;
}
}
return false;
}
} }

View File

@ -1,57 +1,57 @@
<?php <?php
class Repo{ class Repo{
public function __construct(Client $client,$user,$repo){ public function __construct(Client $client,$user,$repo){
$this->client=$client; $this->client=$client;
$this->user=$user; $this->user=$user;
$this->repo=$repo; $this->repo=$repo;
} }
public function request($url, $type='GET', $postFields = null){ public function request($url, $type='GET', $postFields = null){
return $this->client->request($url, $type, $postFields); return $this->client->request($url, $type, $postFields);
} }
public function forIssues($callback,$args=null){ public function forIssues($callback,$args=null){
$page=1; $page=1;
while(1){ while(1){
$url="repos/{$this->user}/{$this->repo}/issues?page=$page"; $url="repos/{$this->user}/{$this->repo}/issues?page=$page";
if($args){ if($args){
$url.='&'.http_build_query($args); $url.='&'.http_build_query($args);
}
$issues=$this->client->request($url);
if(!$issues) break;
foreach($issues as $data){
$issue=new Issue($this,$data);
call_user_func($callback,$issue);
}
$page++;
}
}
public function getLabelByName($name){
$url="repos/{$this->user}/{$this->repo}/labels";
$data=$this->client->request($url);
foreach($data as $datum){
if($datum->name==$name){
$datum->url=$url."/".$datum->id; // not set by api for some reason (bug?)
return new Label($this,$datum);
}
} }
return null; $issues=$this->client->request($url);
} if(!$issues) break;
foreach($issues as $data){
$issue=new Issue($this,$data);
call_user_func($callback,$issue);
}
$page++;
}
}
public function createLabel($args){ public function getLabelByName($name){
$url="repos/{$this->user}/{$this->repo}/labels"; $url="repos/{$this->user}/{$this->repo}/labels";
$data=$this->client->request($url,'POST',$args); $data=$this->client->request($url);
$data->url=$url."/".$data->id; // not set by api for some reason (bug?) foreach($data as $datum){
return new Label($this,$data); if($datum->name==$name){
} $datum->url=$url."/".$datum->id; // not set by api for some reason (bug?)
return new Label($this,$datum);
}
}
return null;
}
public function createIssue($args){ public function createLabel($args){
$url="repos/{$this->user}/{$this->repo}/issues"; $url="repos/{$this->user}/{$this->repo}/labels";
$data=$this->client->request($url,'POST',$args); $data=$this->client->request($url,'POST',$args);
//$data->url=$url."/".$data->id; // not set by api for some reason (bug?) $data->url=$url."/".$data->id; // not set by api for some reason (bug?)
return new Issue($this,$data); return new Label($this,$data);
} }
public function createIssue($args){
$url="repos/{$this->user}/{$this->repo}/issues";
$data=$this->client->request($url,'POST',$args);
//$data->url=$url."/".$data->id; // not set by api for some reason (bug?)
return new Issue($this,$data);
}
} }