tools: Pass image path as an argument to the screenshot tool.

Instead of figuring out the image path from the integration name in the
puppeteer script, we do it in the `generate-integration-docs-screenshot`
script and pass it as an argument to `message-screenshot.js`.
This commit is contained in:
Puneeth Chaganti 2020-04-24 18:18:28 +05:30 committed by Tim Abbott
parent 39bea656f7
commit 4e5c30e7fd
2 changed files with 13 additions and 13 deletions

View File

@ -131,15 +131,14 @@ def send_bot_payload_message(bot: UserProfile, integration: WebhookIntegration,
print('Triggered {} webhook'.format(integration.name))
return True
def capture_last_message_screenshot(bot: UserProfile, integration: WebhookIntegration,
fixture_name: str) -> None:
def capture_last_message_screenshot(bot: UserProfile, image_path: 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))
print('No message found for {}'.format(bot.full_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])
subprocess.check_call(['node', screenshot_script, message_id, image_path])
parser = argparse.ArgumentParser()
parser.add_argument('fixture', type=webhook_json_fixture, help='Path to the fixture to use')
@ -155,4 +154,5 @@ bot = create_integration_bot(integration)
create_integration_stream(integration, bot)
message_sent = send_bot_payload_message(bot, integration, options.fixture, options.custom_headers)
if message_sent:
capture_last_message_screenshot(bot, integration, fixture_name)
image_path = static_path('images/integrations/{name}/001.png'.format(name=integration.name))
capture_last_message_screenshot(bot, image_path)

View File

@ -6,16 +6,16 @@ const host = "localhost:9991";
const options = {};
commander
.arguments('<integration> <message_id>')
.action((integration, messageId) => {
options.integration = integration;
.arguments('<message_id> <image_path>')
.action((messageId, imagePath) => {
options.messageId = messageId;
console.log(`Capturing screenshot for ${integration} using message ${messageId}`);
options.imagePath = imagePath;
console.log(`Capturing screenshot for message ${messageId} to ${imagePath}`);
})
.parse(process.argv);
if (options.integration === undefined) {
console.error('no integration specified!');
if (options.messageId === undefined) {
console.error('no messageId specified!');
process.exit(1);
}
@ -56,9 +56,9 @@ async function run() {
clip.x -= 5;
clip.width += 10;
clip.height += 10;
const imageDir = path.join(__dirname, '..', 'static', 'images', 'integrations', options.integration);
const imagePath = options.imagePath;
const imageDir = path.dirname(imagePath);
mkdirp.sync(imageDir);
const imagePath = path.join(imageDir, '001.png');
await page.screenshot({ path: imagePath, clip: clip });
console.log(`Screenshot captured to: \x1B[1;31m${imagePath}\n`);
} catch (e) {