From 92a5714d1329b93a5d2cd846bc5b929c217ab5f1 Mon Sep 17 00:00:00 2001 From: Vacha Date: Wed, 5 Jan 2022 15:34:51 -0800 Subject: [PATCH] Adding an option for custom branch name for backport (#1) Signed-off-by: Vacha Shah --- action.yml | 3 +++ src/backport.ts | 7 ++++++- src/index.ts | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a6bbc3c..b690c5e 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,9 @@ inputs: description: Template for the title of the backport PR. required: false default: "[Backport {{base}}] {{originalTitle}}" + branch_name: + description: Custom branch name for backport PR. + required: false runs: using: node12 main: dist/index.js diff --git a/src/backport.ts b/src/backport.ts index 9b32881..5d0c7ed 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -31,11 +31,13 @@ const getBackportBaseToHead = ({ label, labels, pullRequestNumber, + branchName, }: { action: EventPayloads.WebhookPayloadPullRequest["action"]; label: { name: string }; labels: EventPayloads.WebhookPayloadPullRequest["pull_request"]["labels"]; pullRequestNumber: number; + branchName: string; }): Record => { const baseToHead: Record = {}; @@ -46,7 +48,7 @@ const getBackportBaseToHead = ({ const [ , base, - head = `backport-${pullRequestNumber}-to-${base}`, + head = (branchName != null) ? branchName : `backport-${pullRequestNumber}-to-${base}`, ] = matches; baseToHead[base] = head; } @@ -193,11 +195,13 @@ const backport = async ({ }, titleTemplate, token, + branchName, }: { labelsToAdd: string[]; payload: EventPayloads.WebhookPayloadPullRequest; titleTemplate: string; token: string; + branchName: string; }) => { if (merged !== true) { return; @@ -209,6 +213,7 @@ const backport = async ({ label: label!, labels, pullRequestNumber, + branchName, }); if (Object.keys(backportBaseToHead).length === 0) { diff --git a/src/index.ts b/src/index.ts index 196803d..2456562 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ const run = async () => { try { const token = getInput("github_token", { required: true }); const titleTemplate = getInput("title_template"); + const branchName = getInput("branch_name"); debug(JSON.stringify(context, undefined, 2)); const labelsInput = getInput("add_labels"); const labelsToAdd = getLabelsToAdd(labelsInput); @@ -17,6 +18,7 @@ const run = async () => { payload: context.payload as EventPayloads.WebhookPayloadPullRequest, titleTemplate, token, + branchName, }); } catch (error: unknown) { if (typeof error !== "string" && !(error instanceof Error)) {