From dde8ef1fb507d07b820a00fd10e85cd18dc04277 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 26 Jun 2019 09:42:37 +0100 Subject: [PATCH] finish example script and tidy --- README.md | 2 +- no_milestone.php => no_label_milestone.php | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) rename no_milestone.php => no_label_milestone.php (53%) diff --git a/README.md b/README.md index 5ac689b..89f1c3c 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_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/no_milestone.php) \ No newline at end of file +Usage example: [no_label_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/no_label_milestone.php) diff --git a/no_milestone.php b/no_label_milestone.php similarity index 53% rename from no_milestone.php rename to no_label_milestone.php index 47d0150..f41db63 100644 --- a/no_milestone.php +++ b/no_label_milestone.php @@ -8,13 +8,26 @@ include("src/Label.php"); include("src/Repo.php"); $config=include("config.php"); -$client=new Client($config['url'],$config['user'],$config['pass']); +$client=new Client($config['url'],$config['user'],$config['pass'],true); $repo=$client->getRepo('james','test'); +$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"); -$callback=function($issue) use ($nomilestoneLabel){ +$callback=function($issue) use ($nolabelLabel,$nomilestoneLabel){ + // do the no-label thing + $labelCount=count($issue->getData()->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( count($issue->getData()->milestone)==0 && !$issue->hasLabel($nomilestoneLabel) ){ $issue->addLabel( $nomilestoneLabel ); }elseif( count($issue->getData()->milestone)>0 && $issue->hasLabel($nomilestoneLabel) ){