pass args and return issues

This commit is contained in:
Bob E Moe 2019-06-23 11:48:59 +01:00
parent ca603025ac
commit da3d2d2c3b

View File

@ -7,10 +7,14 @@ class Gitea{
$this->pass=$pass; $this->pass=$pass;
} }
public function forIssues($user,$repo,$callback,$args){ public function forIssues($user,$repo,$callback,$args=null){
$page=1; $page=1;
while(1){ while(1){
$issues=$this->request("repos/$user/$repo/issues?page=$page&".http_build_query($args)); $url="repos/$user/$repo/issues?page=$page";
if($args){
$url.='&'.http_build_query($args);
}
$issues=$this->request($url);
if(!$issues) break; if(!$issues) break;
foreach($issues as $issue){ foreach($issues as $issue){
call_user_func($callback,$issue); call_user_func($callback,$issue);
@ -20,16 +24,16 @@ class Gitea{
} }
public function editIssue($issue,$args){ public function editIssue($issue,$args){
$this->request($issue->url,$args,true); return $this->request($issue->url,$args,true);
} }
public function request($url, $postFields = null, $patch=false){ public function request($url, $postFields = null, $patch=false){
if(substr($url,0,4)!='http'){ if(substr($url,0,4)!='http'){
$url=$this->url.$url; $url=$this->url.$url;
} }
echo ">> $url\n"; echo ">> $url ".json_encode($postFields).' '.json_encode($patch)." <<\n";
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Bot'); curl_setopt($ch, CURLOPT_USERAGENT, 'james/GiteaBot');
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);