Tweak a session variable name and update comments

This commit is contained in:
Alex Cabal 2024-11-20 16:38:47 -06:00
parent 3050ab7219
commit 11d9d0f44a
12 changed files with 25 additions and 37 deletions

View file

@ -6,8 +6,7 @@ use function Safe\glob;
use function Safe\shell_exec;
// This script makes various calls to external scripts using exec() (and when called via Apache, as the www-data user).
// These scripts are allowed using the /etc/sudoers.d/www-data file. Only the specific scripts
// in that file may be executed by this script.
// These scripts are allowed using the /etc/sudoers.d/www-data file. Only the specific scripts in that file may be executed by this script.
try{
$log = new Log(GITHUB_WEBHOOK_LOG_FILE_PATH);
$lastPushHashFlag = '';
@ -87,13 +86,13 @@ try{
}
else{
if($data['after'] == $lastCommitSha1){
// This commit is already in our local repo, so silent success
// This commit is already in our local repo, so silent success.
$log->Write('Local repo already in sync, no action taken.');
throw new Exceptions\NoopException();
}
}
// Get the current HEAD hash and save for later
// Get the current HEAD hash and save for later.
$output = [];
exec('sudo --set-home --user se-vcs-bot git -C ' . escapeshellarg($dir) . ' rev-parse HEAD', $output, $returnCode);
if($returnCode != 0){
@ -130,11 +129,9 @@ try{
throw new Exceptions\WebhookException('Unrecognized GitHub webhook event.', $post);
}
// "Success, no content"
http_response_code(Enums\HttpCode::NoContent->value);
}
catch(Exceptions\InvalidCredentialsException){
// "Forbidden"
http_response_code(Enums\HttpCode::Forbidden->value);
}
catch(Exceptions\WebhookException $ex){
@ -146,14 +143,12 @@ catch(Exceptions\WebhookException $ex){
// Print less details to the client.
print($ex->getMessage());
// "Client error"
http_response_code(Enums\HttpCode::BadRequest->value);
}
catch(Exceptions\NoopException){
// 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(Enums\HttpCode::NoContent->value);
}
?>