From 585618d39a90a56fbfe2f064d62ba94bd7875674 Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Thu, 25 Jan 2024 20:24:55 +0100 Subject: [PATCH 1/2] refactor: put current code in a function --- .github/verify_versions.py | 52 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/.github/verify_versions.py b/.github/verify_versions.py index 42e8060..15a59ce 100644 --- a/.github/verify_versions.py +++ b/.github/verify_versions.py @@ -2,31 +2,35 @@ from urllib.request import urlopen import json -# Load local manifesto file -f = open('verified-mods.json') -manifesto = json.load(f) +def verify_all_mod_versions(): + # Load local manifesto file + f = open('verified-mods.json') + manifesto = json.load(f) -for mod in manifesto: - print('Verifying "{}":'.format(mod)) + for mod in manifesto: + print('Verifying "{}":'.format(mod)) - # Build GitHub API link and fetch distant tags list - words = manifesto[mod]['Repository'].split('/') - tags_url = "https://api.github.com/repos/{}/{}/tags".format(words[-2], words[-1]) - response = urlopen(tags_url) - tags_data = json.loads(response.read()) + # Build GitHub API link and fetch distant tags list + words = manifesto[mod]['Repository'].split('/') + tags_url = "https://api.github.com/repos/{}/{}/tags".format(words[-2], words[-1]) + response = urlopen(tags_url) + tags_data = json.loads(response.read()) - # Check all mod versions one-by-one - for version in manifesto[mod]['Versions']: - local_hash = version['CommitHash'] - matching_distant_versions = list(filter(lambda v: v['name'] == version['Version'], tags_data)) + # Check all mod versions one-by-one + for version in manifesto[mod]['Versions']: + local_hash = version['CommitHash'] + matching_distant_versions = list(filter(lambda v: v['name'] == version['Version'], tags_data)) - # There should be only one matching version - if len(matching_distant_versions) != 1: - sys.exit(' ❌ v{} (unknown distant version)'.format(version['Version'])) - - # Compare manifesto commit hash with repository hash - distant_version = matching_distant_versions[0] - if local_hash == distant_version['commit']['sha']: - print(' ✔️ v{}'.format(version['Version'])) - else: - sys.exit(' ❌ v{} (hash comparison failed)'.format(version['Version'])) + # There should be only one matching version + if len(matching_distant_versions) != 1: + sys.exit(' ❌ v{} (unknown distant version)'.format(version['Version'])) + + # Compare manifesto commit hash with repository hash + distant_version = matching_distant_versions[0] + if local_hash == distant_version['commit']['sha']: + print(' ✔️ v{}'.format(version['Version'])) + else: + sys.exit(' ❌ v{} (hash comparison failed)'.format(version['Version'])) + +if __name__ == "__main__": + verify_all_mod_versions() \ No newline at end of file From fb340debebdea20f464064224daef15d18be100e Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Mon, 29 Jan 2024 16:02:16 +0100 Subject: [PATCH 2/2] style: Add trailing newline --- .github/verify_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/verify_versions.py b/.github/verify_versions.py index 15a59ce..4da2ea1 100644 --- a/.github/verify_versions.py +++ b/.github/verify_versions.py @@ -33,4 +33,4 @@ def verify_all_mod_versions(): sys.exit(' ❌ v{} (hash comparison failed)'.format(version['Version'])) if __name__ == "__main__": - verify_all_mod_versions() \ No newline at end of file + verify_all_mod_versions()