From dd52e1f9ba62f5efb33c12570e65c96efb1c8477 Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Tue, 28 Nov 2023 17:31:24 +0100 Subject: [PATCH 1/8] add method to strip out test plan --- package.json | 2 +- src/backport.ts | 4 +++- src/utils.ts | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/utils.ts diff --git a/package.json b/package.json index 41e353f..d938885 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backport", - "version": "2.0.7", + "version": "2.0.8", "license": "MIT", "main": "dist/index.js", "files": [ diff --git a/src/backport.ts b/src/backport.ts index 8ed7156..1e0ccac 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -9,6 +9,8 @@ import type { import ensureError from "ensure-error"; import { compact } from "lodash-es"; +import { stripTestPlanFromPRBody } from "./utils"; + const getBaseBranchFromLabel = ( label: string, labelRegExp: RegExp, @@ -301,7 +303,7 @@ const backport = async ({ for (const base of baseBranches) { const body = getBody({ base, - body: originalBody ?? "", + body: originalBody ? stripTestPlanFromPRBody(originalBody) : "", mergeCommitSha, number, }); diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..13d37bc --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,16 @@ +export function stripTestPlanFromPRBody(body: string): string { + const startDelimiter = ''; + + let startIndex = body.indexOf(startDelimiter); + if (startIndex === -1) { + return body; + } + + let endIndex = body.indexOf(endDelimiter, startIndex + startDelimiter.length); + if (endIndex === -1) { + return body; + } + + return body.slice(0, startIndex) + body.slice(endIndex + endDelimiter.length); +}; From 45df4cabc08ffabcb08cbb5a79a2287aa2f7d6ea Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Tue, 28 Nov 2023 18:00:59 +0100 Subject: [PATCH 2/8] switch to regex-based replace --- src/utils.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 13d37bc..320993e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,16 +1,3 @@ export function stripTestPlanFromPRBody(body: string): string { - const startDelimiter = ''; - - let startIndex = body.indexOf(startDelimiter); - if (startIndex === -1) { - return body; - } - - let endIndex = body.indexOf(endDelimiter, startIndex + startDelimiter.length); - if (endIndex === -1) { - return body; - } - - return body.slice(0, startIndex) + body.slice(endIndex + endDelimiter.length); + return body.replace(//g, ''); }; From 7e1e612a1ec781501aa5610c7a5aabd941065683 Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Wed, 29 Nov 2023 15:17:56 +0100 Subject: [PATCH 3/8] Empty commit From 3a965748c4d2d5748d40654ca1c21265d88f7618 Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Wed, 29 Nov 2023 15:24:06 +0100 Subject: [PATCH 4/8] fix import path --- src/backport.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backport.ts b/src/backport.ts index 1e0ccac..a8b18d6 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -9,7 +9,7 @@ import type { import ensureError from "ensure-error"; import { compact } from "lodash-es"; -import { stripTestPlanFromPRBody } from "./utils"; +import { stripTestPlanFromPRBody } from "./utils.js"; const getBaseBranchFromLabel = ( label: string, From d8cff32061ed92662d423024ef424d6859a7fe50 Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Wed, 29 Nov 2023 15:26:35 +0100 Subject: [PATCH 5/8] lint --- src/backport.ts | 2 +- src/index.ts | 4 ++-- src/utils.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backport.ts b/src/backport.ts index a8b18d6..ca961b2 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -303,7 +303,7 @@ const backport = async ({ for (const base of baseBranches) { const body = getBody({ base, - body: originalBody ? stripTestPlanFromPRBody(originalBody) : "", + body: originalBody ? stripTestPlanFromPRBody(originalBody) : "", mergeCommitSha, number, }); diff --git a/src/index.ts b/src/index.ts index bc3c1db..6c27614 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ const run = async () => { } const payload = context.payload as PullRequestEvent; - const runId = context.runId; + const runId = context.runId; const serverUrl = context.serverUrl; if (payload.action !== "closed" && payload.action !== "labeled") { @@ -31,7 +31,7 @@ const run = async () => { `Unsupported pull request event action: ${payload.action}.`, ); } - + const createdPullRequestBaseBranchToNumber = await backport({ getBody, getHead, diff --git a/src/utils.ts b/src/utils.ts index 320993e..0b66a15 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,3 @@ export function stripTestPlanFromPRBody(body: string): string { - return body.replace(//g, ''); -}; + return body.replace(//g, ""); +} From f2d995cd12547d7ae331b54bf1abe8645e38a8a2 Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Wed, 29 Nov 2023 15:27:41 +0100 Subject: [PATCH 6/8] fix import order --- src/backport.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backport.ts b/src/backport.ts index ca961b2..30e7723 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -8,7 +8,6 @@ import type { } from "@octokit/webhooks-types"; import ensureError from "ensure-error"; import { compact } from "lodash-es"; - import { stripTestPlanFromPRBody } from "./utils.js"; const getBaseBranchFromLabel = ( From 9f43e17af0cf3d33a32f158a4cce01df27466c9a Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Wed, 29 Nov 2023 15:28:59 +0100 Subject: [PATCH 7/8] change to arrow func --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 0b66a15..8309caa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,3 @@ -export function stripTestPlanFromPRBody(body: string): string { +export const stripTestPlanFromPRBody = (body: string): string => { return body.replace(//g, ""); } From ec27057c852aedd23d6094b2314f36f71eefa40d Mon Sep 17 00:00:00 2001 From: BolajiOlajide Date: Wed, 29 Nov 2023 15:30:31 +0100 Subject: [PATCH 8/8] jeeeez --- src/utils.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 8309caa..475e242 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,2 @@ -export const stripTestPlanFromPRBody = (body: string): string => { - return body.replace(//g, ""); -} +export const stripTestPlanFromPRBody = (body: string): string => + body.replace(//g, "");