From dee6370db21705b252a091c0af39a5fe920e416b Mon Sep 17 00:00:00 2001 From: soulgalore Date: Wed, 5 May 2021 10:10:49 +0200 Subject: [PATCH 1/8] Lets try out sending a webhook. --- lib/plugins/webhook/cli.js | 8 ++++ lib/plugins/webhook/index.js | 75 ++++++++++++++++++++++++++++++++++++ lib/plugins/webhook/send.js | 54 ++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 lib/plugins/webhook/cli.js create mode 100644 lib/plugins/webhook/index.js create mode 100644 lib/plugins/webhook/send.js diff --git a/lib/plugins/webhook/cli.js b/lib/plugins/webhook/cli.js new file mode 100644 index 0000000000..2145c6023c --- /dev/null +++ b/lib/plugins/webhook/cli.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = { + url: { + describe: 'The URL where to send the webhook.', + group: 'WebHook' + } +}; diff --git a/lib/plugins/webhook/index.js b/lib/plugins/webhook/index.js new file mode 100644 index 0000000000..b50b2d4147 --- /dev/null +++ b/lib/plugins/webhook/index.js @@ -0,0 +1,75 @@ +'use strict'; + +const throwIfMissing = require('../../support/util').throwIfMissing; +const log = require('intel').getLogger('sitespeedio.plugin.webhook'); +const path = require('path'); +const cliUtil = require('../../cli/util'); +const send = require('./send'); + +module.exports = { + name() { + return path.basename(__dirname); + }, + get cliOptions() { + return require(path.resolve(__dirname, 'cli.js')); + }, + open(context, options = {}) { + this.webHookOptions = options.webhook || {}; + this.options = options; + log.info('Starting the webhook plugin'); + throwIfMissing(options.webhook, ['url'], 'webhook'); + this.resultUrls = context.resultUrls; + this.waitForUpload = false; + this.alias = {}; + this.message = { text: '' }; + if (options.webhook) { + for (let key of Object.keys(options.webhook)) { + if (key !== 'url') { + this.message[key] = options.webhook[key]; + } + } + } + }, + async processMessage(message) { + const options = this.webHookOptions; + switch (message.type) { + case 'browsertime.browser': { + this.browserData = message.data; + break; + } + case 'gcs.setup': + case 'ftp.setup': + case 's3.setup': { + this.waitForUpload = true; + break; + } + case 'browsertime.alias': { + this.alias[message.url] = message.data; + break; + } + case 'browsertime.config': { + if (message.data.screenshot === true) { + this.screenshotType = message.data.screenshotType; + } + break; + } + + case 'gcs.finished': + case 'ftp.finished': + case 's3.finished': + case 'sitespeedio.render': { + // sitespeedio.render is just for testing purpose + // if (this.waitForUpload) { + const message = { + text: this.resultUrls.reportSummaryUrl() + '/index.html' + }; + await send(options.url, message); + //} + break; + } + } + }, + get config() { + return cliUtil.pluginDefaults(this.cliOptions); + } +}; diff --git a/lib/plugins/webhook/send.js b/lib/plugins/webhook/send.js new file mode 100644 index 0000000000..3487369807 --- /dev/null +++ b/lib/plugins/webhook/send.js @@ -0,0 +1,54 @@ +'use strict'; + +const https = require('https'); +const log = require('intel').getLogger('sitespeedio.plugin.webhook'); + +function send(url, message, retries = 3, backoff = 5000) { + const parsedUrl = new URL(url); + const retryCodes = [408, 429, 500, 503]; + return new Promise((resolve, reject) => { + const req = https.request( + { + host: parsedUrl.hostname, + port: 443, + path: parsedUrl.pathname, + headers: { + 'Content-Type': 'application/json', + 'Content-Length': Buffer.byteLength(JSON.stringify(message), 'utf8') + }, + method: 'POST' + }, + res => { + const { statusCode } = res; + if (statusCode < 200 || statusCode > 299) { + if (retries > 0 && retryCodes.includes(statusCode)) { + setTimeout(() => { + return send(url, message, retries - 1, backoff * 2); + }, backoff); + } else { + log.error( + `Got error from the webhook server. Error Code: ${ + res.statusCode + } Message: ${res.statusMessage}` + ); + reject(new Error(`Status Code: ${res.statusCode}`)); + } + } else { + const data = []; + res.on('data', chunk => { + data.push(chunk); + }); + res.on('end', () => { + resolve(Buffer.concat(data).toString()); + }); + } + } + ); + req.write(JSON.stringify(message)); + req.end(); + }); +} + +module.exports = async (url, message) => { + return send(url, message); +}; From 3fb8f39781539547477b79dbcb48bf171d95c758 Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Fri, 21 May 2021 13:58:46 +0200 Subject: [PATCH 2/8] Fix hardcoded port --- lib/plugins/webhook/send.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/plugins/webhook/send.js b/lib/plugins/webhook/send.js index 3487369807..35f1378ef5 100644 --- a/lib/plugins/webhook/send.js +++ b/lib/plugins/webhook/send.js @@ -1,16 +1,20 @@ 'use strict'; const https = require('https'); +const http = require('http'); const log = require('intel').getLogger('sitespeedio.plugin.webhook'); function send(url, message, retries = 3, backoff = 5000) { const parsedUrl = new URL(url); + + const send = parsedUr.protocol === 'https' ? https : http; + const retryCodes = [408, 429, 500, 503]; return new Promise((resolve, reject) => { - const req = https.request( + const req = send.request( { host: parsedUrl.hostname, - port: 443, + port: parsedUrl.port, path: parsedUrl.pathname, headers: { 'Content-Type': 'application/json', From 15e325b2df3d2b12afc51836a8d4831ac176064a Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Fri, 21 May 2021 13:58:46 +0200 Subject: [PATCH 3/8] Fix hardcoded port --- lib/plugins/webhook/cli.js | 12 ++++++++ lib/plugins/webhook/content.js | 53 ++++++++++++++++++++++++++++++++++ lib/plugins/webhook/index.js | 11 +++++++ lib/plugins/webhook/send.js | 3 +- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 lib/plugins/webhook/content.js diff --git a/lib/plugins/webhook/cli.js b/lib/plugins/webhook/cli.js index 2145c6023c..a05f22341a 100644 --- a/lib/plugins/webhook/cli.js +++ b/lib/plugins/webhook/cli.js @@ -4,5 +4,17 @@ module.exports = { url: { describe: 'The URL where to send the webhook.', group: 'WebHook' + }, + messages: { + describe: 'Choose what type of message to send', + choices: ['budget', 'errors', 'summary'], + default: 'done', + group: 'WebHook' + }, + style: { + describe: 'How to format the content of the webhook.', + choices: ['html', 'markdown', 'text'], + default: 'text', + group: 'WebHook' } }; diff --git a/lib/plugins/webhook/content.js b/lib/plugins/webhook/content.js new file mode 100644 index 0000000000..3aaf87d579 --- /dev/null +++ b/lib/plugins/webhook/content.js @@ -0,0 +1,53 @@ +'use strict'; + +class Content { + constructor(style) { + this.style = style; + } + + getLink(url, name) { + switch (this.style) { + case 'html': + return `${name ? name : url}`; + case 'markdown': + return `[${name ? name : url}](${url})`; + default: + return url; + } + } + + getHeading(text) { + switch (this.style) { + case 'html': + return `

${text}

`; + case 'markdown': + return `# ${text}`; + default: + return text; + } + } + + getImage(url, altText) { + switch (this.style) { + case 'html': + return ``; + case 'markdown': + return `![${altText}](${url})`; + default: + return url; + } + } + + getHR() { + switch (this.style) { + case 'html': + return `
`; + case 'markdown': + return `---`; + default: + return ''; + } + } +} + +module.exports = Content; diff --git a/lib/plugins/webhook/index.js b/lib/plugins/webhook/index.js index b50b2d4147..641f33b83b 100644 --- a/lib/plugins/webhook/index.js +++ b/lib/plugins/webhook/index.js @@ -21,6 +21,7 @@ module.exports = { this.resultUrls = context.resultUrls; this.waitForUpload = false; this.alias = {}; + this.data = {}; this.message = { text: '' }; if (options.webhook) { for (let key of Object.keys(options.webhook)) { @@ -53,6 +54,16 @@ module.exports = { } break; } + case 'browsertime.pageSummary': { + this.data[message.url] = message.data; + break; + } + + case 'budget.result': { + if (options.messages.indexOf('budget') > -1) { + } + break; + } case 'gcs.finished': case 'ftp.finished': diff --git a/lib/plugins/webhook/send.js b/lib/plugins/webhook/send.js index 35f1378ef5..7905e77efd 100644 --- a/lib/plugins/webhook/send.js +++ b/lib/plugins/webhook/send.js @@ -6,8 +6,7 @@ const log = require('intel').getLogger('sitespeedio.plugin.webhook'); function send(url, message, retries = 3, backoff = 5000) { const parsedUrl = new URL(url); - - const send = parsedUr.protocol === 'https' ? https : http; + const send = parsedUrl.protocol === 'https' ? https : http; const retryCodes = [408, 429, 500, 503]; return new Promise((resolve, reject) => { From 799b7cc1c6537af6e6017e56c76f0c5f8a2286ab Mon Sep 17 00:00:00 2001 From: soulgalore Date: Wed, 16 Jun 2021 14:39:46 +0200 Subject: [PATCH 4/8] hepp --- lib/plugins/webhook/cli.js | 2 +- lib/plugins/webhook/content.js | 53 ------------- lib/plugins/webhook/format.js | 107 ++++++++++++++++++++++++++ lib/plugins/webhook/index.js | 135 ++++++++++++++++++++++++++++++--- 4 files changed, 233 insertions(+), 64 deletions(-) delete mode 100644 lib/plugins/webhook/content.js create mode 100644 lib/plugins/webhook/format.js diff --git a/lib/plugins/webhook/cli.js b/lib/plugins/webhook/cli.js index a05f22341a..4ad2987730 100644 --- a/lib/plugins/webhook/cli.js +++ b/lib/plugins/webhook/cli.js @@ -8,7 +8,7 @@ module.exports = { messages: { describe: 'Choose what type of message to send', choices: ['budget', 'errors', 'summary'], - default: 'done', + default: 'summary', group: 'WebHook' }, style: { diff --git a/lib/plugins/webhook/content.js b/lib/plugins/webhook/content.js deleted file mode 100644 index 3aaf87d579..0000000000 --- a/lib/plugins/webhook/content.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -class Content { - constructor(style) { - this.style = style; - } - - getLink(url, name) { - switch (this.style) { - case 'html': - return `${name ? name : url}`; - case 'markdown': - return `[${name ? name : url}](${url})`; - default: - return url; - } - } - - getHeading(text) { - switch (this.style) { - case 'html': - return `

${text}

`; - case 'markdown': - return `# ${text}`; - default: - return text; - } - } - - getImage(url, altText) { - switch (this.style) { - case 'html': - return ``; - case 'markdown': - return `![${altText}](${url})`; - default: - return url; - } - } - - getHR() { - switch (this.style) { - case 'html': - return `
`; - case 'markdown': - return `---`; - default: - return ''; - } - } -} - -module.exports = Content; diff --git a/lib/plugins/webhook/format.js b/lib/plugins/webhook/format.js new file mode 100644 index 0000000000..3f7f9c8073 --- /dev/null +++ b/lib/plugins/webhook/format.js @@ -0,0 +1,107 @@ +'use strict'; + +const newLine = '\n'; +class Format { + constructor(style) { + this.style = style; + } + + link(url, name) { + switch (this.style) { + case 'html': + return `${name ? name : url}`; + case 'markdown': + return `[${name ? name : url}](${url})`; + default: + return url; + } + } + + heading(text) { + switch (this.style) { + case 'html': + return `

${text}

`; + case 'markdown': + return `# ${text}`; + default: + return text; + } + } + + image(url, altText) { + switch (this.style) { + case 'html': + return ``; + case 'markdown': + return `![${altText}](${url})`; + default: + return url; + } + } + + bold(text) { + switch (this.style) { + case 'html': + return `${text}"`; + case 'markdown': + return `**${text})**`; + default: + return text; + } + } + + pre(text) { + switch (this.style) { + case 'html': + return `
${text}"
`; + case 'markdown': + return `${text})`; + default: + return text; + } + } + + p(text) { + switch (this.style) { + case 'html': + return `

${text}"

`; + case 'markdown': + return `${newLine}${newLine}${text})`; + default: + return `${newLine}${newLine}${text})`; + } + } + + list(text) { + switch (this.style) { + case 'html': + return `
    ${text}"
`; + default: + return text; + } + } + + listItem(text) { + switch (this.style) { + case 'html': + return `
  • ${text}"
  • `; + case 'markdown': + return `* ${text})`; + default: + return `* ${text} ${newLine})`; + } + } + + hr() { + switch (this.style) { + case 'html': + return `
    `; + case 'markdown': + return `---`; + default: + return `${newLine}`; + } + } +} + +module.exports = Format; diff --git a/lib/plugins/webhook/index.js b/lib/plugins/webhook/index.js index 641f33b83b..73ea21f729 100644 --- a/lib/plugins/webhook/index.js +++ b/lib/plugins/webhook/index.js @@ -3,8 +3,24 @@ const throwIfMissing = require('../../support/util').throwIfMissing; const log = require('intel').getLogger('sitespeedio.plugin.webhook'); const path = require('path'); +const get = require('lodash.get'); const cliUtil = require('../../cli/util'); const send = require('./send'); +const Format = require('./format'); + +function getBrowserData(data) { + if (data && data.browser) { + return `${data.browser.name} ${data.browser.version} ${get( + data, + 'android.model', + '' + )} ${get(data, 'android.androidVersion', '')} ${get( + data, + 'android.id', + '' + )} `; + } else return ''; +} module.exports = { name() { @@ -18,14 +34,16 @@ module.exports = { this.options = options; log.info('Starting the webhook plugin'); throwIfMissing(options.webhook, ['url'], 'webhook'); + this.format = new Format(this.webHookOptions.style); this.resultUrls = context.resultUrls; this.waitForUpload = false; this.alias = {}; this.data = {}; + this.errorTexts = {}; this.message = { text: '' }; if (options.webhook) { for (let key of Object.keys(options.webhook)) { - if (key !== 'url') { + if (key !== 'url' && key !== 'messages' && key !== 'style') { this.message[key] = options.webhook[key]; } } @@ -33,6 +51,7 @@ module.exports = { }, async processMessage(message) { const options = this.webHookOptions; + const format = this.format; switch (message.type) { case 'browsertime.browser': { this.browserData = message.data; @@ -55,27 +74,123 @@ module.exports = { break; } case 'browsertime.pageSummary': { - this.data[message.url] = message.data; + if (this.waitForUpload) { + this.data[message.url] = message.data; + } else { + await send(options.url, { + text: `Test for URL ${message.data.info.url}` + }); + } + break; + } + + case 'error': { + // We can send too many messages to Matrix and get 429 so instead + // we bulk send them all one time + if (options.messages.indexOf('error') > -1) { + this.errorTexts += `${format.hr()} ⚠️ Error from ${format.bold( + message.source + )} testing ${ + message.url ? format.link(message.url) : '' + } ${format.pre(message.data)}`; + } break; } case 'budget.result': { if (options.messages.indexOf('budget') > -1) { + let text = ''; + // We have failing URLs in the budget + if (Object.keys(message.data.failing).length > 0) { + const failingURLs = Object.keys(message.data.failing); + text += `${format.heading( + '⚠️ Budget failing (' + failingURLs.length + ' URLs)' + )}`; + text += `${format.p( + get(this.options, 'name', '') + + ' ' + + getBrowserData(this.browserData) + )}`; + for (let url of failingURLs) { + text += `
    ❌ ${url}`; + if (this.resultUrls.hasBaseUrl()) { + text += ` (result - screenshot)
    `; + } else { + text += ''; + } + text += '
      '; + for (let failing of message.data.failing[url]) { + text += `
    • ${failing.metric} : ${failing.friendlyValue} (${ + failing.friendlyLimit + })
    • `; + } + text += `
    `; + } + } + if (Object.keys(message.data.error).length > 0) { + const errorURLs = Object.keys(message.data.error); + text += `

    ⚠️ Budget errors testing ${ + errorURLs.length + } URLs

    `; + for (let url of errorURLs) { + text += `
    ❌ ${url}
    `; + text += `
    ${message.data.error[url]}
    `; + } + } + if ( + Object.keys(message.data.error).length === 0 && + Object.keys(message.data.failing).length === 0 + ) { + text += `

    🎉 All (${ + Object.keys(message.data.working).length + }) URLs passed the budget.

    `; + text += `${format.p( + get(this.options, 'name', '') + + ' ' + + getBrowserData(this.browserData) + )}`; + } + if (!this.waitForUpload) { + await send(options.url, { text }); + } else { + this.budgetText = text; + } } break; } case 'gcs.finished': case 'ftp.finished': - case 's3.finished': + case 's3.finished': { + if (this.waitForUpload && options.messages.indexOf('summary') > -1) { + const message = { + text: format.link( + this.resultUrls.reportSummaryUrl() + '/index.html' + ) + }; + await send(options.url, message); + } else if ( + this.waitForUpload && + options.messages.indexOf('budget') > -1 + ) { + await send(options.url, { text: this.budgetText }); + } + + break; + } + case 'sitespeedio.render': { - // sitespeedio.render is just for testing purpose - // if (this.waitForUpload) { - const message = { - text: this.resultUrls.reportSummaryUrl() + '/index.html' - }; - await send(options.url, message); - //} + if (this.errorTexts !== '') { + await send(options.url, { message: this.errorTexts }); + } break; } } From cafc877a875876aa5255b4cb02b0c29b54f88567 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Sat, 19 Jun 2021 15:07:12 +0200 Subject: [PATCH 5/8] hepp --- lib/plugins/webhook/index.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/plugins/webhook/index.js b/lib/plugins/webhook/index.js index 73ea21f729..a375042bbc 100644 --- a/lib/plugins/webhook/index.js +++ b/lib/plugins/webhook/index.js @@ -74,11 +74,11 @@ module.exports = { break; } case 'browsertime.pageSummary': { - if (this.waitForUpload) { + if (this.waitForUpload && options.messages.indexOf('pageSumary') > -1) { this.data[message.url] = message.data; - } else { + } else if (options.messages.indexOf('pageSumary') > -1) { await send(options.url, { - text: `Test for URL ${message.data.info.url}` + text: `Test finished ${format.link(message.data.info.url)}` }); } break; @@ -149,14 +149,15 @@ module.exports = { Object.keys(message.data.error).length === 0 && Object.keys(message.data.failing).length === 0 ) { - text += `

    🎉 All (${ - Object.keys(message.data.working).length - }) URLs passed the budget.

    `; - text += `${format.p( - get(this.options, 'name', '') + - ' ' + - getBrowserData(this.browserData) - )}`; + text += format.p( + `🎉 All (${ + Object.keys(message.data.working).length + }) URL(s) passed the budget using ${get( + this.options, + 'name', + '' + )} ${getBrowserData(this.browserData)}` + ); } if (!this.waitForUpload) { await send(options.url, { text }); From 95e94148ea6d0c2dce86c86b2f6ca9590f28f6ab Mon Sep 17 00:00:00 2001 From: soulgalore Date: Sun, 20 Jun 2021 15:45:45 +0200 Subject: [PATCH 6/8] hepp --- lib/plugins/webhook/format.js | 4 +- lib/plugins/webhook/index.js | 141 +++++++++++++++++++++++++--------- 2 files changed, 108 insertions(+), 37 deletions(-) diff --git a/lib/plugins/webhook/format.js b/lib/plugins/webhook/format.js index 3f7f9c8073..4a7b12b933 100644 --- a/lib/plugins/webhook/format.js +++ b/lib/plugins/webhook/format.js @@ -66,9 +66,9 @@ class Format { case 'html': return `

    ${text}"

    `; case 'markdown': - return `${newLine}${newLine}${text})`; + return `${newLine}${newLine}${text}`; default: - return `${newLine}${newLine}${text})`; + return `${newLine}${newLine}${text}`; } } diff --git a/lib/plugins/webhook/index.js b/lib/plugins/webhook/index.js index a375042bbc..c74c23fdc0 100644 --- a/lib/plugins/webhook/index.js +++ b/lib/plugins/webhook/index.js @@ -7,6 +7,52 @@ const get = require('lodash.get'); const cliUtil = require('../../cli/util'); const send = require('./send'); const Format = require('./format'); +const friendlynames = require('../../support/friendlynames'); + +function getPageSummary(data, format) { + let text = format.heading('Tested data for ' + data.info.url); + if (data.statistics.visualMetrics) { + let f = friendlynames['browsertime']['timnings']['FirstVisualChange']; + text += format.p( + f.name + + ' ' + + f.format(data.statistics.visualMetrics['FirstVisualChange'].median) + ); + f = friendlynames['browsertime']['timnings']['SpeedIndex']; + text += format.p( + f.name + + ' ' + + f.format(data.statistics.visualMetrics['SpeedIndex'].median) + ); + + f = friendlynames['browsertime']['timnings']['LastVisualChange']; + text += format.p( + f.name + + ' ' + + f.format(data.statistics.visualMetrics['LastVisualChange'].median) + ); + } + + if (data.statistics.googleWebVitals) { + for (let metric of Object.keys(data.statistics.googleWebVitals)) { + let f = + friendlynames.browsertime.timings[metric] || + friendlynames.browsertime.cpu[metric] || + friendlynames.browsertime.pageinfo[metric]; + + if (f) { + text += format.p( + f.name + + ' ' + + f.format(data.statistics.googleWebVitals[metric].median) + ); + } else { + // We do not have a mapping for FID + } + } + } + return text; +} function getBrowserData(data) { if (data && data.browser) { @@ -103,46 +149,57 @@ module.exports = { // We have failing URLs in the budget if (Object.keys(message.data.failing).length > 0) { const failingURLs = Object.keys(message.data.failing); - text += `${format.heading( - '⚠️ Budget failing (' + failingURLs.length + ' URLs)' - )}`; - text += `${format.p( - get(this.options, 'name', '') + + text += format.heading( + `${'⚠️ Budget failing (' + + failingURLs.length + + ' URLs)'}` + ); + text += format.p( + `${get(this.options, 'name', '') + ' ' + - getBrowserData(this.browserData) - )}`; + getBrowserData(this.browserData)}` + ); for (let url of failingURLs) { - text += `
    ❌ ${url}`; - if (this.resultUrls.hasBaseUrl()) { - text += ` (result - screenshot)
    `; - } else { - text += ''; - } - text += '
      '; + text += format.bold( + `❌ ${url}` + + (this.resultUrls.hasBaseUrl() + ? ` (${format.link( + this.resultUrls.absoluteSummaryPagePath( + url, + this.alias[url] + ) + 'index.html', + 'result' + )} - ${format.link( + this.resultUrls.absoluteSummaryPagePath( + url, + this.alias[url] + ) + + 'data/screenshots/1/afterPageCompleteCheck.' + + this.screenshotType, + 'screenshot' + )}` + : '') + ); + + let items = ''; for (let failing of message.data.failing[url]) { - text += `
    • ${failing.metric} : ${failing.friendlyValue} (${ - failing.friendlyLimit - })
    • `; + items += format.listItem( + `${failing.metric} : ${failing.friendlyValue} (${ + failing.friendlyLimit + })` + ); } - text += `
    `; + text += format.list(items); } } if (Object.keys(message.data.error).length > 0) { const errorURLs = Object.keys(message.data.error); - text += `

    ⚠️ Budget errors testing ${ - errorURLs.length - } URLs

    `; + text += format.heading( + `⚠️ Budget errors testing ${errorURLs.length} URLs` + ); for (let url of errorURLs) { - text += `
    ❌ ${url}
    `; - text += `
    ${message.data.error[url]}
    `; + text += format.p(`❌ ${url}`); + text += format.pre(`${message.data.error[url]}`); } } if ( @@ -171,12 +228,26 @@ module.exports = { case 'gcs.finished': case 'ftp.finished': case 's3.finished': { - if (this.waitForUpload && options.messages.indexOf('summary') > -1) { + if ( + this.waitForUpload && + options.messages.indexOf('pageSummary') > -1 + ) { const message = { - text: format.link( - this.resultUrls.reportSummaryUrl() + '/index.html' - ) + text: '' }; + for (let url of Object.keys(this.data)) { + message.text += getPageSummary(this.data[url], format); + } + + if (this.resultUrls.reportSummaryUrl()) { + message.text += format.p( + format.link( + this.resultUrls.reportSummaryUrl() + '/index.html', + 'Summary' + ) + ); + } + await send(options.url, message); } else if ( this.waitForUpload && From 6b091173712318279a75cc0c43a8983acd35f2a5 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Sun, 20 Jun 2021 17:10:25 +0200 Subject: [PATCH 7/8] Show screenshot --- lib/plugins/webhook/index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/plugins/webhook/index.js b/lib/plugins/webhook/index.js index c74c23fdc0..91d399c959 100644 --- a/lib/plugins/webhook/index.js +++ b/lib/plugins/webhook/index.js @@ -9,8 +9,17 @@ const send = require('./send'); const Format = require('./format'); const friendlynames = require('../../support/friendlynames'); -function getPageSummary(data, format) { +function getPageSummary(data, format, resultUrls, alias, screenshotType) { let text = format.heading('Tested data for ' + data.info.url); + + if (resultUrls.hasBaseUrl()) { + text += format.image( + resultUrls.absoluteSummaryPagePath(data.info.url, alias[data.info.url]) + + 'data/screenshots/1/afterPageCompleteCheck.' + + screenshotType + ); + } + if (data.statistics.visualMetrics) { let f = friendlynames['browsertime']['timnings']['FirstVisualChange']; text += format.p( @@ -236,7 +245,13 @@ module.exports = { text: '' }; for (let url of Object.keys(this.data)) { - message.text += getPageSummary(this.data[url], format); + message.text += getPageSummary( + this.data[url], + format, + this.resultUrls, + this.alias, + this.screenshotType + ); } if (this.resultUrls.reportSummaryUrl()) { From 6808677d4fc70d7b66806d3ba178a52c14a60277 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Sun, 20 Jun 2021 17:17:20 +0200 Subject: [PATCH 8/8] Add link to result --- lib/plugins/webhook/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/plugins/webhook/index.js b/lib/plugins/webhook/index.js index 91d399c959..f7def98bdf 100644 --- a/lib/plugins/webhook/index.js +++ b/lib/plugins/webhook/index.js @@ -10,7 +10,19 @@ const Format = require('./format'); const friendlynames = require('../../support/friendlynames'); function getPageSummary(data, format, resultUrls, alias, screenshotType) { - let text = format.heading('Tested data for ' + data.info.url); + let text = format.heading( + 'Tested data for ' + + data.info.url + + (resultUrls.hasBaseUrl() + ? format.link( + resultUrls.absoluteSummaryPagePath( + data.info.url, + alias[data.info.url] + ), + '(result)' + ) + : '') + ); if (resultUrls.hasBaseUrl()) { text += format.image(