Skip to content

Commit 868b016

Browse files
committed
fix: log existing branch recovery
It's useful to explain what happens to the readers of the logs. In the case where the push of the backport branch failed, we attempt to recover a previous run by verifying that a branch with the same name already exists on the remote. If so, we can simply create a PR for it. It's possible that the remote branch does not contain the same contents, and we currently don't verify this. However, malicious actors would need write access to the repo to push such a branch anyways. So, this is not considered to be dangerous.
1 parent ba349a0 commit 868b016

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/backport.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,19 @@ export class Backport {
346346
if (pushExitCode != 0) {
347347
try {
348348
// If the branch already exists, ignore the error and keep going.
349+
console.info(
350+
`Branch ${branchname} may already exist, fetching it instead to recover previous run`,
351+
);
349352
await this.git.fetch(
350353
branchname,
351354
this.config.pwd,
352355
1,
353356
this.getRemote(),
354357
);
358+
console.info(
359+
`Previous branch successfully recovered, retrying PR creation`,
360+
);
361+
// note that the recovered branch is not guaranteed to be up-to-date
355362
} catch {
356363
// Fetching the branch failed as well, so report the original push error.
357364
const message = this.composeMessageForGitPushFailure(

0 commit comments

Comments
 (0)