diff --git a/action.yml b/action.yml index a6bbc3c..3434230 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,9 @@ inputs: add_labels: description: Comma separated list of labels to add to the backport PR. required: false + branch_name: + description: Custom branch name for backport PR. + required: false github_token: description: Token for the GitHub API. required: true 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)) {