add reopen example
This commit is contained in:
parent
396d195cab
commit
1a46b0202c
18
Gitea.php
18
Gitea.php
@ -7,20 +7,26 @@ class Gitea{
|
||||
$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){
|
||||
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
11
example_reopen_label.php
Normal 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']);
|
Loading…
Reference in New Issue
Block a user