From ba76fded92531f232146c81185321c2dac486ce2 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 1 Aug 2019 15:50:41 +0100 Subject: [PATCH 01/25] importer --- import.csv | 1 + import.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 import.csv create mode 100644 import.php diff --git a/import.csv b/import.csv new file mode 100644 index 0000000..4ea922e --- /dev/null +++ b/import.csv @@ -0,0 +1 @@ +"example title","example body","test" diff --git a/import.php b/import.php new file mode 100644 index 0000000..13fa3b7 --- /dev/null +++ b/import.php @@ -0,0 +1,48 @@ + [debug]\n"); +} +$debug = ($argc==4 && $argv[3]=='debug'); + +//open connection and repo +$client=new Client($config['url'],$config['user'],$config['pass'],$debug); +$repo=$client->getRepo($argv[1],$argv[2]); + +function label($name){ + if($label=$repo->getLabelByName($name)){ + return $label; + }else{ + return $repo->createLabel($name); + } +} + +function issue($name){ + if($label=$repo->getIssueByName($name)){ + return $issue; + }else{ + return $repo->createIssue($name); + } +} + +/* +$jan=label('janurary/repeat'); +$iss=issue('test'); +$iss->addLabel($jan); +*/ + +/* +//do the import +$f=fopen('import.csv','r'); +while($data=fgetcsv($f)){ + print_r($data); +} +*/ + +$issue=new Issue($repo); +$issue->setTitle('nice')->setBody('ly')->save(); +print_r($issue); -- 2.30.2 From 1ee076aac60482fc9ac3bcd521e6b54ddedf5175 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 16 Aug 2019 16:30:38 +0100 Subject: [PATCH 02/25] throw exception on API error --- src/Client.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 27061fc..d04cd3a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -42,9 +42,14 @@ class Client{ 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); + $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - return json_decode($result); + + if(in_array($status_code,[200,201])){ + return json_decode($result); + }else{ + throw new Exception("API $status_code Code: ".$result); + } } } -- 2.30.2 From 6123f69996ee33d60eafe12396cc437a45dfe1df Mon Sep 17 00:00:00 2001 From: James Date: Fri, 16 Aug 2019 16:42:24 +0100 Subject: [PATCH 03/25] fix examples and move into a dir of their own --- .../no_label_milestone.php | 4 +- repeat.php => example/repeat.php | 4 +- import.csv => example/test.csv | 0 example/test.php | 28 +++++++++++ import.php | 48 ------------------- 5 files changed, 32 insertions(+), 52 deletions(-) rename no_label_milestone.php => example/no_label_milestone.php (95%) rename repeat.php => example/repeat.php (97%) rename import.csv => example/test.csv (100%) create mode 100644 example/test.php delete mode 100644 import.php diff --git a/no_label_milestone.php b/example/no_label_milestone.php similarity index 95% rename from no_label_milestone.php rename to example/no_label_milestone.php index b6865b6..211585e 100644 --- a/no_label_milestone.php +++ b/example/no_label_milestone.php @@ -4,9 +4,9 @@ //2a. Adds a no-label label to any issues with no labels (excluding the no-label and no-milestone) //2b. Also removes the label if present on an issue with a label (excluding the no-label and no-milestone) -require('bootstrap.php'); +require(__DIR__.'/../bootstrap.php'); -$config=require('config.php'); +$config=require(__DIR__.'/../config.php'); //pass cmd line args if($argc<3){ diff --git a/repeat.php b/example/repeat.php similarity index 97% rename from repeat.php rename to example/repeat.php index 6aaf676..6582cdc 100644 --- a/repeat.php +++ b/example/repeat.php @@ -1,7 +1,7 @@ [debug]\n"); +} +$debug = ($argc==4 && $argv[3]=='debug'); + +//open connection and repo +$client=new Client($config['url'],$config['user'],$config['pass'],$debug); +$repo=$client->getRepo($argv[1],$argv[2]); + +//create a label +if(!$label=$repo->getLabelByName('Test')){ + $label=$repo->createLabel(['name'=>'Test','color'=>'#336699']); +} + +//create a test issue +$issue=$repo->createIssue([ + 'title'=>'Test', + 'body'=>'Just testing' +]); +$issue->addLabel($label); +$issue->addComment('Test comment'); +$issue->save(); diff --git a/import.php b/import.php deleted file mode 100644 index 13fa3b7..0000000 --- a/import.php +++ /dev/null @@ -1,48 +0,0 @@ - [debug]\n"); -} -$debug = ($argc==4 && $argv[3]=='debug'); - -//open connection and repo -$client=new Client($config['url'],$config['user'],$config['pass'],$debug); -$repo=$client->getRepo($argv[1],$argv[2]); - -function label($name){ - if($label=$repo->getLabelByName($name)){ - return $label; - }else{ - return $repo->createLabel($name); - } -} - -function issue($name){ - if($label=$repo->getIssueByName($name)){ - return $issue; - }else{ - return $repo->createIssue($name); - } -} - -/* -$jan=label('janurary/repeat'); -$iss=issue('test'); -$iss->addLabel($jan); -*/ - -/* -//do the import -$f=fopen('import.csv','r'); -while($data=fgetcsv($f)){ - print_r($data); -} -*/ - -$issue=new Issue($repo); -$issue->setTitle('nice')->setBody('ly')->save(); -print_r($issue); -- 2.30.2 From ed0e70898a80fc7b0f3156e897ec218857bbbf35 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 16 Aug 2019 16:48:06 +0100 Subject: [PATCH 04/25] update example --- example/test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/test.php b/example/test.php index 440d546..bd2144c 100644 --- a/example/test.php +++ b/example/test.php @@ -13,7 +13,7 @@ $debug = ($argc==4 && $argv[3]=='debug'); $client=new Client($config['url'],$config['user'],$config['pass'],$debug); $repo=$client->getRepo($argv[1],$argv[2]); -//create a label +//get the test label or create if not exist if(!$label=$repo->getLabelByName('Test')){ $label=$repo->createLabel(['name'=>'Test','color'=>'#336699']); } @@ -26,3 +26,7 @@ $issue=$repo->createIssue([ $issue->addLabel($label); $issue->addComment('Test comment'); $issue->save(); + +//change the issue body +$issue->body.=' (Edited!)'; +$issue->save(); -- 2.30.2 From d85fe085047c0676a079e597411db625ba247f67 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 16 Aug 2019 16:49:02 +0100 Subject: [PATCH 05/25] update link to new location --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 89f1c3c..43158f1 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Simple PHP library to interface with Gitea API Designed to make a "Bot" for manipulating labels on issues. -Usage example: [no_label_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/no_label_milestone.php) +Usage example: [no_label_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/example) -- 2.30.2 From a6bb48ef96730001b64de24a656a946bb672283c Mon Sep 17 00:00:00 2001 From: James Date: Sat, 24 Aug 2019 14:31:26 +0100 Subject: [PATCH 06/25] cache label names for MUCH quicker scripts when getting many labels --- src/Repo.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Repo.php b/src/Repo.php index 0fdd6f4..fa92669 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -1,6 +1,8 @@ client=$client; $this->user=$user; @@ -29,9 +31,12 @@ class Repo{ } public function getLabelByName($name){ - $url="repos/{$this->user}/{$this->repo}/labels"; - $data=$this->client->request($url); - foreach($data as $datum){ + if(!$this->cache['lables']){ + $url="repos/{$this->user}/{$this->repo}/labels"; + $this->cache['lables']=$this->client->request($url); + } + + foreach($this->cache['lables'] as $datum){ if($datum->name==$name){ $datum->url=$url."/".$datum->id; // not set by api for some reason (bug?) return new Label($this,$datum); -- 2.30.2 From 9be81336160b9618cc75171a009522b0f6cb7c64 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 24 Aug 2019 14:31:35 +0100 Subject: [PATCH 07/25] add new close all example --- example/close_all.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 example/close_all.php diff --git a/example/close_all.php b/example/close_all.php new file mode 100644 index 0000000..dd61bed --- /dev/null +++ b/example/close_all.php @@ -0,0 +1,20 @@ + [debug]\n"); +} +$debug = ($argc==4 && $argv[3]=='debug'); + +//open connection and repo +$client=new Client($config['url'],$config['user'],$config['pass'],$debug); +$repo=$client->getRepo($argv[1],$argv[2]); + +//close all issues +$repo->forIssues(function($issue){ + $issue->state='closed'; + $issue->save(); +}); -- 2.30.2 From d6ca95922617f25903dda431d9ed695c7a270ae4 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 24 Aug 2019 14:52:48 +0100 Subject: [PATCH 08/25] add composer.json --- .gitignore | 2 ++ composer.json | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 composer.json diff --git a/.gitignore b/.gitignore index b74decb..c30df37 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /config.php + +/vendor/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b8688e6 --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "name": "jh/giteabot", + "description": "Simple PHP library to interface with Gitea API", + "type": "library", + "license": "OS", + "authors": [ + { + "name": "James", + "email": "inbox.dev@jhodges.co.uk" + } + ], + "require": {} +} -- 2.30.2 From cda81d95aedb821961a750e1c4276573bf207349 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 25 Aug 2019 09:27:36 +0100 Subject: [PATCH 09/25] added install for composer --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43158f1..052e992 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ +# GiteaBot Simple PHP library to interface with Gitea API Designed to make a "Bot" for manipulating labels on issues. - +## Install +composer create-project -s dev jh/giteabot --repository-url 'https://git.jhodges.co.uk/composer/' +## Usage Usage example: [no_label_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/example) + + -- 2.30.2 From bb1e21db2edce4fcd17140855eefce3eda307b76 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 25 Aug 2019 10:45:41 +0100 Subject: [PATCH 10/25] Update 'README.md' --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 052e992..e14e96b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,20 @@ Simple PHP library to interface with Gitea API Designed to make a "Bot" for manipulating labels on issues. +## Create New Project (optional) +You only need to do this if you dont already have a composer project. +```bash +mkdir bot +cd bot +composer init -n --name "acme/bot" --description "my bot!" --author "Me " +``` + ## Install -composer create-project -s dev jh/giteabot --repository-url 'https://git.jhodges.co.uk/composer/' +```bash +composer config repositories.repo-name vcs https://git.jhodges.co.uk/composer/ +composer require jh/giteabot:dev-composer +``` + ## Usage Usage example: [no_label_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/example) -- 2.30.2 From 5eb7e5f872f99a29b06af6cd7c653f02a08ce021 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 25 Aug 2019 10:47:04 +0100 Subject: [PATCH 11/25] Update 'README.md' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e14e96b..abe1172 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Simple PHP library to interface with Gitea API Designed to make a "Bot" for manipulating labels on issues. ## Create New Project (optional) -You only need to do this if you dont already have a composer project. +You only need to do this if you don't already have a composer project. Use the following commands, or create your composer.json manually. ```bash mkdir bot cd bot -- 2.30.2 From d4bdbc2c16526470f56bae8d565070ccf4ebbbd1 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 25 Aug 2019 10:57:20 +0100 Subject: [PATCH 12/25] remove example code to seperate project --- bootstrap.php | 4 -- config.php.dist | 6 -- example/close_all.php | 20 ------ example/no_label_milestone.php | 48 -------------- example/repeat.php | 114 --------------------------------- example/test.csv | 1 - example/test.php | 32 --------- 7 files changed, 225 deletions(-) delete mode 100644 bootstrap.php delete mode 100644 config.php.dist delete mode 100644 example/close_all.php delete mode 100644 example/no_label_milestone.php delete mode 100644 example/repeat.php delete mode 100644 example/test.csv delete mode 100644 example/test.php diff --git a/bootstrap.php b/bootstrap.php deleted file mode 100644 index 1659c20..0000000 --- a/bootstrap.php +++ /dev/null @@ -1,4 +0,0 @@ -'', - 'user'=>'', - 'pass'=>'', -]; diff --git a/example/close_all.php b/example/close_all.php deleted file mode 100644 index dd61bed..0000000 --- a/example/close_all.php +++ /dev/null @@ -1,20 +0,0 @@ - [debug]\n"); -} -$debug = ($argc==4 && $argv[3]=='debug'); - -//open connection and repo -$client=new Client($config['url'],$config['user'],$config['pass'],$debug); -$repo=$client->getRepo($argv[1],$argv[2]); - -//close all issues -$repo->forIssues(function($issue){ - $issue->state='closed'; - $issue->save(); -}); diff --git a/example/no_label_milestone.php b/example/no_label_milestone.php deleted file mode 100644 index 211585e..0000000 --- a/example/no_label_milestone.php +++ /dev/null @@ -1,48 +0,0 @@ - [debug]\n"); -} -$debug = ($argc==4 && $argv[3]=='debug'); - -//open connection and repo -$client=new Client($config['url'],$config['user'],$config['pass'],$debug); -$repo=$client->getRepo($argv[1],$argv[2]); - -//get the labels of interest -$nolabelLabel=$repo->getLabelByName('no-label'); -if(!$nolabelLabel) die ("Can't find 'no-label' label in repo\n"); - -$nomilestoneLabel=$repo->getLabelByName('no-milestone'); -if(!$nomilestoneLabel) die ("Can't find 'no-milestone' label in repo\n"); - -//define the function to process each issue -$callback=function($issue) use ($nolabelLabel,$nomilestoneLabel){ - // do the no-label thing - $labelCount=count($issue->labels); - if($issue->hasLabel($nolabelLabel)) $labelCount--; //dont count the no-label label - if($nomilestoneLabel && $issue->hasLabel($nomilestoneLabel)) $labelCount--; //dont count the no-milestone label - if($labelCount==0 && !$issue->hasLabel($nolabelLabel) ){ - $issue->addLabel( $nolabelLabel ); - }elseif( $labelCount>0 && $issue->hasLabel($nolabelLabel) ){ - $issue->removeLabel( $nolabelLabel ); - } - //do the no-milestone thing - if( !$issue->milestone && !$issue->hasLabel($nomilestoneLabel) ){ - $issue->addLabel( $nomilestoneLabel ); - }elseif( $issue->milestone && $issue->hasLabel($nomilestoneLabel) ){ - $issue->removeLabel( $nomilestoneLabel ); - } -}; - -//loop through issues and call the callback -$repo->forIssues($callback); diff --git a/example/repeat.php b/example/repeat.php deleted file mode 100644 index 6582cdc..0000000 --- a/example/repeat.php +++ /dev/null @@ -1,114 +0,0 @@ - [debug]\n"); -} -$debug = ($argc==4 && $argv[3]=='debug'); - -//open connection and repo -$client=new Client($config['url'],$config['user'],$config['pass'],$debug); -$repo=$client->getRepo($argv[1],$argv[2]); - -$terms=[ - 'months'=>['janurary','feburary','march','april','may','june','july','august','september','october','november','december'], - 'days'=>['monday','tuesday','wednesday','thursday','friday','saturday','sunday'], - 'generic'=>['daily','weekly','fortnightly','monthly','yearly'] -]; - -/* create the labels */ -/* -foreach($terms as $k=>$vs){ - foreach($vs as $v){ - $label=$repo->getLabelByName($v); - if(!$label){ - $label=$repo->createLabel(['name'=>$new_name,'color'=>'#ffff00','description'=>'Reopen this issue with the given frequency']); - } - } -} -*/ - -//define the function to process each issue - -$daily=function($issue){ - $day_updated=date('d/m/Y',strtotime($issue->updated_at)); - $day_closed=date('d/m/Y',strtotime($issue->closed_at)); - $day_today=date('d/m/Y'); - echo "Daily: ". $issue->title." ".$issue->closed_at." ($day_closed, $day_today) \n"; - if($day_closed!=$day_today){ - if($issue->state=="closed"){ - $issue->state='open'; - $issue->save(); - }else{ - if($day_updated!=$day_today){ - $issue->addComment("NAG!"); - } - } - } -}; - -$monthly=function($issue) use ($terms){ - $month_closed=date('m/Y',strtotime($issue->closed_at)); - $month_today=date('m/Y'); - echo "Monthly: ".$issue->title." ".$issue->closed_at." ($month_closed, $month_today) \n"; - //print_r($issue->labels); - //print_r(getRepeatTerms($issue,$terms)); - //die(); - if($month_closed!=$month_today){ - $issue->state='open'; - $issue->save(); - } -}; - -$weekly=function($issue){ - $day_updated=date('z',strtotime($issue->updated_at)); - $day_closed=date('z',strtotime($issue->closed_at)); - $day_today=date('z'); - echo "Weekly: ". $issue->title." ".$issue->closed_at." ($day_closed, $day_today => ".(abs($day_closed-$day_today)).") \n"; - if( abs($day_closed-$day_today)>7 ){ - if($issue->state=="closed"){ - $issue->state='open'; - $issue->save(); - }else{ - if($day_updated!=$day_today){ - $issue->addComment("NAG!"); - } - } - } -}; - -$tmp=function($issue){ - //$hours_ago=(time()-strtotime($issue->closed_at))/60/60; -}; - -function getRepeatTerms($issue,$terms){ - $labels=[]; - $found=[]; - foreach($issue->labels as $label){ - $labels[]=$label->name; - } - print_r($labels); - foreach($terms as $name=>$values){ - foreach($values as $value){ - if( in_array("$value/repeat",$labels) ){ - $found[$name][]=$value; - } - } - } - return $found; -} - -//loop through issues and call the callback -$day_name=strtolower(date('l')); -$month_name=strtolower(date('F')); - -//$repo->forIssues($daily,['state'=>'open','labels'=>'daily/repeat']); -//die(); -$repo->forIssues($weekly,['state'=>'closed','labels'=>'weekly/repeat']); -$repo->forIssues($daily,['state'=>'closed','labels'=>'daily/repeat']); -$repo->forIssues($daily,['state'=>'closed','labels'=>$day_name.'/repeat']); -$repo->forIssues($monthly,['state'=>'closed','labels'=>'monthly/repeat']); -$repo->forIssues($monthly,['state'=>'closed','labels'=>$month_name.'/repeat']); diff --git a/example/test.csv b/example/test.csv deleted file mode 100644 index 4ea922e..0000000 --- a/example/test.csv +++ /dev/null @@ -1 +0,0 @@ -"example title","example body","test" diff --git a/example/test.php b/example/test.php deleted file mode 100644 index bd2144c..0000000 --- a/example/test.php +++ /dev/null @@ -1,32 +0,0 @@ - [debug]\n"); -} -$debug = ($argc==4 && $argv[3]=='debug'); - -//open connection and repo -$client=new Client($config['url'],$config['user'],$config['pass'],$debug); -$repo=$client->getRepo($argv[1],$argv[2]); - -//get the test label or create if not exist -if(!$label=$repo->getLabelByName('Test')){ - $label=$repo->createLabel(['name'=>'Test','color'=>'#336699']); -} - -//create a test issue -$issue=$repo->createIssue([ - 'title'=>'Test', - 'body'=>'Just testing' -]); -$issue->addLabel($label); -$issue->addComment('Test comment'); -$issue->save(); - -//change the issue body -$issue->body.=' (Edited!)'; -$issue->save(); -- 2.30.2 From 2f04372d87159fc27755d5146e66746526a8c82c Mon Sep 17 00:00:00 2001 From: James Date: Sun, 25 Aug 2019 12:30:35 +0100 Subject: [PATCH 13/25] add namespaces --- src/Client.php | 2 ++ src/GiteaData.php | 2 ++ src/GiteaRepoData.php | 2 ++ src/Issue.php | 2 ++ src/Label.php | 2 ++ src/Repo.php | 2 ++ 6 files changed, 12 insertions(+) diff --git a/src/Client.php b/src/Client.php index d04cd3a..8f22cbe 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,4 +1,6 @@ Date: Sun, 25 Aug 2019 12:39:00 +0100 Subject: [PATCH 14/25] update composer with namespace info --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b8688e6..b6b7270 100644 --- a/composer.json +++ b/composer.json @@ -2,12 +2,13 @@ "name": "jh/giteabot", "description": "Simple PHP library to interface with Gitea API", "type": "library", - "license": "OS", + "license": "GPL3", "authors": [ { "name": "James", "email": "inbox.dev@jhodges.co.uk" } ], + "psr-4": { "JHodges\\GiteaBot\\": "src/" } "require": {} } -- 2.30.2 From 1064c504074bebb0d13a54c4e1d6191e4ee5ba6b Mon Sep 17 00:00:00 2001 From: James Date: Mon, 26 Aug 2019 09:07:38 +0100 Subject: [PATCH 15/25] Update 'composer.json' --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b6b7270..5edff1f 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "jh/giteabot", + "name": "jhodges/giteabot", "description": "Simple PHP library to interface with Gitea API", "type": "library", "license": "GPL3", @@ -9,6 +9,6 @@ "email": "inbox.dev@jhodges.co.uk" } ], - "psr-4": { "JHodges\\GiteaBot\\": "src/" } + "psr-4": { "JHodges\\GiteaBot\\": "src/" }, "require": {} } -- 2.30.2 From 4747e9b270d97a9ccabb5f6cf547b334e8249a34 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 26 Aug 2019 09:40:58 +0100 Subject: [PATCH 16/25] fix autoloader in composer --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5edff1f..79b4cb4 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,10 @@ "email": "inbox.dev@jhodges.co.uk" } ], - "psr-4": { "JHodges\\GiteaBot\\": "src/" }, + "autoload": { + "psr-4": { + "JHodges\\GiteaBot\\": "src/" + } + }, "require": {} } -- 2.30.2 From 22b423cd5eddafb67a74c94abd61008300145253 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 26 Aug 2019 09:46:49 +0100 Subject: [PATCH 17/25] fix namespace of Exception --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 8f22cbe..8ec59ed 100644 --- a/src/Client.php +++ b/src/Client.php @@ -51,7 +51,7 @@ class Client{ if(in_array($status_code,[200,201])){ return json_decode($result); }else{ - throw new Exception("API $status_code Code: ".$result); + throw new \Exception("API $status_code Code: ".$result); } } } -- 2.30.2 From d5c65bcb7e84d09ecdb6f6c084c4438104231099 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 26 Aug 2019 09:51:06 +0100 Subject: [PATCH 18/25] remove referances to old examples (now in seperate repo) --- .gitignore | 2 -- README.md | 15 +-------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index c30df37..57872d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -/config.php - /vendor/ diff --git a/README.md b/README.md index abe1172..84d2cfd 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,8 @@ Simple PHP library to interface with Gitea API Designed to make a "Bot" for manipulating labels on issues. -## Create New Project (optional) -You only need to do this if you don't already have a composer project. Use the following commands, or create your composer.json manually. -```bash -mkdir bot -cd bot -composer init -n --name "acme/bot" --description "my bot!" --author "Me " -``` - -## Install -```bash -composer config repositories.repo-name vcs https://git.jhodges.co.uk/composer/ -composer require jh/giteabot:dev-composer -``` ## Usage -Usage example: [no_label_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/example) +For usage examples see https://git.jhodges.co.uk/james/GiteaBot-examples -- 2.30.2 From 7aad548198feba2e965a96b69a7f10edbbfc9e68 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 26 Aug 2019 10:10:37 +0100 Subject: [PATCH 19/25] Update 'README.md' --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 84d2cfd..b6cfc7a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ # GiteaBot Simple PHP library to interface with Gitea API -Designed to make a "Bot" for manipulating labels on issues. +Designed to make a "Bot" for manipulating labels and issues. -## Usage For usage examples see https://git.jhodges.co.uk/james/GiteaBot-examples -- 2.30.2 From a0865766b3f648c0b21ddbb31d0763dd08616ac8 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 29 Aug 2019 07:45:08 +0100 Subject: [PATCH 20/25] fix: warning: undefined index for $cache['labels'] --- src/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repo.php b/src/Repo.php index 530c869..362b2a9 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -33,7 +33,7 @@ class Repo{ } public function getLabelByName($name){ - if(!$this->cache['lables']){ + if(!isset($this->cache['lables'])){ $url="repos/{$this->user}/{$this->repo}/labels"; $this->cache['lables']=$this->client->request($url); } -- 2.30.2 From d56a75b629d161df5bb2b75a9d29531910c725a4 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 29 Aug 2019 10:55:05 +0100 Subject: [PATCH 21/25] bug: url not being set properly when reading from cache --- src/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repo.php b/src/Repo.php index 362b2a9..358e8d8 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -33,8 +33,8 @@ class Repo{ } public function getLabelByName($name){ + $url="repos/{$this->user}/{$this->repo}/labels"; if(!isset($this->cache['lables'])){ - $url="repos/{$this->user}/{$this->repo}/labels"; $this->cache['lables']=$this->client->request($url); } -- 2.30.2 From 5cbf35add3fb66efadbba5b991f2651a1f2c4794 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 2 Sep 2019 20:36:08 +0100 Subject: [PATCH 22/25] add deleteLabel --- src/Repo.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Repo.php b/src/Repo.php index 358e8d8..21a42e1 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -54,6 +54,10 @@ class Repo{ return new Label($this,$data); } + public function deleteLabel($label){ + $data=$this->client->request($label->url,'DELETE'); + } + public function createIssue($args){ $url="repos/{$this->user}/{$this->repo}/issues"; $data=$this->client->request($url,'POST',$args); -- 2.30.2 From 5959b1ffe5e65101e189f17d4428c5fd5df21edf Mon Sep 17 00:00:00 2001 From: James Date: Tue, 3 Sep 2019 10:55:41 +0100 Subject: [PATCH 23/25] add 204 as an non-error response code from API (recieved after a DELETE) --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 8ec59ed..bd8cb09 100644 --- a/src/Client.php +++ b/src/Client.php @@ -48,7 +48,7 @@ class Client{ $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - if(in_array($status_code,[200,201])){ + if(in_array($status_code,[200,201,204])){ return json_decode($result); }else{ throw new \Exception("API $status_code Code: ".$result); -- 2.30.2 From 47d54d63f75f31349d28b89e767c98efaf337469 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 5 Sep 2019 16:27:23 +0100 Subject: [PATCH 24/25] support for comments --- src/Issue.php | 4 ++++ src/Repo.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/Issue.php b/src/Issue.php index cf0ef91..25078d3 100644 --- a/src/Issue.php +++ b/src/Issue.php @@ -26,6 +26,10 @@ class Issue extends GiteaRepoData{ return $this->request($this->url.'/comments','POST',$args); } + public function getComments(){ + return $this->request($this->url.'/comments','GET'); + } + public function hasLabel($label){ $id=$label->id; foreach($this->labels as $label){ diff --git a/src/Repo.php b/src/Repo.php index 21a42e1..5e766d7 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -58,6 +58,11 @@ class Repo{ $data=$this->client->request($label->url,'DELETE'); } + public function deleteComment($comment){ + $url="repos/{$this->user}/{$this->repo}/issues/comments/{$comment->id}"; + $data=$this->client->request($url,'DELETE'); + } + public function createIssue($args){ $url="repos/{$this->user}/{$this->repo}/issues"; $data=$this->client->request($url,'POST',$args); -- 2.30.2 From cd79454aa703b810c46bf2dce5f65bc6ec264687 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 5 Sep 2019 17:15:58 +0100 Subject: [PATCH 25/25] Update 'README.md' --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index b6cfc7a..4e5fde5 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,22 @@ Designed to make a "Bot" for manipulating labels and issues. For usage examples see https://git.jhodges.co.uk/james/GiteaBot-examples +## Change Log +v1.2 + +* Added namespacing and composer.json +* Moved usage example code to seperate repo +* Added support for add/delete comment + +V1.1.1 + +* Refactor, bootstrap, examples + +V1.1 + +* Refactor, better OO, examples + +v1.0 + +* Initial Prototype \ No newline at end of file -- 2.30.2