Update GitHub webhook to work for ebooks whose repo names are so long that they have to be truncated in GitHub.

This commit is contained in:
Alex Cabal 2019-10-23 16:00:09 -05:00
parent 0a565c3e00
commit e44a6bffa2

View file

@ -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 . '".');