Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment support for file_to_skip for visibility #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
43 changes: 39 additions & 4 deletions src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this not change the behavior for filesToSkip?

/* 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) {
Expand Down Expand Up @@ -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,
Expand Down
Loading