working rrule prototype
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
/*
|
||||
* This will find all issues with RRULE: in the body
|
||||
* 1. extract the RRULE string and calculate the recurring dates.
|
||||
* 2. if the rule is due to occure today then:
|
||||
* 2a. if the issue is closed then it will re-open it,
|
||||
* 2b. and it will add a comment "Today!"
|
||||
*/
|
||||
|
||||
// load the config, create the connection and load the repo sepcified on the cmd line args
|
||||
// we will then have $client and $repo available
|
||||
require('setup.php');
|
||||
|
||||
use RRule\RRule;
|
||||
|
||||
//callback function to add/replace the tag with our text
|
||||
//function to add/replace the tag with our text
|
||||
/*
|
||||
function updateIssueBody($issue,$text){
|
||||
$issue->addComment($text);
|
||||
return;
|
||||
|
||||
// add a tag to the body if to doesn't exist
|
||||
if( strpos($issue->body,'<!--BOT-->')===false ){
|
||||
$issue->body.="\n<!--BOT--><hr/><!--ENDBOT-->";
|
||||
@@ -16,9 +28,15 @@ function updateIssueBody($issue,$text){
|
||||
$issue->body=preg_replace("#<!--BOT-->.*?<!--ENDBOT-->#s",'<!--BOT--><hr/>'.$text.'<!--ENDBOT-->',$issue->body);
|
||||
$issue->save();
|
||||
};
|
||||
*/
|
||||
|
||||
//loop through each issue that has a RRULE
|
||||
foreach($repo->getIssues(['q'=>'RRULE:']) as $issue){
|
||||
$issues=array_merge(
|
||||
$repo->getIssues(['q'=>'RRULE:']),
|
||||
$repo->getIssues(['q'=>'RRULE:','state'=>'closed'])
|
||||
);
|
||||
foreach($issues as $issue){
|
||||
echo "\n\n### ".$issue->number.": ".$issue->title."\n";
|
||||
//extract the rule text
|
||||
if(preg_match('/RRULE:\s?(.*)/',$issue->body,$matches)){
|
||||
$rruletxt=$matches[1];
|
||||
@@ -26,12 +44,12 @@ foreach($repo->getIssues(['q'=>'RRULE:']) as $issue){
|
||||
try{
|
||||
$rrule = new RRule($rruletxt);
|
||||
}catch(Exception $e){
|
||||
$result="\n```plain\n".$e->getMessage()." ($rruletxt)\n```\n";
|
||||
updateIssueBody($issue,$result);
|
||||
continue;
|
||||
$result="Error in RRULE\n```plain\n".$e->getMessage()."\n\n$rruletxt\n```\n";
|
||||
$issue->addComment($result);
|
||||
continue;
|
||||
}
|
||||
}else{ //couldn't extract, report error
|
||||
updateIssueBody($issue,"Can't extract RRULE:");
|
||||
$issue->addComment("Can't extract RRULE:");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -42,22 +60,32 @@ foreach($repo->getIssues(['q'=>'RRULE:']) as $issue){
|
||||
$next_exc=$rrule->getOccurrencesAfter(date('Y-m-d'),$inclusive=false,$limit=1)[0];
|
||||
$today=$next_inc->format('Y-m-d')==date('Y-m-d');
|
||||
|
||||
//some debug
|
||||
$result=$rrule->humanReadable().
|
||||
"<br/>\n NOW: ".date('Y-m-d').
|
||||
"<br/>\n First: ".$rrule[0]->format('Y-m-d').
|
||||
"<br/>\n Second: ".$rrule[1]->format('Y-m-d').
|
||||
"<br/>\n Today: ".($today?'Yes':'no').
|
||||
"<br/>\n Next Inc: ".$next_inc->format('Y-m-d').
|
||||
"<br/>\n Next Exc: ".$next_exc->format('Y-m-d');
|
||||
updateIssueBody($issue,$result);
|
||||
if($debug){
|
||||
echo $rrule->humanReadable().
|
||||
"\n NOW: ".date('Y-m-d').
|
||||
"\n First: ".$rrule[0]->format('Y-m-d').
|
||||
"\n Second: ".$rrule[1]->format('Y-m-d').
|
||||
"\n Today: ".($today?'Yes':'no').
|
||||
"\n Next Inc: ".$next_inc->format('Y-m-d').
|
||||
"\n Next Exc: ".$next_exc->format('Y-m-d').
|
||||
"\n";
|
||||
}
|
||||
|
||||
//is it today?
|
||||
if($today){
|
||||
$issue->addComment("Today (NEXT:".$next_exc->format('Y-m-d').")");
|
||||
echo "@Today\n";
|
||||
if($issue->state=='closed'){
|
||||
$issue->state='open';
|
||||
$issue->save();
|
||||
}
|
||||
$issue->addComment("Today!!\n\nNext: ".$next_exc->format('Y-m-d'));
|
||||
}
|
||||
|
||||
// not working https://github.com/go-gitea/gitea/issues/8179
|
||||
//$issue->due_date=$rrule[0]->format('c');
|
||||
//$issue->save();
|
||||
//$issue->save();
|
||||
//if( date('Y-m-d',strtotime($issue->due_date)) != $next_exc->format('Y-m-d') ){
|
||||
/*if( !$issue->due_date ){
|
||||
$issue->setDueDate($next_exc);
|
||||
}*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user