Skip to content

Commit e8ef132

Browse files
authored
fix: truncate body when exceeds max length (#1711)
1 parent 60e5747 commit e8ef132

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

dist/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ const fs = __importStar(__nccwpck_require__(7147));
4545
const util = __importStar(__nccwpck_require__(3837));
4646
const utils = __importStar(__nccwpck_require__(918));
4747
const util_1 = __nccwpck_require__(3837);
48+
function truncateBody(body) {
49+
// 65536 characters is the maximum allowed for issues.
50+
const truncateWarning = '...*[Issue body truncated]*';
51+
if (body.length > 65536) {
52+
core.warning(`Issue body is too long. Truncating to 65536 characters.`);
53+
return body.substring(0, 65536 - truncateWarning.length) + truncateWarning;
54+
}
55+
return body;
56+
}
4857
function run() {
4958
return __awaiter(this, void 0, void 0, function* () {
5059
try {
@@ -64,9 +73,10 @@ function run() {
6473
// Check the file exists
6574
if (yield util.promisify(fs.exists)(inputs.contentFilepath)) {
6675
// Fetch the file content
67-
const fileContent = yield fs.promises.readFile(inputs.contentFilepath, {
76+
let fileContent = yield fs.promises.readFile(inputs.contentFilepath, {
6877
encoding: 'utf8'
6978
});
79+
fileContent = truncateBody(fileContent);
7080
const issueNumber = yield (() => __awaiter(this, void 0, void 0, function* () {
7181
if (inputs.issueNumber) {
7282
// Update an existing issue

src/main.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import * as util from 'util'
55
import * as utils from './utils'
66
import {inspect} from 'util'
77

8+
function truncateBody(body: string) {
9+
// 65536 characters is the maximum allowed for issues.
10+
const truncateWarning = '...*[Issue body truncated]*'
11+
if (body.length > 65536) {
12+
core.warning(`Issue body is too long. Truncating to 65536 characters.`)
13+
return body.substring(0, 65536 - truncateWarning.length) + truncateWarning
14+
}
15+
return body
16+
}
17+
818
async function run(): Promise<void> {
919
try {
1020
const inputs = {
@@ -26,10 +36,12 @@ async function run(): Promise<void> {
2636
// Check the file exists
2737
if (await util.promisify(fs.exists)(inputs.contentFilepath)) {
2838
// Fetch the file content
29-
const fileContent = await fs.promises.readFile(inputs.contentFilepath, {
39+
let fileContent = await fs.promises.readFile(inputs.contentFilepath, {
3040
encoding: 'utf8'
3141
})
3242

43+
fileContent = truncateBody(fileContent)
44+
3345
const issueNumber = await (async (): Promise<number> => {
3446
if (inputs.issueNumber) {
3547
// Update an existing issue

0 commit comments

Comments
 (0)