pretty good prototype

This commit is contained in:
James 2019-09-29 11:22:53 +01:00
parent d917a7c27c
commit c05f37ce61

View File

@ -14,35 +14,50 @@ function updateIssueBody($issue,$text){
}
//replace the tag contents with the result from our $text function
$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){
//echo "GOT: {$issue->number}\n";
//extract the rule text
if(preg_match('/RRULE:\s?(.*)/',$issue->body,$matches)){
$rruletxt=$matches[1];
//echo "RRULEtxt: ".$rruletxt."\n";
//create the rule, report any exceptions
try{
$rrule = new RRule($rruletxt);
/*foreach ( $rrule as $occurrence ) {
echo $occurrence->format('D d M Y'),"\n ";
}*/
$result=$rrule->humanReadable()."<br/>\n NEXT1:".$rrule[0]->format('r')."<br/>\n NEXT2:".$rrule[1]->format('r');
updateIssueBody($issue,$result);
$issue->save();
//echo $rrule[0]->format('Y-m-d')." == ".date('Y-m-d')."\n";
}catch(Exception $e){
$result="\n```plain\n".$e->getMessage()." ($rruletxt)\n```\n";
updateIssueBody($issue,$result);
$issue->save();
continue;
}
if($rrule[0]->format('Y-m-d')==date('Y-m-d')){
$issue->addComment("Today (NEXT:".$rrule[1]->format('r').")");
}else{ //couldn't extract, report error
updateIssueBody($issue,"Can't extract RRULE:");
continue;
}
// if we get here, then there is a valid rrule :)
// calcultate some useful info
$next_inc=$rrule->getOccurrencesAfter(date('Y-m-d'),$inclusive=true,$limit=1)[0];
$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);
//is it today?
if($today){
$issue->addComment("Today (NEXT:".$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();
}