From d5f5a99b0735ea7abb67468dc1439a8c7417910b Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 21 Apr 2020 22:31:54 +0530 Subject: [PATCH] tools: Verify that all integrations have bot avatars. --- tools/ci/backend | 1 + .../generate_integration_bots_avatars.py | 23 ++++++++++++++++--- tools/test-all | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/ci/backend b/tools/ci/backend index 30abe15562..00e3f326b5 100755 --- a/tools/ci/backend +++ b/tools/ci/backend @@ -21,6 +21,7 @@ set -x ./tools/test-migrations ./tools/setup/optimize-svg +./tools/setup/generate_integration_bots_avatars.py --check-missing # In CI, we only test links we control in test-documentation to avoid flakes ./tools/test-documentation --skip-external-links ./tools/test-help-documentation --skip-external-links diff --git a/tools/setup/generate_integration_bots_avatars.py b/tools/setup/generate_integration_bots_avatars.py index e25136fa43..b735d3a1da 100755 --- a/tools/setup/generate_integration_bots_avatars.py +++ b/tools/setup/generate_integration_bots_avatars.py @@ -14,7 +14,9 @@ import django django.setup() +import argparse import io + import cairosvg from PIL import Image @@ -53,12 +55,27 @@ def create_integration_bot_avatar(logo_path: str) -> None: with open(bot_avatar_path, 'wb') as f: f.write(avatar) -def generate_integration_bots_avatars() -> None: +def generate_integration_bots_avatars(check_missing: bool=False) -> None: + missing = set() for webhook in WEBHOOK_INTEGRATIONS: logo_path = webhook.get_logo_path() if not logo_path: continue - create_integration_bot_avatar(static_path(logo_path)) + if check_missing: + bot_avatar_path = static_path(webhook.DEFAULT_BOT_AVATAR_PATH.format(name=webhook.name)) + if not os.path.isfile(bot_avatar_path): + missing.add(webhook.name) + else: + create_integration_bot_avatar(static_path(logo_path)) + + if missing: + print('Bot avatars are missing for these webhooks: {}.\n' + 'Run ./tools/setup/generate_integration_bots_avatars.py ' + 'to generate them.'.format(', '.join(missing))) + sys.exit(1) if __name__ == '__main__': - generate_integration_bots_avatars() + parser = argparse.ArgumentParser() + parser.add_argument('--check-missing', action='store_true') + options = parser.parse_args() + generate_integration_bots_avatars(options.check_missing) diff --git a/tools/test-all b/tools/test-all index f886be48f3..9902f84f1a 100755 --- a/tools/test-all +++ b/tools/test-all @@ -45,6 +45,8 @@ run ./tools/test-backend --include-webhooks $FORCEARG run ./tools/test-migrations # Not running SVG optimizing since it's low-churn # run ./tools/setup/optimize-svg +# Not running missing bot avatar detection since it's low churn +# ./tools/setup/generate_integration_bots_avatars.py --check-missing # Not running documentation tests since it takes 20s and only tests documentation # run ./tools/test-documentation run ./tools/test-help-documentation $FORCEARG