Skip to content

Commit

Permalink
Adding an option for custom branch name for backport (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah committed Jan 6, 2022
1 parent 7eb9608 commit 92a5714
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> => {
const baseToHead: Record<string, string> = {};

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -209,6 +213,7 @@ const backport = async ({
label: label!,
labels,
pullRequestNumber,
branchName,
});

if (Object.keys(backportBaseToHead).length === 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down

0 comments on commit 92a5714

Please sign in to comment.