Skip to content

Commit

Permalink
Escape message of failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Scholz committed Oct 16, 2023
1 parent 6a3d4dc commit 402ae87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,20 @@ function createGoogleCardV2StructureOutput(
'https://raw.githubusercontent.com/SimonScholz/google-chat-action/main/assets/failure-128.png'
},
wrapText: true,
text: `<b>Name:</b> ${makeJQAndBashFriendly(failure.source?.name)} <br><b>Test:</b> ${makeJQAndBashFriendly(failure.error.test)} <br><b>Message:</b> ${makeJQAndBashFriendly(failure.error.message)}`
text: `<b>Name:</b> ${makeJQAndBashFriendly(
failure.source?.name
)} <br><b>Test:</b> ${makeJQAndBashFriendly(
failure.error.test
)} <br><b>Message:</b> ${makeJQAndBashFriendly(failure.error.message)}`
}
}
})

const headerText =
summary.run.failures.length > 0
? `<font color="#FF0B0B">${makeJQAndBashFriendly(summary.collection.name)} - ${summary.run.failures.length} Failure(s)</font>`
? `<font color="#FF0B0B">${makeJQAndBashFriendly(
summary.collection.name
)} - ${summary.run.failures.length} Failure(s)</font>`
: makeJQAndBashFriendly(summary.collection.name)

return [
Expand All @@ -111,6 +117,8 @@ function createGoogleCardV2StructureOutput(
* @param jsonString json string that may contain single quotes
* @returns the JSON string without single quotes
*/
function makeJQAndBashFriendly(jsonString: string | undefined): string | undefined {
return jsonString?.replace(/'/g, '').replace( /(<([^>]+)>)/ig, '')
function makeJQAndBashFriendly(
jsonString: string | undefined
): string | undefined {
return jsonString?.replace(/'/g, '').replace(/(<([^>]+)>)/gi, '')
}

0 comments on commit 402ae87

Please sign in to comment.