fix examples and move into a dir of their own
This commit is contained in:
48
example/no_label_milestone.php
Normal file
48
example/no_label_milestone.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
//1a. Adds a no-milestone label to any issues with no milestone
|
||||
//1b. Also removes the label if present on an issue with a milestone
|
||||
//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(__DIR__.'/../bootstrap.php');
|
||||
|
||||
$config=require(__DIR__.'/../config.php');
|
||||
|
||||
//pass cmd line args
|
||||
if($argc<3){
|
||||
die(basename(__FILE__)." <USER> <REPO> [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);
|
Reference in New Issue
Block a user