Skip to content

Commit

Permalink
pr_validation.py: Improve Twitter verification and general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
m417z committed Nov 5, 2024
1 parent a9fe3e8 commit defdc82
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions .github/pr_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
]

VERIFIED_TWITTER_ACCOUNTS = {
'https://twitter.com/m417z': 'https://github.com/m417z',
'https://twitter.com/AhmedWalid605': 'https://github.com/ahmed605',
'https://twitter.com/learn_more': 'https://github.com/learn-more',
'https://twitter.com/realgam3': 'https://github.com/realgam3',
'https://twitter.com/teknixstuff': 'https://github.com/teknixstuff',
'https://twitter.com/kawaipure': 'https://github.com/kawapure',
'https://twitter.com/TorutheRedFox': 'https://github.com/TorutheRedFox',
'https://github.com/m417z': 'm417z',
'https://github.com/ahmed605': 'AhmedWalid605',
'https://github.com/learn-more': 'learn_more',
'https://github.com/realgam3': 'realgam3',
'https://github.com/teknixstuff': 'teknixstuff',
'https://github.com/kawapure': 'kawaipure',
'https://github.com/TorutheRedFox': 'TorutheRedFox',
}

MOD_METADATA_PARAMS = {
Expand Down Expand Up @@ -114,7 +114,7 @@ def get_mod_file_metadata(path: Path, file: TextIO):

if not any(key in x for x in MOD_METADATA_PARAMS.values()):
warnings += add_warning(
path, line_number, f'@{key} is not a valid metadata parameter'
path, line_number, f'{key} is not a valid metadata parameter'
)
continue

Expand All @@ -133,7 +133,7 @@ def get_mod_file_metadata(path: Path, file: TextIO):
else:
if (key, language) in properties:
warnings += add_warning(
path, line_number, f'@{key} must be specified only once'
path, line_number, f'{key} must be specified only once'
)
continue

Expand All @@ -158,61 +158,66 @@ def validate_metadata(path: Path, expected_author: str):
expected = f'https://github.com/{expected_author}'
if value != expected:
warnings += add_warning(
path, line_number, f'Expected @{key[0]} to be "{expected}"'
path, line_number, f'Expected {key[0]} to be "{expected}"'
)
else:
warnings += add_warning(path, 1, f'Missing @{key[0]}')
warnings += add_warning(path, 1, f'Missing {key[0]}')

key = ('id', None)
if key in properties:
value, line_number = properties[key]
expected = path.name.removesuffix('.cpp').removesuffix('.wh')
if value != expected:
warnings += add_warning(
path, line_number, f'Expected the id to be "{expected}"'
path, line_number, f'Expected {key[0]} to be "{expected}"'
)

if not re.fullmatch(r'([0-9a-z]+-)*[0-9a-z]+', value):
warnings += add_warning(
path, line_number, '@id must contain only letters, numbers and dashes'
path,
line_number,
f'{key[0]} must contain only letters, numbers and dashes',
)

if len(value) < 8 or len(value) > 50:
warnings += add_warning(
path, line_number, '@id must be between 8 and 50 characters'
path, line_number, f'{key[0]} must be between 8 and 50 characters'
)
else:
warnings += add_warning(path, 1, f'Missing @{key[0]}')
warnings += add_warning(path, 1, f'Missing {key[0]}')

key = ('version', None)
if key in properties:
value, line_number = properties[key]
if not re.fullmatch(r'([0-9]+\.)*[0-9]+', value):
warnings += add_warning(
path, line_number, 'Version must contain only numbers and dots'
path, line_number, f'{key[0]} must contain only numbers and dots'
)
else:
warnings += add_warning(path, 1, f'Missing @{key[0]}')
warnings += add_warning(path, 1, f'Missing {key[0]}')

key = ('twitter', None)
if key in properties:
value, line_number = properties[key]
if github is None or VERIFIED_TWITTER_ACCOUNTS.get(value) != github:
expected = github and VERIFIED_TWITTER_ACCOUNTS.get(github)
if not expected or not re.fullmatch(
r'https://(twitter|x)\.com/' + re.escape(expected), value
):
warnings += add_warning(
path, line_number, f'@{key[0]} requires manual verification'
path, line_number, f'{key[0]} requires manual verification'
)

key = ('compilerOptions', None)
if key in properties:
value, line_number = properties[key]
if not re.fullmatch(r'((-[lD]\S+|-Wl,--export-all-symbols)\s+)+', value + ' '):
warnings += add_warning(
path, line_number, 'Compiler options require manual verification'
path, line_number, f'{key[0]} require manual verification'
)

key = ('author', None)
if key not in properties:
warnings += add_warning(path, 1, f'Missing @{key[0]}')
warnings += add_warning(path, 1, f'Missing {key[0]}')

# Validate that this file has the required extensions
if ''.join(path.suffixes) != '.wh.cpp':
Expand Down

0 comments on commit defdc82

Please sign in to comment.