-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strip ansi control chars from PR comments when called with {"color": "always"}
#859
base: main
Are you sure you want to change the base?
Conversation
When called with `color: always`, the PR comment includes ANSI control characters. Let's strip them using ansi-to-html
{"color": "always"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the whole this change LGTM. I do wonder if it makes sense to add pre
tags in all cases. My two concerns are if this will affect users who have color
disabled, and the performance of substringing when over max length (see inline comment).
Does GitHub Flavored Markdown always convert code blocks (```) to <pre>
tags when it renders in the browser? i.e. is change equivalent when color: never
?
while (maxLength !== undefined && html.length > maxLength) { | ||
message = message.substring(0, message.length - 1); | ||
html = convert.toHtml(message); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain in a comment what this code is doing? It looks like it's truncating the message body according to the max length of the message.
However, it looks like it's only cutting out a single character at a time and attempting to convert to HTML again. I imagine that would be very slow if html.length >>>> maxLength.
@@ -20,7 +34,7 @@ export async function handlePullRequestMessage( | |||
|
|||
const summary = '<summary>Pulumi report</summary>'; | |||
|
|||
const rawBody = output.substring(0, 64_000); | |||
const rawBody = ansiToHtml(output, { maxLength: 64_000 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR touches this code, would you mind pulling this value into a constant so it's not a "magic number"? I'd appreciate it :D
const comment = comments.find( | ||
(comment) => | ||
comment.body.startsWith(heading) && comment.body.includes(summary), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like its a purely aesthetic change, right? NBD, just checking.
When
pulumi/actions
is used with{comment-on-pr: true, color: "always"}
, it creates a PR comment with extra ANSI control characters.Let's strip them before adding them to the PR comment.
Uses
ansi-to-html
to convert the output into HTML. The result is then wrapped in<pre></pre>
tags before adding it to the PR comment.I have no idea if this is the best way to do it, but I thought I'd try it and see what people think. 😀
Before:
After: