From bc35e741c27921853f09070174530bc93d176d4f Mon Sep 17 00:00:00 2001 From: Kunal Kotwani Date: Wed, 10 Apr 2024 11:32:28 -0700 Subject: [PATCH] Add comment support for file_to_skip for visibility Signed-off-by: Kunal Kotwani --- CHANGELOG.md | 4 ++++ src/backport.ts | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c86c08..a647958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.3.0 (4/10/2024) + +- Add comment support for file_to_skip for visibility ([#13](https://github.com/VachaShah/backport/pull/13)) + # 2.1.0 (10/28/2022) - Put worktree outside of repo in manual steps ([#5](https://github.com/VachaShah/backport/pull/5)) diff --git a/src/backport.ts b/src/backport.ts index e2e456a..f90bb7b 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -104,6 +104,7 @@ const backportOnce = async ({ await git("switch", base); await git("switch", "--create", head); + let partialBackport = false; try { try { await git("cherry-pick", "-x", "-n", commitSha); @@ -112,17 +113,20 @@ const backportOnce = async ({ logError( "Possibly a conflict error. Trying to skip possible conflict files. ", ); + partialBackport = true; console.log(error.message); } else { console.log("Unexpected error", error); } } - /* eslint-disable no-await-in-loop */ - for (const file of filesToSkip) { - await git("checkout", "HEAD", file); + if (partialBackport) { + /* eslint-disable no-await-in-loop */ + for (const file of filesToSkip) { + await git("checkout", "HEAD", file); + } + /* eslint-enable no-await-in-loop */ } - /* eslint-enable no-await-in-loop */ await git("commit", "--no-edit", "-s"); } catch (error: unknown) { @@ -153,10 +157,41 @@ const backportOnce = async ({ ); } + if (partialBackport) { + await github.request( + "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", + { + body: getPartialBackportCommentBody({ + base, + filesToSkip, + }), + issue_number: number, + owner, + repo, + }, + ); + } + info(`PR #${number} has been created.`); return number; }; +const getPartialBackportCommentBody = ({ + base, + filesToSkip, +}: { + base: string; + filesToSkip: string[]; +}) => { + return [ + `This backport to \`${base}\` skipped certain files:`, + "```", + filesToSkip.join(","), + "```", + "Please manually backport these files to the PR if needed.", + ].join("\n"); +}; + const getFailedBackportCommentBody = ({ base, commitSha,