@@ -39647,6 +39647,8 @@ async function pushWithFallback(branchName, owner, repo, octokit) {
3964739647 core.info(`Regular push to '${branchName}' failed. Attempting to rebase on remote branch.`);
3964839648 }
3964939649 // Try pull --rebase then push
39650+ let rebaseErrorMsg = null;
39651+ let abortErrorMsg = null;
3965039652 try {
3965139653 await exec.exec("git", ["pull", "--rebase", "origin", branchName], {
3965239654 silent: false,
@@ -39655,28 +39657,43 @@ async function pushWithFallback(branchName, owner, repo, octokit) {
3965539657 core.info(`Successfully pushed to '${branchName}' after rebasing on remote changes.`);
3965639658 return true;
3965739659 }
39658- catch {
39659- core.info(`Rebase failed (likely due to merge conflicts). Aborting rebase.`);
39660+ catch (rebaseError) {
39661+ rebaseErrorMsg =
39662+ rebaseError instanceof Error
39663+ ? rebaseError.message
39664+ : "Unknown error";
39665+ core.info(`Rebase failed (likely due to merge conflicts): ${rebaseErrorMsg}. Aborting rebase.`);
3966039666 // Abort the rebase so the working tree is clean
3966139667 try {
3966239668 await exec.exec("git", ["rebase", "--abort"], { silent: true });
3966339669 }
39664- catch {
39665- // rebase --abort can fail if there's no rebase in progress, ignore
39670+ catch (abortError) {
39671+ abortErrorMsg =
39672+ abortError instanceof Error
39673+ ? abortError.message
39674+ : "Unknown error";
39675+ core.info(`rebase --abort failed: ${abortErrorMsg}. The working tree may be in an unexpected state.`);
3966639676 }
3966739677 }
3966839678 // Last resort: leave a comment on the existing PR
3966939679 const existingPRNumber = await prExists(owner, repo, branchName, octokit);
3967039680 if (existingPRNumber) {
3967139681 core.info(`Could not push to '${branchName}' due to conflicts. Leaving a comment on PR #${existingPRNumber}.`);
39682+ let commentBody = `⚠️ **Sync failed**: The latest \`fern api update\` detected changes, but they could not be pushed to this branch due to merge conflicts.\n\n` +
39683+ `**To resolve**, either:\n` +
39684+ `- Merge or close this PR so the next run creates a fresh one, or\n` +
39685+ `- Manually rebase this branch on \`${github.context.ref.replace("refs/heads/", "")}\` and re-run the workflow.`;
39686+ if (rebaseErrorMsg) {
39687+ commentBody += `\n\n**Rebase error:** \`${rebaseErrorMsg}\``;
39688+ }
39689+ if (abortErrorMsg) {
39690+ commentBody += `\n**Rebase abort error:** \`${abortErrorMsg}\` — the working tree may be in an unexpected state.`;
39691+ }
3967239692 await octokit.rest.issues.createComment({
3967339693 owner,
3967439694 repo,
3967539695 issue_number: existingPRNumber,
39676- body: `⚠️ **Sync failed**: The latest \`fern api update\` detected changes, but they could not be pushed to this branch due to merge conflicts.\n\n` +
39677- `**To resolve**, either:\n` +
39678- `- Merge or close this PR so the next run creates a fresh one, or\n` +
39679- `- Manually rebase this branch on \`${github.context.ref.replace("refs/heads/", "")}\` and re-run the workflow.`,
39696+ body: commentBody,
3968039697 });
3968139698 core.setFailed(`Failed to push changes to '${branchName}' due to conflicts. A comment has been left on PR #${existingPRNumber}.`);
3968239699 }
0 commit comments