mirror of
https://github.com/SPLURT-Station/S.P.L.U.R.T-Station-13.git
synced 2025-12-10 09:54:52 +00:00
hello linter??
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
/**CREDITS:
|
||||
* GitHub webhook handler template.
|
||||
*
|
||||
*
|
||||
* @see https://developer.github.com/webhooks/
|
||||
* @author Miloslav Hula (https://github.com/milo)
|
||||
*/
|
||||
@@ -126,24 +126,24 @@ switch (strtolower($_SERVER['HTTP_X_GITHUB_EVENT'])) {
|
||||
function apisend($url, $method = 'GET', $content = null, $authorization = null) {
|
||||
if (is_array($content))
|
||||
$content = json_encode($content);
|
||||
|
||||
|
||||
$headers = array();
|
||||
$headers[] = 'Content-type: application/json';
|
||||
if ($authorization)
|
||||
$headers[] = 'Authorization: ' . $authorization;
|
||||
|
||||
|
||||
$scontext = array('http' => array(
|
||||
'method' => $method,
|
||||
'header' => implode("\r\n", $headers),
|
||||
'ignore_errors' => true,
|
||||
'user_agent' => 'tgstation13.org-Github-Automation-Tools'
|
||||
));
|
||||
|
||||
|
||||
if ($content)
|
||||
$scontext['http']['content'] = $content;
|
||||
|
||||
|
||||
return file_get_contents($url, false, stream_context_create($scontext));
|
||||
|
||||
|
||||
}
|
||||
|
||||
function github_apisend($url, $method = 'GET', $content = NULL) {
|
||||
@@ -178,7 +178,7 @@ function validate_user($payload) {
|
||||
$res = github_apisend('https://api.github.com/search/issues?q='.$querystring);
|
||||
$res = json_decode($res, TRUE);
|
||||
return $res['total_count'] >= (int)$validation_count;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function get_labels($payload){
|
||||
@@ -227,7 +227,7 @@ function tag_pr($payload, $opened) {
|
||||
sleep(10);
|
||||
$payload['pull_request'] = json_decode(github_apisend($url), TRUE);
|
||||
}
|
||||
|
||||
|
||||
$tags = array();
|
||||
$title = $payload['pull_request']['title'];
|
||||
if($opened) { //you only have one shot on these ones so as to not annoy maintainers
|
||||
@@ -235,7 +235,7 @@ function tag_pr($payload, $opened) {
|
||||
|
||||
if(strpos(strtolower($title), 'refactor') !== FALSE)
|
||||
$tags[] = 'Refactor';
|
||||
|
||||
|
||||
if(strpos(strtolower($title), 'revert') !== FALSE)
|
||||
$tags[] = 'Revert';
|
||||
if(strpos(strtolower($title), 'removes') !== FALSE)
|
||||
@@ -302,7 +302,7 @@ function check_ready_for_review($payload, $labels = null, $remove = array()){
|
||||
if($L == $r4rlabel)
|
||||
$has_label_already = true;
|
||||
}
|
||||
|
||||
|
||||
if($has_label_already && $should_not_have_label){
|
||||
$remove[] = $r4rlabel;
|
||||
return $returned;
|
||||
@@ -340,7 +340,7 @@ function check_ready_for_review($payload, $labels = null, $remove = array()){
|
||||
//make sure they are part of an offending review
|
||||
if(!in_array($C['pull_request_review_id'], $reviews_ids_with_changes_requested))
|
||||
continue;
|
||||
|
||||
|
||||
//review comments which are outdated have a null position
|
||||
if($C['position'] !== null){
|
||||
if($has_label_already)
|
||||
@@ -363,10 +363,10 @@ function check_dismiss_changelog_review($payload){
|
||||
|
||||
if(!$require_changelog)
|
||||
return;
|
||||
|
||||
|
||||
if(!$no_changelog)
|
||||
checkchangelog($payload, false);
|
||||
|
||||
|
||||
$review_message = 'Your changelog for this PR is either malformed or non-existent. Please create one to document your changes.';
|
||||
|
||||
$reviews = get_reviews($payload);
|
||||
@@ -427,8 +427,8 @@ function handle_pr($payload) {
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$pr_flags = 0;
|
||||
if (strpos(strtolower($payload['pull_request']['title']), '[s]') !== false) {
|
||||
$pr_flags |= F_SECRET_PR;
|
||||
@@ -438,7 +438,7 @@ function handle_pr($payload) {
|
||||
}
|
||||
discord_announce($action, $payload, $pr_flags);
|
||||
game_announce($action, $payload, $pr_flags);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
|
||||
@@ -447,7 +447,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
|
||||
unset($targets[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (isset($target['announce_secret']) && $target['announce_secret']) {
|
||||
if (!($pr_flags & F_SECRET_PR) && $target['announce_secret'] === 'only') {
|
||||
unset($targets[$i]);
|
||||
@@ -457,7 +457,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
|
||||
unset($targets[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (isset($target['announce_unvalidated']) && $target['announce_unvalidated']) {
|
||||
if (!($pr_flags & F_UNVALIDATED_USER) && $target['announce_unvalidated'] === 'only') {
|
||||
unset($targets[$i]);
|
||||
@@ -467,7 +467,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
|
||||
unset($targets[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$wildcard = false;
|
||||
if (isset($target['include_repos'])) {
|
||||
foreach ($target['include_repos'] as $match_string) {
|
||||
@@ -490,7 +490,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($target['exclude_repos']))
|
||||
foreach ($target['exclude_repos'] as $match_string) {
|
||||
$owner_repo_pair = explode('/', strtolower($match_string));
|
||||
@@ -517,13 +517,13 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
|
||||
|
||||
function game_announce($action, $payload, $pr_flags) {
|
||||
global $servers;
|
||||
|
||||
|
||||
$msg = '['.$payload['pull_request']['base']['repo']['full_name'].'] Pull Request '.$action.' by '.htmlSpecialChars($payload['sender']['login']).': <a href="'.$payload['pull_request']['html_url'].'">'.htmlSpecialChars('#'.$payload['pull_request']['number'].' '.$payload['pull_request']['user']['login'].' - '.$payload['pull_request']['title']).'</a>';
|
||||
|
||||
$game_servers = filter_announce_targets($servers, $payload['pull_request']['base']['repo']['owner']['login'], $payload['pull_request']['base']['repo']['name'], $action, $pr_flags);
|
||||
|
||||
|
||||
$msg = '?announce='.urlencode($msg).'&payload='.urlencode(json_encode($payload));
|
||||
|
||||
|
||||
foreach ($game_servers as $serverid => $server) {
|
||||
$server_message = $msg;
|
||||
if (isset($server['comskey']))
|
||||
@@ -554,9 +554,9 @@ function discord_announce($action, $payload, $pr_flags) {
|
||||
'username' => 'GitHub',
|
||||
'avatar_url' => $payload['pull_request']['base']['user']['avatar_url'],
|
||||
);
|
||||
|
||||
|
||||
$content = 'Pull Request #'.$payload['pull_request']['number'].' *'.$action.'* by '.discord_sanitize($payload['sender']['login'])."\n".discord_sanitize($payload['pull_request']['user']['login']).' - __**'.discord_sanitize($payload['pull_request']['title']).'**__'."\n".'<'.$payload['pull_request']['html_url'].'>';
|
||||
|
||||
|
||||
$embeds = array(
|
||||
array(
|
||||
'title' => '__**'.discord_sanitize($payload['pull_request']['title'], S_MARKDOWN).'**__',
|
||||
@@ -586,22 +586,22 @@ function discord_announce($action, $payload, $pr_flags) {
|
||||
}
|
||||
discord_webhook_send($discordWebHook['url'], $sending_data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function discord_sanitize($text, $flags = S_MENTIONS|S_LINK_EMBED|S_MARKDOWN) {
|
||||
function discord_sanitize($text, $flags = S_MENTIONS|S_LINK_EMBED|S_MARKDOWN) {
|
||||
if ($flags & S_MARKDOWN)
|
||||
$text = str_ireplace(array('\\', '*', '_', '~', '`', '|'), (array('\\\\', '\\*', '\\_', '\\~', '\\`', '\\|')), $text);
|
||||
|
||||
|
||||
if ($flags & S_HTML_COMMENTS)
|
||||
$text = preg_replace('/<!--(.*)-->/Uis', '', $text);
|
||||
|
||||
|
||||
if ($flags & S_MENTIONS)
|
||||
$text = str_ireplace(array('@everyone', '@here', '<@'), array('`@everyone`', '`@here`', '@<'), $text);
|
||||
|
||||
if ($flags & S_LINK_EMBED)
|
||||
$text = preg_replace("/((https?|ftp|byond)\:\/\/)([a-z0-9-.]*)\.([a-z]{2,3})(\:[0-9]{2,5})?(\/(?:[a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?/mi", '<$0>', $text);
|
||||
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ function get_pr_code_friendliness($payload, $oldbalance = null){
|
||||
$maxNegative = min($friendliness, $maxNegative);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$affecting = abs($maxNegative) >= $maxPositive ? $maxNegative : $maxPositive;
|
||||
return $affecting;
|
||||
}
|
||||
@@ -805,7 +805,7 @@ function checkchangelog($payload, $compile = true) {
|
||||
}
|
||||
if (!$incltag)
|
||||
continue;
|
||||
|
||||
|
||||
$firstword = explode(' ', $line)[0];
|
||||
$pos = strpos($line, " ");
|
||||
$item = '';
|
||||
@@ -815,7 +815,7 @@ function checkchangelog($payload, $compile = true) {
|
||||
} else {
|
||||
$firstword = $line;
|
||||
}
|
||||
|
||||
|
||||
if (!strlen($firstword)) {
|
||||
$currentchangelogblock[count($currentchangelogblock)-1]['body'] .= "\n";
|
||||
continue;
|
||||
@@ -933,7 +933,7 @@ function checkchangelog($payload, $compile = true) {
|
||||
case 'server':
|
||||
if($item != 'something server ops should know')
|
||||
$currentchangelogblock[] = array('type' => 'server', 'body' => $item);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
//we add it to the last changelog entry as a separate line
|
||||
if (count($currentchangelogblock) > 0)
|
||||
@@ -970,10 +970,10 @@ function checkchangelog($payload, $compile = true) {
|
||||
function game_server_send($addr, $port, $str) {
|
||||
// All queries must begin with a question mark (ie "?players")
|
||||
if($str{0} != '?') $str = ('?' . $str);
|
||||
|
||||
|
||||
/* --- Prepare a packet to send to the server (based on a reverse-engineered packet structure) --- */
|
||||
$query = "\x00\x83" . pack('n', strlen($str) + 6) . "\x00\x00\x00\x00\x00" . $str . "\x00";
|
||||
|
||||
|
||||
/* --- Create a socket and connect it to the server --- */
|
||||
$server = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) or exit("ERROR");
|
||||
socket_set_option($server, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 2, 'usec' => 0)); //sets connect and send timeout to 2 seconds
|
||||
@@ -981,7 +981,7 @@ function game_server_send($addr, $port, $str) {
|
||||
return "ERROR: Connection failed";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* --- Send bytes to the server. Loop until all bytes have been sent --- */
|
||||
$bytestosend = strlen($query);
|
||||
$bytessent = 0;
|
||||
@@ -989,22 +989,22 @@ function game_server_send($addr, $port, $str) {
|
||||
//echo $bytessent.'<br>';
|
||||
$result = socket_write($server,substr($query,$bytessent),$bytestosend-$bytessent);
|
||||
//echo 'Sent '.$result.' bytes<br>';
|
||||
if ($result===FALSE)
|
||||
if ($result===FALSE)
|
||||
return "ERROR: " . socket_strerror(socket_last_error());
|
||||
$bytessent += $result;
|
||||
}
|
||||
|
||||
|
||||
/* --- Idle for a while until recieved bytes from game server --- */
|
||||
$result = socket_read($server, 10000, PHP_BINARY_READ);
|
||||
socket_close($server); // we don't need this anymore
|
||||
|
||||
|
||||
if($result != "") {
|
||||
if($result{0} == "\x00" || $result{1} == "\x83") { // make sure it's the right packet format
|
||||
|
||||
|
||||
// Actually begin reading the output:
|
||||
$sizebytes = unpack('n', $result{2} . $result{3}); // array size of the type identifier and content
|
||||
$size = $sizebytes[1] - 1; // size of the string/floating-point (minus the size of the identifier byte)
|
||||
|
||||
|
||||
if($result{4} == "\x2a") { // 4-byte big-endian floating-point
|
||||
$unpackint = unpack('f', $result{5} . $result{6} . $result{7} . $result{8}); // 4 possible bytes: add them up together, unpack them as a floating-point
|
||||
return $unpackint[1];
|
||||
@@ -1012,7 +1012,7 @@ function game_server_send($addr, $port, $str) {
|
||||
else if($result{4} == "\x06") { // ASCII string
|
||||
$unpackstr = ""; // result string
|
||||
$index = 5; // string index
|
||||
|
||||
|
||||
while($size > 0) { // loop through the entire ASCII string
|
||||
$size--;
|
||||
$unpackstr .= $result{$index}; // add the string position to return string
|
||||
|
||||
Reference in New Issue
Block a user