diff --git a/tools/WebhookProcessor/github_webhook_processor.php b/tools/WebhookProcessor/github_webhook_processor.php
index 37805aae7a..20d5631b73 100644
--- a/tools/WebhookProcessor/github_webhook_processor.php
+++ b/tools/WebhookProcessor/github_webhook_processor.php
@@ -519,32 +519,46 @@ 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);
-}
-
$github_diff = null;
-function has_tree_been_edited($payload, $tree){
+function get_diff($payload) {
global $github_diff;
if ($github_diff === null) {
//go to the diff url
$url = $payload['pull_request']['diff_url'];
$github_diff = file_get_contents($url);
}
+ return $github_diff;
+}
+
+function auto_update($payload){
+ global $enable_live_tracking;
+ global $path_to_script;
+ global $repoOwnerAndName;
+ global $tracked_branch;
+ global $github_diff;
+ if(!$enable_live_tracking || !has_tree_been_edited($payload, $path_to_script) || $payload['pull_request']['base']['ref'] != $tracked_branch)
+ return;
+
+ get_diff($payload);
+ $content = file_get_contents('https://raw.githubusercontent.com/' . $repoOwnerAndName . '/' . $tracked_branch . '/'. $path_to_script);
+ $content_diff = "### Diff not available. :slightly_frowning_face:";
+ if($github_diff && preg_match('/(diff --git a\/' . preg_quote($path_to_script, '/') . '.+?)(?:^diff)?/sm', $github_diff, $matches)) {
+ $script_diff = matches[1];
+ if($script_diff) {
+ $content_diff = "``" . "`DIFF\n" . $script_diff ."\n``" . "`";
+ }
+ }
+ create_comment($payload, "Edit detected. Self updating... \nHere are my changes:
\n\n" . $content_diff . "\n \nHere is my new code:
\n\n``" . "`HTML+PHP\n" . $content . "\n``" . '`\n ');
+
+ $code_file = fopen(basename($path_to_script), 'w');
+ fwrite($code_file, $content);
+ fclose($code_file);
+}
+
+function has_tree_been_edited($payload, $tree){
+ global $github_diff;
+ get_diff($payload);
//find things in the _maps/map_files tree
//e.g. diff --git a/_maps/map_files/Cerestation/cerestation.dmm b/_maps/map_files/Cerestation/cerestation.dmm
return $github_diff !== FALSE && preg_match('/^diff --git a\/' . preg_quote($tree, '/') . '/m') !== FALSE;