GiteaBot/repeat.php
2019-07-06 16:25:47 +01:00

48 lines
1.4 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){
//$hours_ago=(time()-strtotime($issue->closed_at))/60/60;
$day_closed=date('z',strtotime($issue->closed_at));
$day_today=date('z');
echo $issue->title." ".$issue->closed_at." ($day_closed, $day_today) \n";
if($day_closed!=$day_today){
$issue->state='open';
$issue->save();
}
};
//loop through issues and call the callback
$repo->forIssues($daily,['state'=>'closed','labels'=>'daily/repeat']);