improve request for new types

This commit is contained in:
Bob E Moe 2019-06-25 08:17:52 +01:00
parent 61066027d1
commit e378c2ee6d

View File

@ -24,19 +24,37 @@ class Gitea{
} }
public function editIssue($issue,$args){ public function editIssue($issue,$args){
return $this->request($issue->url,$args,true); return $this->request($issue->url,'PATCH',$args);
}
public function addLabelsToIssue($issue,$labels){
$args=['labels'=>$labels];
return $this->request($issue->url.'/labels','POST',$args);
}
public function removeLabelFromIssue($issue,$id){
return $this->request($issue->url."/labels/$id",'DELETE');
} }
public function addComment($issue,$body){ public function addComment($issue,$body){
$args=['body'=>$body]; $args=['body'=>$body];
return $this->request($issue->url.'/comments',$args); return $this->request($issue->url.'/comments','POST',$args);
} }
public function request($url, $postFields = null, $patch=false){ public function issueHasLabel($issue,$id){
foreach($issue->labels as $label){
if($label->id==$id){
return true;
}
}
return false;
}
public function request($url, $type='GET', $postFields = null){
if(substr($url,0,4)!='http'){ if(substr($url,0,4)!='http'){
$url=$this->url.$url; $url=$this->url.$url;
} }
echo ">> $url ".json_encode($postFields).' '.json_encode($patch)." <<\n"; echo ">> $type $url ".json_encode($postFields)." <<\n";
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'james/GiteaBot'); curl_setopt($ch, CURLOPT_USERAGENT, 'james/GiteaBot');
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
@ -45,8 +63,8 @@ class Gitea{
curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if($patch){ if($type!='GET'){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
} }
if (!is_null($postFields)) { if (!is_null($postFields)) {