add reopen example

This commit is contained in:
Bob E Moe 2019-06-20 20:13:31 +01:00
parent 396d195cab
commit 1a46b0202c
3 changed files with 27 additions and 13 deletions

View File

@ -1,26 +1,32 @@
<?php
class Gitea{
public function __construct($url,$user,$pass){
$this->url=$url;
$this->user=$user;
$this->pass=$pass;
}
public function getIssues($user,$repo){
public function forIssues($user,$repo,$callback,$args){
$page=1;
while(1){
$issues=$this->request("repos/$user/$repo/issues?page=$page");
$issues=$this->request("repos/$user/$repo/issues?page=$page&".http_build_query($args));
if(!$issues) break;
foreach($issues as $issue){
echo $issue->number."\n";
call_user_func($callback,$issue);
}
$page++;
}
}
public function request($url, $postFields = null){
$url=$this->url.$url;
public function editIssue($issue,$args){
$this->request($issue->url,$args,true);
}
public function request($url, $postFields = null, $patch=false){
if(substr($url,0,4)!='http'){
$url=$this->url.$url;
}
echo ">> $url\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Bot');
@ -30,6 +36,10 @@ class Gitea{
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if($patch){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
}
if (!is_null($postFields)) {
$postFields = json_encode($postFields);
curl_setopt($ch, CURLOPT_POST, true);

11
example_reopen_label.php Normal file
View File

@ -0,0 +1,11 @@
<?php
include("Gitea.php");
$config=include("config.php");
$gitea=new Gitea($config['url'],$config['user'],$config['pass']);
$reopen=function($issue) use ($gitea){
$gitea->editIssue( $issue, ['state'=>'open']);
};
$gitea->forIssues('james','rc',$reopen,['state'=>'closed','labels'=>'test']);

View File

@ -1,7 +0,0 @@
<?php
include("Gitea.php");
$config=include("config.php");
$gitea=new Gitea($config['url'],$config['user'],$config['pass']);
$gitea->getIssues('james','rc');