diff --git a/www/webhooks/github.php b/www/webhooks/github.php index fda9b0c8..bf2f1caf 100644 --- a/www/webhooks/github.php +++ b/www/webhooks/github.php @@ -5,6 +5,7 @@ use function Safe\substr; use function Safe\file_get_contents; use function Safe\preg_replace; use function Safe\json_decode; +use function Safe\glob; // Get a semi-random ID to identify this request within the log. $requestId = substr(sha1(time() . rand()), 0, 8); @@ -61,8 +62,16 @@ try{ $dir = REPOS_PATH . '/' . $repoName . '.git/'; // Confirm we're looking at a Git repo in our filesystem - if(!file_exists($dir . "HEAD")){ - throw new WebhookException('Couldn\'t find repo "' . $repoName . '" in filesystem at "' . $dir . '".', $post); + if(!file_exists($dir . 'HEAD')){ + // We might be looking for a repo whose name is so long, it was truncated for GitHub. Try to check that here by simply globbing the rest. + $dirs = glob(REPOS_PATH . '/' . $repoName . '*'); + if(sizeof($dirs) == 1){ + $dir = rtrim($dirs[0], '/') . '/'; + } + + if(!file_exists($dir . 'HEAD')){ + throw new WebhookException('Couldn\'t find repo "' . $repoName . '" in filesystem at "' . $dir . '".', $post); + } } Logger::WriteGithubWebhookLogEntry($requestId, 'Processing ebook "' . $repoName . '" located at "' . $dir . '".');