generate-integration-docs-screenshot: Fix crash on ignored fixtures.

When using a fixture that is correctly handled by our webhooks, but don't
cause a notification message to be sent, the tool shouldn't crash.
This commit is contained in:
Puneeth Chaganti 2020-04-17 16:55:05 +05:30 committed by Tim Abbott
parent 9248b16e86
commit 84e411c543
1 changed files with 8 additions and 3 deletions

View File

@ -114,8 +114,13 @@ def send_bot_payload_message(bot: UserProfile, integration: WebhookIntegration,
sys.exit(1)
print('Triggered {} webhook'.format(integration.name))
def capture_last_message_screenshot(bot: UserProfile, integration: WebhookIntegration) -> None:
message_id = str(Message.objects.filter(sender=bot).last().id)
def capture_last_message_screenshot(bot: UserProfile, integration: WebhookIntegration,
fixture_name: str) -> None:
message = Message.objects.filter(sender=bot).last()
if message is None:
print('No message found for {} integration for {}'.format(integration.name, fixture_name))
return
message_id = str(message.id)
screenshot_script = os.path.join(TOOLS_DIR, 'message-screenshot.js')
subprocess.check_call(['node', screenshot_script, integration.name, message_id])
@ -128,4 +133,4 @@ integration_name, fixture_name = split_fixture_path(options.fixture)
integration = get_integration(integration_name)
bot = create_integration_bot(integration)
send_bot_payload_message(bot, integration, options.fixture)
capture_last_message_screenshot(bot, integration)
capture_last_message_screenshot(bot, integration, fixture_name)