93 lines
2.4 KiB
PHP
93 lines
2.4 KiB
PHP
<?php
|
|
namespace JHodges\GiteaBot;
|
|
|
|
class Repo{
|
|
|
|
private $cache=[];
|
|
|
|
public function __construct(Client $client,$user,$repo){
|
|
$this->client=$client;
|
|
$this->user=$user;
|
|
$this->repo=$repo;
|
|
}
|
|
|
|
public function request($url, $type='GET', $postFields = null){
|
|
return $this->client->request($url, $type, $postFields);
|
|
}
|
|
|
|
public function forIssues($callback,$args=null){
|
|
$page=1;
|
|
while(1){
|
|
$url="repos/{$this->user}/{$this->repo}/issues?page=$page";
|
|
if($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 getIssues($args=null){
|
|
$page=1;
|
|
$all_issues=[];
|
|
while(1){
|
|
$url="repos/{$this->user}/{$this->repo}/issues?page=$page";
|
|
if($args){
|
|
$url.='&'.http_build_query($args);
|
|
}
|
|
$issues=$this->client->request($url);
|
|
foreach($issues as $data){
|
|
$issue=new Issue($this,$data);
|
|
$all_issues[]=$issue;
|
|
}
|
|
if(!$issues) break;
|
|
$page++;
|
|
}
|
|
return $all_issues;
|
|
}
|
|
|
|
public function getLabelByName($name){
|
|
$url="repos/{$this->user}/{$this->repo}/labels";
|
|
if(!isset($this->cache['lables'])){
|
|
$this->cache['lables']=$this->client->request($url);
|
|
}
|
|
|
|
foreach($this->cache['lables'] 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;
|
|
}
|
|
|
|
public function createLabel($args){
|
|
$url="repos/{$this->user}/{$this->repo}/labels";
|
|
$data=$this->client->request($url,'POST',$args);
|
|
$data->url=$url."/".$data->id; // not set by api for some reason (bug?)
|
|
return new Label($this,$data);
|
|
}
|
|
|
|
public function deleteLabel($label){
|
|
$data=$this->client->request($label->url,'DELETE');
|
|
}
|
|
|
|
public function deleteComment($comment){
|
|
$url="repos/{$this->user}/{$this->repo}/issues/comments/{$comment->id}";
|
|
$data=$this->client->request($url,'DELETE');
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|