Skip to content

fix: truncate body when exceeds max length #1711

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

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ const fs = __importStar(__nccwpck_require__(7147));
const util = __importStar(__nccwpck_require__(3837));
const utils = __importStar(__nccwpck_require__(918));
const util_1 = __nccwpck_require__(3837);
function truncateBody(body) {
// 65536 characters is the maximum allowed for issues.
const truncateWarning = '...*[Issue body truncated]*';
if (body.length > 65536) {
core.warning(`Issue body is too long. Truncating to 65536 characters.`);
return body.substring(0, 65536 - truncateWarning.length) + truncateWarning;
}
return body;
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand All @@ -64,9 +73,10 @@ function run() {
// Check the file exists
if (yield util.promisify(fs.exists)(inputs.contentFilepath)) {
// Fetch the file content
const fileContent = yield fs.promises.readFile(inputs.contentFilepath, {
let fileContent = yield fs.promises.readFile(inputs.contentFilepath, {
encoding: 'utf8'
});
fileContent = truncateBody(fileContent);
const issueNumber = yield (() => __awaiter(this, void 0, void 0, function* () {
if (inputs.issueNumber) {
// Update an existing issue
Expand Down
14 changes: 13 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import * as util from 'util'
import * as utils from './utils'
import {inspect} from 'util'

function truncateBody(body: string) {
// 65536 characters is the maximum allowed for issues.
const truncateWarning = '...*[Issue body truncated]*'
if (body.length > 65536) {
core.warning(`Issue body is too long. Truncating to 65536 characters.`)
return body.substring(0, 65536 - truncateWarning.length) + truncateWarning
}
return body
}

async function run(): Promise<void> {
try {
const inputs = {
Expand All @@ -26,10 +36,12 @@ async function run(): Promise<void> {
// Check the file exists
if (await util.promisify(fs.exists)(inputs.contentFilepath)) {
// Fetch the file content
const fileContent = await fs.promises.readFile(inputs.contentFilepath, {
let fileContent = await fs.promises.readFile(inputs.contentFilepath, {
encoding: 'utf8'
})

fileContent = truncateBody(fileContent)

const issueNumber = await (async (): Promise<number> => {
if (inputs.issueNumber) {
// Update an existing issue
Expand Down