diff --git a/tools/github_webhook_processor.php b/tools/WebhookProcessor/github_webhook_processor.php similarity index 93% rename from tools/github_webhook_processor.php rename to tools/WebhookProcessor/github_webhook_processor.php index a915c76ad2..6d62309f03 100644 --- a/tools/github_webhook_processor.php +++ b/tools/WebhookProcessor/github_webhook_processor.php @@ -17,20 +17,11 @@ //CONFIG START (all defaults are random examples, do change them) //Use single quotes for config options that are strings. - -//Github lets you have it sign the message with a secret that you can validate. This prevents people from faking events. -//This var should match the secret you configured for this webhook on github. -//This is required as otherwise somebody could trick the script into leaking the api key. + +//These are all default settings that are described in secret.php $hookSecret = '08ajh0qj93209qj90jfq932j32r'; - -$trackPRBalance = true; //set this to false to disable PR balance tracking -$prBalanceJson = ''; //Set this to the path you'd like the writable pr balance file to be stored, not setting it writes it to the working directory -$startingPRBalance = 3; //Starting balance for never before seen users -//team 133041: tgstation/commit-access -$maintainer_team_id = 133041; //org team id that is exempt from PR balance system, setting this to null will use anyone with write access to the repo. Get from https://api.github.com/orgs/:org/teams - -//Api key for pushing changelogs. $apiKey = '209ab8d879c0f987d06a09b9d879c0f987d06a09b9d8787d0a089c'; +<<<<<<< HEAD:tools/github_webhook_processor.php //servers to announce PRs to. $servers = array(); @@ -44,6 +35,22 @@ $servers[1]['address'] = 'game.tgstation13.org'; $servers[1]['port'] = '2337'; $servers[1]['comskey'] = '89aj90cq2fm0amc90832mn9rm90'; */ +======= +$repoOwnerAndName = "tgstation/tgstation"; +$servers = array(); +$enable_live_tracking = true; +$path_to_script = 'tools/WebhookProcessor/github_webhook_processor.php'; +$tracked_branch = "master"; +$trackPRBalance = true; +$prBalanceJson = ''; +$startingPRBalance = 3; +$maintainer_team_id = 133041; +$validation = "org"; +$validation_count = 1; +$tracked_branch = 'master'; + +require_once 'secret.php'; +>>>>>>> 07c1c4a... Gives the webhook processor the ability to self update (#30448):tools/WebhookProcessor/github_webhook_processor.php //CONFIG END set_error_handler(function($severity, $message, $file, $line) { @@ -221,6 +228,7 @@ function handle_pr($payload) { } else { $action = 'merged'; + auto_update($payload); checkchangelog($payload, true, true); update_pr_balance($payload); $validated = TRUE; //pr merged events always get announced. @@ -349,6 +357,23 @@ function update_pr_balance($payload) { fclose($balances_file); } +function auto_update($payload){ + global $enable_live_tracking; + global $path_to_script; + global $repoOwnerAndName; + global $tracked_branch; + if(!$enable_live_tracking || !has_tree_been_edited($payload, $path_to_script) || $payload['pull_request']['base']['ref'] != $tracked_branch) + return; + + $content = file_get_contents('https://raw.githubusercontent.com/' . $repoOwnerAndName . '/' . $tracked_branch . '/'. $path_to_script); + + create_comment($payload, "Edit detected. Self updating... Here is my new code:\n``" . "`HTML+PHP\n" . $content . "\n``" . '`'); + + $code_file = fopen(basename($path_to_script), 'w'); + fwrite($code_file, $content); + fclose($code_file); +} + function has_tree_been_edited($payload, $tree){ //go to the diff url $url = $payload['pull_request']['diff_url']; diff --git a/tools/WebhookProcessor/secret.php b/tools/WebhookProcessor/secret.php new file mode 100644 index 0000000000..abea10564f --- /dev/null +++ b/tools/WebhookProcessor/secret.php @@ -0,0 +1,49 @@ +