GiteaBot/repeat.php
2019-07-06 16:20:33 +01:00

57 lines
1.8 KiB
PHP

<?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("src/Client.php");
require("src/GiteaData.php");
require("src/GiteaRepoData.php");
require("src/Issue.php");
require("src/Label.php");
require("src/Repo.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']);