diff --git a/action.yml b/action.yml index cbe0c96..7b15b01 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 + files_to_skip: + description: Comma seperated list of files to be skipped from the backport + required: false branch_name: description: Custom branch name for the backport PR. required: false diff --git a/src/backport.ts b/src/backport.ts index afce466..25c28dd 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -94,6 +94,7 @@ const backportOnce = async ({ owner, repo, title, + filesToSkip, }: { base: string; body: string; @@ -104,6 +105,7 @@ const backportOnce = async ({ owner: string; repo: string; title: string; + filesToSkip: string[]; }) => { const git = async (...args: string[]) => { await exec("git", args, { cwd: repo }); @@ -112,7 +114,11 @@ const backportOnce = async ({ await git("switch", base); await git("switch", "--create", head); try { - await git("cherry-pick", "-x", commitToBackport); + await git("cherry-pick", "-x", "-n", commitToBackport); + if (filesToSkip) { + filesToSkip.forEach(file => await git("checkout", "HEAD", file)); + } + await git("commit", "--no-edit", "-s"); } catch (error: unknown) { await git("cherry-pick", "--abort"); throw error; @@ -239,6 +245,7 @@ const backport = async ({ }, titleTemplate, token, + filesToSkip, }: { branchName: string; deleteBranch: boolean; @@ -246,6 +253,7 @@ const backport = async ({ payload: EventPayloads.WebhookPayloadPullRequest; titleTemplate: string; token: string; + filesToSkip: string[]; }) => { if (!merged) { return; @@ -310,6 +318,7 @@ const backport = async ({ owner, repo, title, + filesToSkip, }); } catch (error: unknown) { if (!(error instanceof Error)) { diff --git a/src/get-files-to-skip.ts b/src/get-files-to-skip.ts new file mode 100644 index 0000000..3bb456b --- /dev/null +++ b/src/get-files-to-skip.ts @@ -0,0 +1,14 @@ +/** + * Get an array of files to be skipped from the backport PR. + * Filtering out empty strings. + */ +const getFilesToSkip = (input: string | undefined): string[] => { + if (input === undefined || input === "") { + return []; + } + + const files_to_skip = input.split(","); + return files_to_skip.map((v) => v.trim()).filter((v) => v !== ""); +}; + +export { getFilesToSkip }; diff --git a/src/index.ts b/src/index.ts index b3c3c81..c4ab8ee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { EventPayloads } from "@octokit/webhooks"; import { backport } from "./backport"; import { getLabelsToAdd } from "./get-labels-to-add"; +import { getFilesToSkip } from "./get-files-to-skip"; const run = async () => { try { @@ -14,6 +15,8 @@ const run = async () => { debug(JSON.stringify(context, undefined, 2)); const labelsInput = getInput("add_labels"); const labelsToAdd = getLabelsToAdd(labelsInput); + const filesInput = getInput("files_to_skip"); + const filesToSkip = getFilesToSkip(labelsInput); await backport({ branchName, deleteBranch, @@ -21,6 +24,7 @@ const run = async () => { payload: context.payload as EventPayloads.WebhookPayloadPullRequest, titleTemplate, token, + filesToSkip }); } catch (error: unknown) { if (typeof error !== "string" && !(error instanceof Error)) {