Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think I got it now #1554

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions .github/actions/validate-manifest/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import requests
from sys import exit as sys_exit
from re import fullmatch as re_match

REQUIRED_KEYS = ['server_name', 'nice_name', 'direct_ip']
USERNAME_SOCIAL_KEYS = ['twitter', 'tiktok', 'facebook', 'instagram', 'teamspeak']
Expand Down Expand Up @@ -154,8 +153,9 @@ def main():
message_format = message_format[0]
else:
error += f'**message_format** has the wrong format. Please recheck the [example manifest](https://github.com/LabyMod/server-media/blob/master/docs/Manifest.md#chat-object).'
template_regex = r'^§[a-f0-9](?P<level>\d+)( \||§8 \|) §[a-f0-9](?P<sender>[a-zA-Z0-9_]{2,16})§r§7: §f(?P<message>.*)$'
if re_match(template_regex, message_format):

template_regex = '^§[a-f0-9](?<level>\\d+)( \\||§8 \\|) §[a-f0-9](?<sender>[a-zA-Z0-9_]{2,16})§r§7: §f(?<message>.*)$'
if template_regex == message_format:
comment += f'- It seems you\'re using the **template regex** for chat message! Please make sure it is the right regex for **your server**!'
if message_format in ('', '-'):
error += f'- Please remove the empty key **message_formats** or fill in information.\n'
Expand All @@ -177,9 +177,9 @@ def main():

if create_comment:
if error != '':
post_comment(error, True)
post_comment(error)
if comment != '':
post_comment(comment, False)
post_comment(comment, 'comments')

if error != '':
# Make job fail
Expand All @@ -206,11 +206,7 @@ def get_changed_manifest_files():
return changed_files


def post_comment(comment: str, error: bool, request_type: str = 'reviews'):
if not error and request_type != 'comment':
print('No error found.')
return

def post_comment(comment: str, request_type: str = 'reviews'):
if request_type == 'reviews':
comment += '\nPlease fix the issues by pushing **one** commit to the pull ' \
'request to prevent too many automatic reviews.'
Expand All @@ -222,7 +218,7 @@ def post_comment(comment: str, error: bool, request_type: str = 'reviews'):
headers={'Accept': 'application/vnd.github.v3+json', 'Authorization': f"Token {os.getenv('GH_TOKEN')}"}
)

print(f'Github request returned {request.status_code}')
print(f'Github request returned {request.status_code}, posted into {request_type}.')


def check_server_online_state(ip: str, wildcards: list):
Expand Down Expand Up @@ -258,7 +254,7 @@ def check_server_online_state(ip: str, wildcards: list):
offline_text += f"Reference: [API URL ({url})]({url})"

if not response['online']:
post_comment(f'*Just as an information*:\nYour server {ip} **could be offline**.\n {offline_text}', False, 'comments')
post_comment(f'*Just as an information*:\nYour server {ip} **could be offline**.\n {offline_text}', 'comments')

wildcard_string = '*Just as an information*:\n'
wildcard_comment = False
Expand All @@ -285,7 +281,7 @@ def check_server_online_state(ip: str, wildcards: list):

wildcard_string += f'\nPlease make sure it is an [actual wildcard](https://en.wikipedia.org/wiki/Wildcard_DNS_record).\n'
if wildcard_comment:
post_comment(wildcard_string, False, 'comments')
post_comment(wildcard_string, 'comments')

if 'motd' in response:
maintenance_tagged = False
Expand All @@ -296,7 +292,7 @@ def check_server_online_state(ip: str, wildcards: list):
else:
print(f'No maintenance found in MOTD')
if maintenance_tagged:
post_comment(f'The server {ip} **is in maintenance**.\n {offline_text}', True)
post_comment(f'The server {ip} **is in maintenance**.\n {offline_text}')


def comment_needed():
Expand Down
Loading