#!/usr/bin/php 30 dyas then add "stale" label */ // 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'; //get the stale label or create if not exist if (!$staleLabel = $repo->getLabelByName('stale')) { $staleLabel = $repo->createLabel(['name' => 'stale', 'color' => '#fad8c7']); } //define the function to process each issue $callback = function($issue) use ($staleLabel) { $updatedTime=strtotime($issue->updated_at); $updateDaysAgo=(time()-$updatedTime)/60/60/24; echo "#{$issue->number} - $updateDaysAgo days ago - {$issue->title}\n"; if($issue->hasLabel($staleLabel)){ //when was it added? $staleTime=null; foreach($issue->getComments() as $comment){ if(substr($comment->body,0,35)=='This issue has been marked as stale'){ $staleTime=strtotime($comment->created_at); $staleDaysAgo=(time()-$staleTime)/60/60/24; } } if(!$staleTime){ echo "ERROR: cant find stale time\n"; return; } //if activity sice added then remove label if($updatedTime>$staleTime){ $issue->removeLabel($staleLabel); return; } //if no activity in 7 days then close if($updateDaysAgo>7) { $issue->state = 'closed'; $issue->save(); $issue->addComment('This issue has been automatically closed due to inactivity.'); return; } }elseif($updateDaysAgo>30){ //no stale label and >30 days $issue->addLabel($staleLabel); $issue->addComment('This issue has been marked as stale due to 30+ days of inactivity. If there is no futrher activity in the next 7 days it will be automatically closed.'); $issue->save(); return; } }; //loop through all issues and call the callback $repo->forIssues($callback);