remove the untested/unfinished "repeat" scripts
This commit is contained in:
parent
5349642752
commit
dd704e858c
14
README.md
14
README.md
@ -20,20 +20,6 @@ All examples include [src/setup.php](https://git.jhodges.co.uk/jhodges/GiteaBot-
|
||||
*************************************************/
|
||||
```
|
||||
----
|
||||
###[src/repeat.php](https://git.jhodges.co.uk/jhodges/GiteaBot-examples/src/branch/master/src/repeat.php)
|
||||
|
||||
```plain
|
||||
/***********************************************************************
|
||||
* This is designed to allow the use of labels to reopen recuring issues
|
||||
* on a specific day, month or duration (daily/weekly/monthly etc)
|
||||
* NOTE: This is not 100% implemented/tested. It's a WIP
|
||||
* It will process any issue that is tagged with 'xxx/repeat' label
|
||||
* The labels are grouped into days/months
|
||||
* If an issue is closed then it will be reopened
|
||||
* If an issue is already open the bot will comment "NAG!" about it
|
||||
***********************************************************************/
|
||||
```
|
||||
----
|
||||
###[src/edit.php](https://git.jhodges.co.uk/jhodges/GiteaBot-examples/src/branch/master/src/edit.php)
|
||||
|
||||
```plain
|
||||
|
129
src/repeat.php
129
src/repeat.php
@ -1,129 +0,0 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
/***********************************************************************
|
||||
* This is designed to allow the use of labels to reopen recuring issues
|
||||
* on a specific day, month or duration (daily/weekly/monthly etc)
|
||||
* NOTE: This is not 100% implemented/tested. It's a WIP
|
||||
* It will process any issue that is tagged with 'xxx/repeat' label
|
||||
* The labels are grouped into days/months
|
||||
* If an issue is closed then it will be reopened
|
||||
* If an issue is already open the bot will comment "NAG!" about it
|
||||
***********************************************************************/
|
||||
|
||||
// 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');
|
||||
|
||||
//define the repeat terms
|
||||
$terms=[
|
||||
'months'=>['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']);
|
Loading…
Reference in New Issue
Block a user