-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from test-results-reporter/152-extension-ci-d…
…etails feat: refactor hyperlinks and metadata
- Loading branch information
Showing
5 changed files
with
160 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
const { checkCondition } = require('./helper') | ||
|
||
/** | ||
* Asynchronously generates metadata text for slack. | ||
* | ||
* @param {object} param0 - the payload object | ||
* @param {Object} param0.elements - The elements to generate metadata text from | ||
* @param {import('..').Target} param0.target - The result object | ||
* @param {import('..').Extension} param0.extension - The result object | ||
* @param {Object} param0.result - The result object | ||
* @param {string} param0.default_condition - The default condition object | ||
* @return {string} The generated metadata text | ||
*/ | ||
async function getSlackMetaDataText({ elements, target, extension, result, default_condition }) { | ||
const items = []; | ||
for (const element of elements) { | ||
if (await is_valid({ element, result, default_condition })) { | ||
if (element.type === 'hyperlink') { | ||
const url = await get_url({ url: element.value, target, result, extension }); | ||
items.push(`<${url}|${element.key}>`); | ||
} else if (element.key) { | ||
items.push(`*${element.key}:* ${element.value}`); | ||
} else { | ||
items.push(element.value); | ||
} | ||
} | ||
} | ||
return items.join(' | '); | ||
} | ||
|
||
/** | ||
* Asynchronously generates metadata text for teams. | ||
* | ||
* @param {object} param0 - the payload object | ||
* @param {Object} param0.elements - The elements to generate metadata text from | ||
* @param {import('..').Target} param0.target - The result object | ||
* @param {import('..').Extension} param0.extension - The result object | ||
* @param {Object} param0.result - The result object | ||
* @param {string} param0.default_condition - The default condition object | ||
* @return {string} The generated metadata text | ||
*/ | ||
async function getTeamsMetaDataText({ elements, target, extension, result, default_condition }) { | ||
const items = []; | ||
for (const element of elements) { | ||
if (await is_valid({ element, result, default_condition })) { | ||
if (element.type === 'hyperlink') { | ||
const url = await get_url({ url: element.value, target, result, extension }); | ||
items.push(`[${element.key}](${url})`); | ||
} else if (element.key) { | ||
items.push(`**${element.key}:** ${element.value}`); | ||
} else { | ||
items.push(element.value); | ||
} | ||
} | ||
} | ||
return items.join(' | '); | ||
} | ||
|
||
/** | ||
* Asynchronously generates metadata text for chat. | ||
* | ||
* @param {object} param0 - the payload object | ||
* @param {Object} param0.elements - The elements to generate metadata text from | ||
* @param {import('..').Target} param0.target - The result object | ||
* @param {import('..').Extension} param0.extension - The result object | ||
* @param {Object} param0.result - The result object | ||
* @param {string} param0.default_condition - The default condition object | ||
* @return {string} The generated metadata text | ||
*/ | ||
async function getChatMetaDataText({ elements, target, extension, result, default_condition }) { | ||
const items = []; | ||
for (const element of elements) { | ||
if (await is_valid({ element, result, default_condition })) { | ||
if (element.type === 'hyperlink') { | ||
const url = await get_url({ url: element.value, target, result, extension }); | ||
items.push(`<a href="${url}">${element.key}</a>`); | ||
} else if (element.key) { | ||
items.push(`<b>${element.key}:</b> ${element.value}`); | ||
} else { | ||
items.push(element.value); | ||
} | ||
} | ||
} | ||
return items.join(' | '); | ||
} | ||
|
||
function is_valid({ element, result, default_condition }) { | ||
const condition = element.condition || default_condition; | ||
return checkCondition({ condition, result }); | ||
} | ||
|
||
function get_url({ url, target, extension, result}) { | ||
if (typeof url === 'function') { | ||
return url({target, extension, result}); | ||
} | ||
return url; | ||
} | ||
|
||
module.exports = { | ||
getSlackMetaDataText, | ||
getTeamsMetaDataText, | ||
getChatMetaDataText | ||
} |