fix: preserve new lines in body and comments (#72)

This commit is contained in:
Andrea Lamparelli 2023-07-27 15:35:23 +02:00 committed by GitHub
parent a402fa4525
commit fa43ffc1dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 38 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ build/
# temporary files created during tests
*test*.json
bp

View file

@ -29,11 +29,11 @@ inputs:
title:
description: "Backporting PR title. Default is the original PR title prefixed by the target branch"
required: false
body:
description: "Backporting PR body. Default is the original PR body prefixed by `backport: <original-pr-link>`"
required: false
body-prefix:
description: "Backporting PR body prefix. Default is `backport: <original-pr-link>`"
description: "Backporting PR body prefix. Default is `Backport: <original-pr-link>`"
required: false
body:
description: "Backporting PR body. Default is the original PR body"
required: false
bp-branch-name:
description: "Backporting PR branch name. Default is auto-generated from commit"

7
dist/cli/index.js vendored
View file

@ -340,7 +340,7 @@ class PullRequestConfigsParser extends configs_parser_1.default {
}
}
const bodyPrefix = args.bodyPrefix ?? `**Backport:** ${originalPullRequest.htmlUrl}\r\n\r\n`;
const body = args.body ?? `${originalPullRequest.body}`;
const body = bodyPrefix + (args.body ?? `${originalPullRequest.body}`);
const labels = args.labels ?? [];
if (args.inheritLabels) {
labels.push(...originalPullRequest.labels);
@ -361,11 +361,12 @@ class PullRequestConfigsParser extends configs_parser_1.default {
head: backportBranch,
base: args.targetBranch,
title: args.title ?? `[${args.targetBranch}] ${originalPullRequest.title}`,
body: `${bodyPrefix}${body}`,
// preserve new line chars
body: body.replace(/\\n/g, "\n").replace(/\\r/g, "\r"),
reviewers: [...new Set(reviewers)],
assignees: [...new Set(args.assignees)],
labels: [...new Set(labels)],
comments: args.comments ?? [],
comments: args.comments?.map(c => c.replace(/\\n/g, "\n").replace(/\\r/g, "\r")) ?? [],
};
}
}

7
dist/gha/index.js vendored
View file

@ -310,7 +310,7 @@ class PullRequestConfigsParser extends configs_parser_1.default {
}
}
const bodyPrefix = args.bodyPrefix ?? `**Backport:** ${originalPullRequest.htmlUrl}\r\n\r\n`;
const body = args.body ?? `${originalPullRequest.body}`;
const body = bodyPrefix + (args.body ?? `${originalPullRequest.body}`);
const labels = args.labels ?? [];
if (args.inheritLabels) {
labels.push(...originalPullRequest.labels);
@ -331,11 +331,12 @@ class PullRequestConfigsParser extends configs_parser_1.default {
head: backportBranch,
base: args.targetBranch,
title: args.title ?? `[${args.targetBranch}] ${originalPullRequest.title}`,
body: `${bodyPrefix}${body}`,
// preserve new line chars
body: body.replace(/\\n/g, "\n").replace(/\\r/g, "\r"),
reviewers: [...new Set(reviewers)],
assignees: [...new Set(args.assignees)],
labels: [...new Set(labels)],
comments: args.comments ?? [],
comments: args.comments?.map(c => c.replace(/\\n/g, "\n").replace(/\\r/g, "\r")) ?? [],
};
}
}

View file

@ -63,7 +63,7 @@ export default class PullRequestConfigsParser extends ConfigsParser {
}
const bodyPrefix = args.bodyPrefix ?? `**Backport:** ${originalPullRequest.htmlUrl}\r\n\r\n`;
const body = args.body ?? `${originalPullRequest.body}`;
const body = bodyPrefix + (args.body ?? `${originalPullRequest.body}`);
const labels = args.labels ?? [];
if (args.inheritLabels) {
@ -88,11 +88,12 @@ export default class PullRequestConfigsParser extends ConfigsParser {
head: backportBranch,
base: args.targetBranch,
title: args.title ?? `[${args.targetBranch}] ${originalPullRequest.title}`,
body: `${bodyPrefix}${body}`,
// preserve new line chars
body: body.replace(/\\n/g, "\n").replace(/\\r/g, "\r"),
reviewers: [...new Set(reviewers)],
assignees: [...new Set(args.assignees)],
labels: [...new Set(labels)],
comments: args.comments ?? [],
comments: args.comments?.map(c => c.replace(/\\n/g, "\n").replace(/\\r/g, "\r")) ?? [],
};
}
}

View file

@ -229,7 +229,7 @@ describe("cli runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -274,7 +274,7 @@ describe("cli runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"),
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -331,7 +331,7 @@ describe("cli runner", () => {
head: "bp-target-9174896",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/4444"),
body: "**Backport:** https://github.com/owner/reponame/pull/4444\r\n\r\nPlease review and merge",
reviewers: ["gh-user"],
assignees: [],
labels: [],
@ -351,7 +351,7 @@ describe("cli runner", () => {
"--body",
"New Body",
"--body-prefix",
"New Body Prefix - ",
"New Body Prefix\\r\\n\\r\\n",
"--bp-branch-name",
"bp_branch_name",
"--reviewers",
@ -389,7 +389,7 @@ describe("cli runner", () => {
head: "bp_branch_name",
base: "target",
title: "New Title",
body: "New Body Prefix - New Body",
body: "New Body Prefix\r\n\r\nNew Body",
reviewers: ["user1", "user2"],
assignees: ["user3", "user4"],
labels: [],
@ -495,7 +495,7 @@ describe("cli runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: ["cherry-pick :cherries:", "original-label"],
@ -543,7 +543,7 @@ describe("cli runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: ["first-label", "second-label"],
@ -634,7 +634,7 @@ describe("cli runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -681,7 +681,7 @@ describe("cli runner", () => {
head: "bp-target-0404fb9-11da4e3",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"),
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -734,7 +734,7 @@ describe("cli runner", () => {
head: truncatedBranch,
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -785,7 +785,7 @@ describe("cli runner", () => {
head: "bp-target-0404fb9-11da4e3",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"),
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -801,7 +801,9 @@ describe("cli runner", () => {
"-pr",
"https://github.com/owner/reponame/pull/8632",
"--comments",
"first comment; second comment"
"first comment; second comment",
"--body",
"New body"
]);
await runner.execute();
@ -832,7 +834,7 @@ describe("cli runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"),
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nNew body",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],

View file

@ -121,7 +121,7 @@ describe("gha runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -174,7 +174,7 @@ describe("gha runner", () => {
head: "bp-target-9174896",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/4444"),
body: "**Backport:** https://github.com/owner/reponame/pull/4444\r\n\r\nPlease review and merge",
reviewers: ["gh-user"],
assignees: [],
labels: [],
@ -189,7 +189,7 @@ describe("gha runner", () => {
"pull-request": "https://github.com/owner/reponame/pull/2368",
"title": "New Title",
"body": "New Body",
"body-prefix": "New Body Prefix - ",
"body-prefix": "New Body Prefix\\r\\n\\r\\n",
"bp-branch-name": "bp_branch_name",
"reviewers": "user1, user2",
"assignees": "user3, user4",
@ -224,7 +224,7 @@ describe("gha runner", () => {
head: "bp_branch_name",
base: "target",
title: "New Title",
body: "New Body Prefix - New Body",
body: "New Body Prefix\r\n\r\nNew Body",
reviewers: ["user1", "user2"],
assignees: ["user3", "user4"],
labels: [],
@ -321,7 +321,7 @@ describe("gha runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: ["cherry-pick :cherries:", "another-label", "original-label"],
@ -367,7 +367,7 @@ describe("gha runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: ["cherry-pick :cherries:", "another-label"],
@ -455,7 +455,7 @@ describe("gha runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -500,7 +500,7 @@ describe("gha runner", () => {
head: "bp-target-0404fb9-11da4e3",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/8632"),
body: "**Backport:** https://github.com/owner/reponame/pull/8632\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -546,7 +546,7 @@ describe("gha runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],
@ -591,7 +591,7 @@ describe("gha runner", () => {
head: "bp-target-28f63db",
base: "target",
title: "[target] PR Title",
body: expect.stringContaining("**Backport:** https://github.com/owner/reponame/pull/2368"),
body: "**Backport:** https://github.com/owner/reponame/pull/2368\r\n\r\nPlease review and merge",
reviewers: ["gh-user", "that-s-a-user"],
assignees: [],
labels: [],