<commit_before><?php
header("Content-Type: none");

// get secret and set config
$secret = "";
$force_download = false;
include_once("gh-webhook-config.php");
$json = file_get_contents('php://input');
$headers = getallheaders();

// verify requester
if (!isset($headers['X-Hub-Signature'])) {
    echo "You need to prove to me that you're GitHub!"; die;
} elseif ("sha1=".hash_hmac("sha1", $json, $secret) !== $headers['X-Hub-Signature']) {
    echo "You're not GitHub!"; die;
}

$result = "verified! :D\n";

// turn into array
$push = json_decode($json, true);

// check for version or changelog change, and update if necessary
$downloaded = false;
foreach ($push["commits"] as $commit) {
    foreach ($commit["modified"] as $filename) {
        if ($filename == "source/version.h" or $force_download) {
            unlink("launcher.zip");
            file_put_contents("version.h", "notready"); // "notready" = 3DS will wait for server to cache
            $versionh = trim(file_get_contents("https://raw.githubusercontent.com/mashers/3ds_hb_menu/master/source/version.h"));
            file_put_contents("version.h", $versionh);
            $launcherzip = file_get_contents("https://raw.githubusercontent.com/mashers/3ds_hb_menu/master/launcher.zip");
            $result .= " > saved version.h and launcher.zip\n";
            $downloaded = true;
        }
        if ($filename == "Updating/Updating-Changelog.md" or $force_download) {
            unlink("Updating-Changelog.md");
            $changelog_release = file_get_contents("https://raw.githubusercontent.com/RedInquisitive/3DS-Homebrew-Menu-Wiki/master/Updating/Updating-Changelog.md");
            file_put_contents("Updating-Changelog.md", $changelog_release);
            $result .= " > saved Updating-Changelog.md\n";
            $downloaded = true;
        }
        if ($filename == "Updating/Updating-Changelog-Beta.md" or $force_download) {
            unlink("Updating-Changelog-Beta.md");
            $changelog_beta = file_get_contents("https://raw.githubusercontent.com/RedInquisitive/3DS-Homebrew-Menu-Wiki/master/Updating/Updating-Changelog-Beta.md");
            file_put_contents("Updating-Changelog-Beta.md", $changelog_beta);
            $result .= " > saved Updating-Changelog-Beta.md\n";
            $downloaded = true;
        }
        if ($downloaded) {
            break;
        }
    }
}

// return result for GitHub
$result .= " - list changed files:\n";
foreach ($push["commits"] as $commit) {
    foreach ($commit["modified"] as $filename) {
        $result .= "   - ".$filename."\n";
    }
}
$result .= "-----\n".print_r($headers, true)."-----\n".print_r($push, true);
echo $result;

// temporary local logging
file_put_contents("gh-webhook-logtest/webhooktest_".time().".txt", $result);
<commit_msg>actually save launcher.zip<commit_after><?php
header("Content-Type: none");

// get secret and set config
$secret = "";
$force_download = false;
include_once("gh-webhook-config.php");
$json = file_get_contents('php://input');
$headers = getallheaders();

// verify requester
if (!isset($headers['X-Hub-Signature'])) {
    echo "You need to prove to me that you're GitHub!"; die;
} elseif ("sha1=".hash_hmac("sha1", $json, $secret) !== $headers['X-Hub-Signature']) {
    echo "You're not GitHub!"; die;
}

$result = "verified! :D\n";

// turn into array
$push = json_decode($json, true);

// check for version or changelog change, and update if necessary
$downloaded = false;
foreach ($push["commits"] as $commit) {
    foreach ($commit["modified"] as $filename) {
        if ($filename == "source/version.h" or $force_download) {
            unlink("launcher.zip");
            file_put_contents("version.h", "notready"); // "notready" = 3DS will wait for server to cache
            $versionh = trim(file_get_contents("https://raw.githubusercontent.com/mashers/3ds_hb_menu/master/source/version.h"));
            file_put_contents("version.h", $versionh);
            $launcherzip = file_get_contents("https://raw.githubusercontent.com/mashers/3ds_hb_menu/master/launcher.zip");
            file_put_contents("launcher.zip", $launcherzip);
            $result .= " > saved version.h and launcher.zip\n";
            $downloaded = true;
        }
        if ($filename == "Updating/Updating-Changelog.md" or $force_download) {
            unlink("Updating-Changelog.md");
            $changelog_release = file_get_contents("https://raw.githubusercontent.com/RedInquisitive/3DS-Homebrew-Menu-Wiki/master/Updating/Updating-Changelog.md");
            file_put_contents("Updating-Changelog.md", $changelog_release);
            $result .= " > saved Updating-Changelog.md\n";
            $downloaded = true;
        }
        if ($filename == "Updating/Updating-Changelog-Beta.md" or $force_download) {
            unlink("Updating-Changelog-Beta.md");
            $changelog_beta = file_get_contents("https://raw.githubusercontent.com/RedInquisitive/3DS-Homebrew-Menu-Wiki/master/Updating/Updating-Changelog-Beta.md");
            file_put_contents("Updating-Changelog-Beta.md", $changelog_beta);
            $result .= " > saved Updating-Changelog-Beta.md\n";
            $downloaded = true;
        }
        if ($downloaded) {
            break;
        }
    }
}

// return result for GitHub
$result .= " - list changed files:\n";
foreach ($push["commits"] as $commit) {
    foreach ($commit["modified"] as $filename) {
        $result .= "   - ".$filename."\n";
    }
}
$result .= "-----\n".print_r($headers, true)."-----\n".print_r($push, true);
echo $result;

// temporary local logging
file_put_contents("gh-webhook-logtest/webhooktest_".time().".txt", $result);

{'fraction_non_alphanumeric': 0.1665489226421759, 'fraction_numerical': 0.002472624514305899, 'mean_word_length': 3.0829127613554435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6676203', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1819, 'n_words': 326}