[MIRROR] Fix github not announcing new prs [MDB IGNORE] (#17216)

* Fix github not announcing new prs

* Resets github_webhook_processor.php to upstream version, with our minor modification

* Adds the whole pull_request_hooks folder that we also missed from upstream

Co-authored-by: Kyle Spier-Swenson <kyleshome@gmail.com>
Co-authored-by: GoldenAlpharex <jerego1234@hotmail.com>
This commit is contained in:
SkyratBot
2022-11-09 18:47:14 +01:00
committed by GitHub
parent 15b114579e
commit 470ea238cb
7 changed files with 362 additions and 70 deletions

View File

@@ -43,6 +43,10 @@ $discordWebHooks = array();
// Only these repositories will announce in game.
// Any repository that players actually care about.
$game_announce_whitelist = array(
/* SKYRAT EDIT - We want it to announce to us - ORIGINAL:
"tgstation",
"TerraGov-Marine-Corps",
// ORIGINAL END - SKYRAT EDIT: */
"Skyrat-tg",
);
@@ -239,7 +243,7 @@ function tag_pr($payload, $opened) {
$tags = array();
$title = $payload['pull_request']['title'];
if($opened) { //you only have one shot on these ones so as to not annoy maintainers
$tags = checkchangelog($payload, false);
$tags = checkchangelog($payload);
if(strpos(strtolower($title), 'refactor') !== FALSE)
$tags[] = 'Refactor';
@@ -271,8 +275,6 @@ function tag_pr($payload, $opened) {
check_tag_and_replace($payload, '[dnm]', 'Do Not Merge', $tags);
check_tag_and_replace($payload, '[no gbp]', 'GBP: No Update', $tags);
check_tag_and_replace($payload, '[host]', 'Host Request', $tags);
return array($tags, $remove);
}
@@ -303,7 +305,7 @@ function check_dismiss_changelog_review($payload){
return;
if(!$no_changelog)
checkchangelog($payload, false);
checkchangelog($payload);
$review_message = 'Your changelog for this PR is either malformed or non-existent. Please create one to document your changes.';
@@ -363,7 +365,7 @@ function handle_pr($payload) {
else {
$action = 'merged';
auto_update($payload);
checkchangelog($payload, true);
checkchangelog($payload);
$validated = TRUE; //pr merged events always get announced.
}
break;
@@ -631,7 +633,7 @@ function has_tree_been_edited($payload, $tree){
}
$no_changelog = false;
function checkchangelog($payload, $compile = true) {
function checkchangelog($payload) {
global $no_changelog;
if (!isset($payload['pull_request']) || !isset($payload['pull_request']['body'])) {
return;
@@ -649,26 +651,16 @@ function checkchangelog($payload, $compile = true) {
$body = str_replace("\r\n", "\n", $body);
$body = explode("\n", $body);
$username = $payload['pull_request']['user']['login'];
$incltag = false;
$changelogbody = array();
$currentchangelogblock = array();
$foundcltag = false;
foreach ($body as $line) {
$line = trim($line);
if (substr($line,0,4) == ':cl:' || substr($line,0,1) == '??') {
$incltag = true;
$foundcltag = true;
$pos = strpos($line, " ");
if ($pos) {
$tmp = substr($line, $pos+1);
if (trim($tmp) != 'optional name here')
$username = $tmp;
}
continue;
} else if (substr($line,0,5) == '/:cl:' || substr($line,0,6) == '/ :cl:' || substr($line,0,5) == ':/cl:' || substr($line,0,5) == '/??' || substr($line,0,6) == '/ ??' ) {
$incltag = false;
$changelogbody = array_merge($changelogbody, $currentchangelogblock);
continue;
}
if (!$incltag)
@@ -684,47 +676,44 @@ function checkchangelog($payload, $compile = true) {
$firstword = $line;
}
// Line is empty
if (!strlen($firstword)) {
if (count($currentchangelogblock) <= 0)
continue;
$currentchangelogblock[count($currentchangelogblock)-1]['body'] .= "\n";
continue;
}
//not a prefix line.
//so we add it to the last changelog entry as a separate line
if (!strlen($firstword) || $firstword[strlen($firstword)-1] != ':') {
if (count($currentchangelogblock) <= 0)
continue;
$currentchangelogblock[count($currentchangelogblock)-1]['body'] .= "\n".$line;
continue;
}
$cltype = strtolower(substr($firstword, 0, -1));
// !!!
// !!! If you are changing any of these at the bottom, also edit `tools/pull_request_hooks/changelogConfig.js`.
// !!!
switch ($cltype) {
case 'fix':
case 'fixes':
case 'bugfix':
if($item != 'fixed a few things') {
$tags[] = 'Fix';
$currentchangelogblock[] = array('type' => 'bugfix', 'body' => $item);
}
break;
case 'qol':
if($item != 'made something easier to use') {
$tags[] = 'Quality of Life';
$currentchangelogblock[] = array('type' => 'qol', 'body' => $item);
}
break;
case 'soundadd':
if($item != 'added a new sound thingy') {
$tags[] = 'Sound';
$currentchangelogblock[] = array('type' => 'soundadd', 'body' => $item);
}
break;
case 'sounddel':
if($item != 'removed an old sound thingy') {
$tags[] = 'Sound';
$tags[] = 'Removal';
$currentchangelogblock[] = array('type' => 'sounddel', 'body' => $item);
}
break;
case 'add':
@@ -732,7 +721,6 @@ function checkchangelog($payload, $compile = true) {
case 'rscadd':
if($item != 'Added new mechanics or gameplay changes' && $item != 'Added more things') {
$tags[] = 'Feature';
$currentchangelogblock[] = array('type' => 'rscadd', 'body' => $item);
}
break;
case 'del':
@@ -740,95 +728,54 @@ function checkchangelog($payload, $compile = true) {
case 'rscdel':
if($item != 'Removed old things') {
$tags[] = 'Removal';
$currentchangelogblock[] = array('type' => 'rscdel', 'body' => $item);
}
break;
case 'imageadd':
if($item != 'added some icons and images') {
$tags[] = 'Sprites';
$currentchangelogblock[] = array('type' => 'imageadd', 'body' => $item);
}
break;
case 'imagedel':
if($item != 'deleted some icons and images') {
$tags[] = 'Sprites';
$tags[] = 'Removal';
$currentchangelogblock[] = array('type' => 'imagedel', 'body' => $item);
}
break;
case 'typo':
case 'spellcheck':
if($item != 'fixed a few typos') {
$tags[] = 'Grammar and Formatting';
$currentchangelogblock[] = array('type' => 'spellcheck', 'body' => $item);
}
break;
case 'balance':
if($item != 'rebalanced something'){
$tags[] = 'Balance';
$currentchangelogblock[] = array('type' => 'balance', 'body' => $item);
}
break;
case 'code_imp':
case 'code':
if($item != 'changed some code'){
$tags[] = 'Code Improvement';
$currentchangelogblock[] = array('type' => 'code_imp', 'body' => $item);
}
break;
case 'refactor':
if($item != 'refactored some code'){
$tags[] = 'Refactor';
$currentchangelogblock[] = array('type' => 'refactor', 'body' => $item);
}
break;
case 'config':
if($item != 'changed some config setting'){
$tags[] = 'Config Update';
$currentchangelogblock[] = array('type' => 'config', 'body' => $item);
}
break;
case 'admin':
if($item != 'messed with admin stuff'){
$tags[] = 'Administration';
$currentchangelogblock[] = array('type' => 'admin', 'body' => $item);
}
break;
case 'server':
if($item != 'something server ops should know')
$currentchangelogblock[] = array('type' => 'server', 'body' => $item);
break;
default:
//we add it to the last changelog entry as a separate line
if (count($currentchangelogblock) > 0)
$currentchangelogblock[count($currentchangelogblock)-1]['body'] .= "\n".$line;
break;
}
}
if(!count($changelogbody))
$no_changelog = true;
if ($no_changelog || !$compile)
return $tags;
$file = 'author: "'.trim(str_replace(array("\\", '"'), array("\\\\", "\\\""), $username)).'"'."\n";
$file .= "delete-after: True\n";
$file .= "changes: \n";
foreach ($changelogbody as $changelogitem) {
$type = $changelogitem['type'];
$body = trim(str_replace(array("\\", '"'), array("\\\\", "\\\""), $changelogitem['body']));
$file .= ' - '.$type.': "'.$body.'"';
$file .= "\n";
}
$content = array (
'branch' => $payload['pull_request']['base']['ref'],
'message' => 'Automatic changelog generation for PR #'.$payload['pull_request']['number'].' [ci skip]',
'content' => base64_encode($file)
);
$filename = '/html/changelogs/AutoChangeLog-pr-'.$payload['pull_request']['number'].'.yml';
echo github_apisend($payload['pull_request']['base']['repo']['url'].'/contents'.$filename, 'PUT', $content);
return $tags;
}
function game_server_send($addr, $port, $str) {