add reopen example
This commit is contained in:
parent
396d195cab
commit
1a46b0202c
22
Gitea.php
22
Gitea.php
@ -1,26 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
class Gitea{
|
class Gitea{
|
||||||
|
|
||||||
public function __construct($url,$user,$pass){
|
public function __construct($url,$user,$pass){
|
||||||
$this->url=$url;
|
$this->url=$url;
|
||||||
$this->user=$user;
|
$this->user=$user;
|
||||||
$this->pass=$pass;
|
$this->pass=$pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIssues($user,$repo){
|
public function forIssues($user,$repo,$callback,$args){
|
||||||
$page=1;
|
$page=1;
|
||||||
while(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;
|
if(!$issues) break;
|
||||||
foreach($issues as $issue){
|
foreach($issues as $issue){
|
||||||
echo $issue->number."\n";
|
call_user_func($callback,$issue);
|
||||||
}
|
}
|
||||||
$page++;
|
$page++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function request($url, $postFields = null){
|
public function editIssue($issue,$args){
|
||||||
$url=$this->url.$url;
|
$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";
|
echo ">> $url\n";
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Bot');
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Bot');
|
||||||
@ -30,6 +36,10 @@ 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){
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($postFields)) {
|
if (!is_null($postFields)) {
|
||||||
$postFields = json_encode($postFields);
|
$postFields = json_encode($postFields);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
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