[MIRROR] Limit repository announcements to a whitelist, Discord announces to a blacklist [MDB IGNORE] (#9791)

* Limit repository announcements to a whitelist, Discord announces to a blacklist (#63179)

About The Pull Request

Limits the game announcers only to arrays in a fixed whitelist.

Discord announcements, as they're more for those interested in the technical side, are on a blacklist of patterns. This is set to blacklist anything starting with event-*.

This stops a lot of internal repos from clogging chat, but more importantly is going to be used as events will now be hosted on the tgstation organization, and we want to limit spoilers/confusion on that for people who don't go looking for it.

* Limit repository announcements to a whitelist, Discord announces to a blacklist

* Update tools/WebhookProcessor/github_webhook_processor.php

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>
This commit is contained in:
SkyratBot
2021-12-01 03:42:29 +01:00
committed by GitHub
parent 654a18f9d5
commit 20bdfe4f97

View File

@@ -40,6 +40,17 @@ $tracked_branch = 'master';
$require_changelogs = false;
$discordWebHooks = array();
// Only these repositories will announce in game.
// Any repository that players actually care about.
$game_announce_whitelist = array(
"Skyrat-tg",
);
// Any repository that matches in this blacklist will not appear on Discord.
$discord_announce_blacklist = array(
"/^event-.*$/",
);
require_once 'secret.php';
//CONFIG END
@@ -310,6 +321,16 @@ function check_dismiss_changelog_review($payload){
dismiss_review($payload, $R['id'], 'Changelog added/fixed.');
}
function is_blacklisted($blacklist, $name) {
foreach ($blacklist as $pattern) {
if (preg_match($pattern, $name)) {
return true;
}
}
return false;
}
function handle_pr($payload) {
global $no_changelog;
$action = 'opened';
@@ -352,9 +373,16 @@ function handle_pr($payload) {
if (!$validated) {
$pr_flags |= F_UNVALIDATED_USER;
}
discord_announce($action, $payload, $pr_flags);
game_announce($action, $payload, $pr_flags);
$repo_name = $payload['repository']['name'];
if (in_array($repo_name, $game_announce_whitelist)) {
game_announce($action, $payload, $pr_flags);
}
if (!is_blacklisted($discord_announce_blacklist, $repo_name)) {
discord_announce($action, $payload, $pr_flags);
}
}
function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {