#!/usr/bin/php VcsUrl); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, Enums\HttpMethod::Head->value); // Only perform HTTP HEAD. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_exec($curl); $finalUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); // Were we redirected? if($finalUrl != $project->VcsUrl){ $project->VcsUrl = $finalUrl; $project->Save(); } // Now check the actual commits. $url = preg_replace('|^https://github.com/|iu', 'https://api.github.com/repos/', $project->VcsUrl . '/commits'); $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); try{ $response = curl_exec($curl); /** @var int $httpCode */ $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if(!is_string($response)){ throw new Exception('Response from GitHub was not a string: ' . $response); } if($httpCode != Enums\HttpCode::Ok->value){ throw new Exception('HTTP code from GitHub was: ' . $httpCode); } /** @var array $commits */ $commits = json_decode($response); if(sizeof($commits) > 0){ $project->LastCommitTimestamp = new DateTimeImmutable($commits[0]->commit->committer->date); } if($project->LastCommitTimestamp !== null && $project->LastCommitTimestamp < new DateTimeImmutable('30 days ago')){ $project->Status = Enums\ProjectStatusType::Stalled; } else{ // Revive previously-stalled `Project`s. $project->Status = Enums\ProjectStatusType::InProgress; } $project->Save(); } catch(Exception $ex){ Log::WriteErrorLogEntry('Error in update-project-commits for URL <' . $url . '>: ' . $ex->getMessage()); } sleep(1); }