finish example script and tidy

This commit is contained in:
James 2019-06-26 09:42:37 +01:00
parent d2a5033c90
commit dde8ef1fb5
2 changed files with 16 additions and 3 deletions

View File

@ -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)
Usage example: [no_label_milestone.php](https://git.jhodges.co.uk/james/GiteaBot/src/branch/master/no_label_milestone.php)

View File

@ -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) ){