diff --git a/src/convert.php b/src/convert.php new file mode 100755 index 0000000..68e3cff --- /dev/null +++ b/src/convert.php @@ -0,0 +1,55 @@ +#!/usr/bin/php +[1=>'janurary',2=>'feburary',3=>'march',4=>'april',5=>'may',6=>'june',7=>'july',8=>'august',9=>'september',10=>'october',11=>'november',12=>'december'], + 'days'=>['MO'=>'monday','TU'=>'tuesday','WE'=>'wednesday','TH'=>'thursday','FR'=>'friday','SA'=>'saturday','SU'=>'sunday'], + 'generic'=>['daily','weekly','fortnightly','monthly','yearly'] +]; + +$month=function($issue) use($terms){ + $t=getRepeatTerms($issue,$terms); + print_r($t); + $ms=[]; + foreach($t['months'] as $id=>$m){ + $ms[]=$id; + } + $ms=implode(',',$ms); + $rrule="RRULE: FREQ=MONTHLY;INTERVAL=1;BYMONTH=$ms;BYMONTHDAY=1"; + echo "\n\n$rrule\n\n"; + + $issue->body=preg_replace("#RRULE:.*#",'',$issue->body); + + $issue->body=$rrule."\n\n".$issue->body; + $issue->save(); +}; + +function getRepeatTerms($issue,$terms){ + $labels=[]; + $found=[]; + foreach($issue->labels as $label){ + $labels[]=$label->name; + } + print_r($labels); + foreach($terms as $name=>$values){ + foreach($values as $id=>$value){ + if( in_array("$value/repeat",$labels) ){ + $found[$name][$id]=$value; + } + } + } + return $found; +} + +foreach($terms['months'] as $value){ + $repo->forIssues($month,['labels'=>"$value/repeat"]); + $repo->forIssues($month,['state'=>'closed','labels'=>"$value/repeat"]); +} diff --git a/src/repeat.php b/src/repeat.php deleted file mode 100755 index a7de9d4..0000000 --- a/src/repeat.php +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/php -['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 $group=>$names){ - foreach($names as $name){ - $name="{$name}/repeat"; - $label=$repo->getLabelByName($name); - if(!$label){ - $label=$repo->createLabel([ - 'name'=>$name, - 'color'=>'#ffff00', - 'description'=>'Reopen this issue with the given frequency' - ]); - } - } -} - -//define the function to process each issue -$daily=function($issue){ - $day_today=date('U')/60/60/24; - $days_closed_ago=$issue->closed_at?$day_today-(date('U',strtotime($issue->closed_at))/60/60/24):null; - $days_updated_ago=$day_today-(date('U',strtotime($issue->updated_at))/60/60/24); - echo "Daily: ". $issue->title." C:".$issue->closed_at." ($days_closed_ago) U:".$issue->updated_at." ($days_updated_ago) \n"; - if($days_closed_ago>1){ - if($issue->state=="closed"){ - $issue->state='open'; - $issue->save(); - }else{ - if($days_updated_ago>1){ - $issue->addComment("NAG!"); - } - } - } -}; - -$weekly=function($issue){ - $day_today=date('U')/60/60/24; - $days_closed_ago=$issue->closed_at?$day_today-(date('U',strtotime($issue->closed_at))/60/60/24):null; - $days_updated_ago=$day_today-(date('U',strtotime($issue->updated_at))/60/60/24); - echo "Weekly: ". $issue->title." C:".$issue->closed_at." ($days_closed_ago) U:".$issue->updated_at." ($days_updated_ago) \n"; - if( $days_closed_ago>7 ){ - if($issue->state=="closed"){ - $issue->state='open'; - $issue->save(); - }else{ - if($days_updated_ago>3){ - $issue->addComment("NAG!"); - } - } - } -}; - -$monthly=function($issue) use ($terms){ - $day_today=date('U')/60/60/24; - $days_closed_ago=$issue->closed_at?$day_today-(date('U',strtotime($issue->closed_at))/60/60/24):null; - $days_updated_ago=$day_today-(date('U',strtotime($issue->updated_at))/60/60/24); - $month_closed=date('m/Y',strtotime($issue->closed_at)); - $month_today=date('m/Y'); - echo "Monthly: ". $issue->title." [MC: $month_closed, MT: $month_today] C:".$issue->closed_at." ($days_closed_ago) U:".$issue->updated_at." ($days_updated_ago) \n"; - //print_r($issue->labels); - //print_r(getRepeatTerms($issue,$terms)); - //die(); - if($month_closed!=$month_today){ - if($issue->state=="closed"){ - $issue->state='open'; - $issue->save(); - }else{ - if($days_updated_ago>7){ - $issue->addComment("NAG!"); - } - } - } -}; - -function getRepeatTerms($issue,$terms){ - $labels=[]; - $found=[]; - foreach($issue->labels as $label){ - $labels[]=$label->name; - } - print_r($labels); - foreach($terms as $name=>$values){ - foreach($values as $value){ - if( in_array("$value/repeat",$labels) ){ - $found[$name][]=$value; - } - } - } - return $found; -} - -//prep the curent day/month names -$day_name=strtolower(date('l')); -$month_name=strtolower(date('F')); - -// nag about open issues -$repo->forIssues($weekly,['labels'=>'weekly/repeat']); -$repo->forIssues($daily,['labels'=>'daily/repeat']); -$repo->forIssues($daily,['labels'=>$day_name.'/repeat']); -$repo->forIssues($monthly,['labels'=>'monthly/repeat']); -$repo->forIssues($monthly,['labels'=>$month_name.'/repeat']); - -// reopen closed issues -$repo->forIssues($weekly,['state'=>'closed','labels'=>'weekly/repeat']); -$repo->forIssues($daily,['state'=>'closed','labels'=>'daily/repeat']); -$repo->forIssues($daily,['state'=>'closed','labels'=>$day_name.'/repeat']); -$repo->forIssues($monthly,['state'=>'closed','labels'=>'monthly/repeat']); -$repo->forIssues($monthly,['state'=>'closed','labels'=>$month_name.'/repeat']); diff --git a/src/rrule.php b/src/rrule.php index 7d84742..b3c0bf6 100755 --- a/src/rrule.php +++ b/src/rrule.php @@ -1,13 +1,25 @@ #!/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
"; @@ -16,9 +28,15 @@ function updateIssueBody($issue,$text){ $issue->body=preg_replace("#.*?#s",'
'.$text.'',$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(). - "
\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'); - 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); + }*/ }