<commit_before><?php

// This script is allowed to run for up to 10 minutes.
set_time_limit(600);

require __DIR__ . '/vendor/autoload.php';
require_once 'config.php';
require_once 'util.php';

$payload = payload();

switch ($_SERVER["HTTP_X_GITHUB_EVENT"]) {
    case "ping":
        echo "Hello GitHub!";
        break;
    case "status":
        $repo = $payload["repository"]["name"];
        $branch = $payload["branches"][0]["name"];
        if (isset($repositories[$repo]["status"][$branch])) {
            // Verify commit status is good
            $token = token();
            $status = get_commit_status();
            if ($status !== "success") {
                echo "Current commit status of ".$payload["sha"]." is ".$status." - not deploying";
                exit;
            }
            echo "Requesting deployment of ".$branch." to ".$repositories[$repo]["status"][$branch]."\n";
            trigger_deployment($payload["sha"], $repositories[$repo]["status"][$branch]);
        } else {
            echo "No applicable configuration found.\n\n";
            echo "Repository: ".$repo."\n";
            echo "Event:      ".$_SERVER["HTTP_X_GITHUB_EVENT"]."\n";
            echo "Branch:     ".$branch;
        }
        break;
    case "push":
        $repo = $payload["repository"]["name"];
        $branch = substr($payload["ref"], 11);
        if (isset($repositories[$repo]["push"][$branch])) {
            echo "Requesting deployment of ".$branch." to ".$repositories[$repo]["push"][$branch]."\n";
            $token = token();
            trigger_deployment($payload["ref"], $repositories[$repo]["push"][$branch]);
        } else {
            echo "No applicable configuration found.\n\n";
            echo "Repository: ".$repo."\n";
            echo "Event:      ".$_SERVER["HTTP_X_GITHUB_EVENT"]."\n";
            echo "Branch:     ".$branch;
        }
        break;
    case "deployment":
        if ($payload["deployment"]["environment"] === "github-pages") {
            echo "Not deploying GitHub Pages build.";
            exit;
        }
        $token = token();

        $this_instance = $payload["repository"]["name"]."/".$payload["deployment"]["environment"];
        $directory = '/var/www/'.$this_instance;

        $return_value = 0;

        $error = false;

        $log_location = __DIR__."/".$this_instance."/".$payload["deployment"]["sha"]."/".$payload["deployment"]["id"];

        mkdir($log_location, 0700, true);
<commit_msg>Add acknowledgement and log link in webhook response<commit_after><?php

// This script is allowed to run for up to 10 minutes.
set_time_limit(600);

require __DIR__ . '/vendor/autoload.php';
require_once 'config.php';
require_once 'util.php';

$payload = payload();

switch ($_SERVER["HTTP_X_GITHUB_EVENT"]) {
    case "ping":
        echo "Hello GitHub!";
        break;
    case "status":
        $repo = $payload["repository"]["name"];
        $branch = $payload["branches"][0]["name"];
        if (isset($repositories[$repo]["status"][$branch])) {
            // Verify commit status is good
            $token = token();
            $status = get_commit_status();
            if ($status !== "success") {
                echo "Current commit status of ".$payload["sha"]." is ".$status." - not deploying";
                exit;
            }
            echo "Requesting deployment of ".$branch." to ".$repositories[$repo]["status"][$branch]."\n";
            trigger_deployment($payload["sha"], $repositories[$repo]["status"][$branch]);
        } else {
            echo "No applicable configuration found.\n\n";
            echo "Repository: ".$repo."\n";
            echo "Event:      ".$_SERVER["HTTP_X_GITHUB_EVENT"]."\n";
            echo "Branch:     ".$branch;
        }
        break;
    case "push":
        $repo = $payload["repository"]["name"];
        $branch = substr($payload["ref"], 11);
        if (isset($repositories[$repo]["push"][$branch])) {
            echo "Requesting deployment of ".$branch." to ".$repositories[$repo]["push"][$branch]."\n";
            $token = token();
            trigger_deployment($payload["ref"], $repositories[$repo]["push"][$branch]);
        } else {
            echo "No applicable configuration found.\n\n";
            echo "Repository: ".$repo."\n";
            echo "Event:      ".$_SERVER["HTTP_X_GITHUB_EVENT"]."\n";
            echo "Branch:     ".$branch;
        }
        break;
    case "deployment":
        if ($payload["deployment"]["environment"] === "github-pages") {
            echo "Not deploying GitHub Pages build.";
            exit;
        } else {
            echo "Starting deployment to ".$payload["deployment"]["environment"]." - watch logs at "."https://".$_SERVER["SERVER_NAME"]."/".$payload["repository"]["name"]."/".$payload["deployment"]["environment"]."/".$payload["deployment"]["sha"]."/".$payload["deployment"]["id"];
        }
        $token = token();

        $this_instance = $payload["repository"]["name"]."/".$payload["deployment"]["environment"];
        $directory = '/var/www/'.$this_instance;

        $return_value = 0;

        $error = false;

        $log_location = __DIR__."/".$this_instance."/".$payload["deployment"]["sha"]."/".$payload["deployment"]["id"];

        mkdir($log_location, 0700, true);

{'fraction_non_alphanumeric': 0.19214056300774607, 'fraction_numerical': 0.0049121481201587006, 'mean_word_length': 2.415483870967742, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3971847', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1541, 'n_words': 315}