From 1a46b0202ca8038df15d72215ec6af8fea22f8a7 Mon Sep 17 00:00:00 2001 From: Bob E Moe Date: Thu, 20 Jun 2019 20:13:31 +0100 Subject: [PATCH] add reopen example --- Gitea.php | 22 ++++++++++++++++------ example_reopen_label.php | 11 +++++++++++ test.php | 7 ------- 3 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 example_reopen_label.php delete mode 100644 test.php diff --git a/Gitea.php b/Gitea.php index f0076b9..9f6361c 100644 --- a/Gitea.php +++ b/Gitea.php @@ -1,26 +1,32 @@ 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); diff --git a/example_reopen_label.php b/example_reopen_label.php new file mode 100644 index 0000000..986e7a8 --- /dev/null +++ b/example_reopen_label.php @@ -0,0 +1,11 @@ +editIssue( $issue, ['state'=>'open']); +}; + +$gitea->forIssues('james','rc',$reopen,['state'=>'closed','labels'=>'test']); diff --git a/test.php b/test.php deleted file mode 100644 index 0382ae5..0000000 --- a/test.php +++ /dev/null @@ -1,7 +0,0 @@ -getIssues('james','rc');