115 lines
3.2 KiB
PHP
115 lines
3.2 KiB
PHP
<?php
|
|
require('bootstrap.php');
|
|
|
|
$config=require("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]);
|
|
|
|
$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('d/m/Y',strtotime($issue->updated_at));
|
|
$day_closed=date('d/m/Y',strtotime($issue->closed_at));
|
|
$day_today=date('d/m/Y');
|
|
echo "Weekly: ". $issue->title." ".$issue->closed_at." ($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']);
|