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

Truncate files which are too long #181

Closed
kunaltyagi opened this issue Apr 28, 2023 · 1 comment · Fixed by #182
Closed

Truncate files which are too long #181

kunaltyagi opened this issue Apr 28, 2023 · 1 comment · Fixed by #182

Comments

@kunaltyagi
Copy link

/opt/github/actions-runner-1/_work/_actions/peter-evans/create-or-update-comment/v3.0.0/dist/index.js:4685
      const error = new requestError.RequestError(toErrorMessage(data), status, {
                    ^

RequestError [HttpError]: Validation Failed: {"resource":"IssueComment","code":"custom","field":"body","message":"body is too long (maximum is 65536 characters)"}
    at /opt/github/actions-runner-1/_work/_actions/peter-evans/create-or-update-comment/v3.0.0/dist/index.js:4685:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 422,

This is caused when the body-path file is too large. Can we limit the body content to 65535 characters with a mode (head/tail)? This would limit an unexpected error handling if an additional warning was output when the file size if more than the limit

A prototype in shell:

if [ stat -c "%s" <file> -gt 65535 ]; then
  echo "::warning file=${filename},line=1,endLine=1,title=Content too long::Restricting content to just 65535 bytes as per truncation setting: ${mode}"
  # get extra bytes since unicode characters can be longer than 1 byte
  if [ ${mode} == "tail" ]; then command=tail else command=head; fi
  content=$(${command} -c 65538 ${filename} | iconv -c -f UTF-8 -t UTF-8 | ${command} -c 65535)
else
  content=$(cat ${filename}
fi
@peter-evans
Copy link
Owner

Hi @kunaltyagi

Thank you for raising this issue.

I've made a fix for this in v3.0.1 / v3. The action will now truncate the body if it exceeds the max length.

You suggested options for head/tail, but I would rather not add those to the action. If you need more complex logic for truncation then that should be done in a separate workflow step before calling this action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants