Skip to content
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

Remove ansi control chars from PR comment message #1231

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ The action can be configured with the following arguments:
`true`. This is in an effort to reduce verbosity - if you want to have a
comment per PR run, please ensure that you set this to `false`.

- `comment-max-character` - (optional) Maximum number of characters of the Pulumi
action result to be added to the PR. Default value is 64000.

- `expect-no-changes` - (optional) Return an error if any changes occur during
this update.

Expand Down
4 changes: 0 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ inputs:
description: 'If true, a comment on the GitHub step summary will be created'
required: false
default: 'false'
comment-max-character:
description: 'Maximum number of characters of output added to the PR.'
required: false
default: "64000"
github-token:
description: 'Github Token'
required: false
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const defaultConfig: Record<string, string> = {
'pulumi-version': '^3',
'comment-on-pr': 'false',
'comment-on-summary': 'false',
'comment-max-character': '64000',
upsert: 'false',
remove: 'false',
refresh: 'false',
Expand Down Expand Up @@ -42,7 +41,6 @@ describe('config.ts', () => {
Object {
"cloudUrl": "file://~",
"command": "up",
"commentMaxCharacter": 64000,
"commentOnPr": false,
"commentOnPrNumber": undefined,
"commentOnSummary": false,
Expand Down
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export function makeConfig() {
commentOnPr: getBooleanInput('comment-on-pr'),
commentOnPrNumber: getNumberInput('comment-on-pr-number', {}),
commentOnSummary: getBooleanInput('comment-on-summary'),
commentMaxCharacter: getNumberInput('comment-max-character'),
upsert: getBooleanInput('upsert'),
remove: getBooleanInput('remove'),
refresh: getBooleanInput('refresh'),
Expand Down
3 changes: 1 addition & 2 deletions src/libs/__tests__/pr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const projectName = 'myFirstProject';
const defaultOptions = {
command: 'preview',
stackName: 'staging',
commentMaxCharacter: 64000,
options: {},
} as Config;
const createComment = jest.fn();
Expand Down Expand Up @@ -56,7 +55,7 @@ describe('pr.ts', () => {
});
});

it('should convert ansi controll character to html and add to pull request message', async () => {
it('should convert ansi control character to html and add to pull request message', async () => {
// @ts-ignore
gh.context = {
payload: {
Expand Down
6 changes: 4 additions & 2 deletions src/libs/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ export async function handlePullRequestMessage(
command,
stackName,
editCommentOnPr,
commentMaxCharacter,
} = config;

// GitHub limits comment characters to 65535, use lower max to keep buffer for variable values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ thanks for documenting this!

const MAX_CHARACTER_COMMENT = 64_000;

const heading = `#### :tropical_drink: \`${command}\` on ${projectName}/${stackName}`;

const summary = '<summary>Pulumi report</summary>';

const [htmlBody, trimmed]: [string, boolean] = ansiToHtml(output, commentMaxCharacter);
const [htmlBody, trimmed]: [string, boolean] = ansiToHtml(output, MAX_CHARACTER_COMMENT);

const body = dedent`
${heading}
Expand Down
Loading