GiteaBot/no_milestone.php
2019-06-25 09:16:33 +01:00

26 lines
866 B
PHP

<?php
//Adds a no-milestone label to any issues with no milestone
//Also removes the label if present on an issue with a milestone
include("src/Client.php");
include("src/Issue.php");
include("src/Label.php");
include("src/Repo.php");
$config=include("config.php");
$client=new Client($config['url'],$config['user'],$config['pass']);
$repo=$client->getRepo('james','test');
$nomilestoneLabel=$repo->getLabelByName('no-milestone');
if(!$nomilestoneLabel) die ("Can't find 'no-milestone' label in repo\n");
$callback=function($issue) use ($nomilestoneLabel){
if( count($issue->getData()->milestone)==0 && !$issue->hasLabel($nomilestoneLabel) ){
$issue->addLabel( $nomilestoneLabel );
}elseif( count($issue->getData()->milestone)>0 && $issue->hasLabel($nomilestoneLabel) ){
$issue->removeLabel( $nomilestoneLabel );
}
};
$repo->forIssues($callback);