&1; echo $?')); if($lastCommitSha1 === null){ Logger::WriteGithubWebhookLogEntry($requestId, 'Error getting last local commit. Output: ' . $lastCommitSha1); throw new WebhookException('Couldn\'t process ebook.', $post); } else{ if($data['after'] == $lastCommitSha1){ // This commit is already in our local repo, so silent success Logger::WriteGithubWebhookLogEntry($requestId, 'Local repo already in sync, no action taken.'); throw new NoopException(); } } // Now that we have the ebook filesystem path, pull the latest commit from GitHub. exec('/standardebooks.org/scripts/pull-from-github ' . escapeshellarg($dir), $output, $returnCode); if($returnCode != 0){ Logger::WriteGithubWebhookLogEntry($requestId, 'Error pulling from GitHub. Output: ' . implode("\n", $output)); throw new WebhookException('Couldn\'t process ebook.', $post); } else{ Logger::WriteGithubWebhookLogEntry($requestId, 'git pull from GitHub complete.'); } break; default: throw new WebhookException('Unrecognized GitHub webhook event.', $post); break; } // "Success, no content" http_response_code(204); } catch(WebhookException $ex){ // Uh oh, something went wrong! // Log detailed error and debugging information locally. Logger::WriteGithubWebhookLogEntry($requestId, 'Webhook failed! Error: ' . $ex->getMessage()); Logger::WriteGithubWebhookLogEntry($requestId, 'Webhook POST data: ' . $ex->PostData); // Print less details to the client. print($ex->getMessage()); // "Client error" http_response_code(400); } catch(NoopException $ex){ // We arrive here because a special case required us to take no action for the request, but execution also had to be interrupted. // For example, we received a request for a known repo for which we must ignore requests. // "Success, no content" http_response_code(204); } ?>