ci/github-script/commits: keep formatting for diffs of markdown blocks

Previously, when the diff contained a context line with ```, this would
end the code block and entirely break the markdown rendering.

Now we use the html code blocks provided by `core.summary` and properly
escape the content, so that it never escapes via html tags.
This commit is contained in:
Wolfgang Walther 2025-07-16 12:15:07 +02:00
parent 40dcbb1483
commit b19798c8b0
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1

View File

@ -179,9 +179,14 @@ module.exports = async function ({ github, context, core }) {
}
core.summary.addRaw('<details><summary>Show diff</summary>')
core.summary.addRaw('\n\n```diff', true)
core.summary.addRaw(truncated.join('\n'), true)
core.summary.addRaw('```', true)
core.summary.addCodeBlock(
truncated
.join('\n')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;'),
'diff',
)
core.summary.addRaw('</details>')
}