#!/usr/bin/php addComment($text); return; // add a tag to the body if to doesn't exist if( strpos($issue->body,'')===false ){ $issue->body.="\n
"; } //replace the tag contents with the result from our $text function $issue->body=preg_replace("#.*?#s",'
'.$text.'',$issue->body); $issue->save(); }; */ //loop through each issue that has a RRULE $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]; //create the rule, report any exceptions try{ $rrule = new RRule($rruletxt); }catch(Exception $e){ $result="Error in RRULE\n```plain\n".$e->getMessage()."\n\n$rruletxt\n```\n"; $issue->addComment($result); continue; } }else{ //couldn't extract, report error $issue->addComment("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'); 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){ 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(); //if( date('Y-m-d',strtotime($issue->due_date)) != $next_exc->format('Y-m-d') ){ if( $issue->due_date ){ if( strtotime(date('Y-m-d',strtotime($issue->due_date))) < strtotime($next_exc->format('Y-m-d')) ){ echo "@Overdue\n"; $issue->addComment("Overdue!!\n\nNext: ".$next_exc->format('Y-m-d')); } }else{ $issue->setDueDate($next_exc); } }