add keep functionality to stale bot

This commit is contained in:
James 2020-10-17 11:39:23 +01:00
parent 46bdc40819
commit ca9933f729

View File

@ -2,11 +2,12 @@
<?php <?php
/* /*
1. loop through all issues: 1. loop through all issues:
2. if issue has stale "label": 3. if issue has "keep" label then skip it
2.1. if activity since label was added then remove label 3. if issue has stale "label":
2.2. if still no activity in 7 days then close 3.1. if activity since label was added then remove label
3. if issue doesn not has stale "label" 3.2. if still no activity in 7 days then close
3.1. if no activity in >30 dyas then add "stale" label 4. if issue doesn not has stale "label"
4.1. if no activity in >30 dyas then add "stale" label
*/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
@ -17,13 +18,18 @@ require 'setup.php';
if (!$staleLabel = $repo->getLabelByName('stale')) { if (!$staleLabel = $repo->getLabelByName('stale')) {
$staleLabel = $repo->createLabel(['name' => 'stale', 'color' => '#fad8c7']); $staleLabel = $repo->createLabel(['name' => 'stale', 'color' => '#fad8c7']);
} }
if (!$keepLabel = $repo->getLabelByName('keep')) {
$keepLabel = $repo->createLabel(['name' => 'keep', 'color' => '#bfe5bf']);
}
//define the function to process each issue //define the function to process each issue
$callback = function($issue) use ($staleLabel) { $callback = function($issue) use ($staleLabel) {
$updatedTime=strtotime($issue->updated_at); $updatedTime=strtotime($issue->updated_at);
$updateDaysAgo=(time()-$updatedTime)/60/60/24; $updateDaysAgo=(time()-$updatedTime)/60/60/24;
echo "#{$issue->number} - $updateDaysAgo days ago - {$issue->title}\n"; echo "#{$issue->number} - $updateDaysAgo days ago - {$issue->title}\n";
if($issue->hasLabel($staleLabel)){ if($issue->hasLabel($keepLabel)){
return;
}elseif($issue->hasLabel($staleLabel)){
//when was it added? //when was it added?
$staleTime=null; $staleTime=null;
foreach($issue->getComments() as $comment){ foreach($issue->getComments() as $comment){