prototype

This commit is contained in:
Gitea 2019-06-20 18:01:08 +01:00
commit 1ba0f72145

50
Gitea.php Normal file
View File

@ -0,0 +1,50 @@
<?php
class Gitea{
public function __construct($url,$user,$pass){
$this->url=$url;
$this->user=$user;
$this->pass=$pass;
}
public function getIssues($user,$repo){
$page=1;
while(1){
$issues=$this->request("repos/$user/$repo/issues?page=$page");
if(!$issues) break;
foreach($issues as $issue){
echo $issue->number."\n";
}
$page++;
}
}
public function request($url, $postFields = null)
{
$url=$this->url.$url;
echo ">> $url\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Bot');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if (!is_null($postFields)) {
$postFields = json_encode($postFields);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json',
'Content-Length: '.strlen($postFields), ]);
}
if($this->user) {
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass);
}
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
}