switch lib and more dev

This commit is contained in:
James
2019-09-28 19:31:57 +01:00
parent 4bb6a486bf
commit d917a7c27c
8 changed files with 75 additions and 155 deletions

48
src/rrule.php Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/php
<?php
// 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 updateIssueBody($issue,$text){
// add a tag to the body if to doesn't exist
if( strpos($issue->body,'<!--BOT-->')===false ){
$issue->body.="\n<!--BOT--><hr/><!--ENDBOT-->";
}
//replace the tag contents with the result from our $text function
$issue->body=preg_replace("#<!--BOT-->.*?<!--ENDBOT-->#s",'<!--BOT--><hr/>'.$text.'<!--ENDBOT-->',$issue->body);
};
foreach($repo->getIssues(['q'=>'RRULE:']) as $issue){
//echo "GOT: {$issue->number}\n";
if(preg_match('/RRULE:\s?(.*)/',$issue->body,$matches)){
$rruletxt=$matches[1];
//echo "RRULEtxt: ".$rruletxt."\n";
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').")");
}
updateIssueBody($issue,$result);
// not working https://github.com/go-gitea/gitea/issues/8179
//$issue->due_date=$rrule[0]->format('c');
$issue->save();
}
}