Skip to content

Commit

Permalink
feat(protected-branch): silently ignore ref not found when deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
jBouyoud committed Feb 8, 2023
1 parent 730d185 commit 2615786
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions plugins/protected-branch/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Auto, IPlugin, validatePluginConfiguration } from "@auto-it/core";
import * as t from "io-ts";
import { RequestError } from "@octokit/request-error";
import { GitOperator } from "./GitOperator";

const pluginOptions = t.partial({
Expand Down Expand Up @@ -111,11 +112,18 @@ export default class ProtectedBranchPlugin implements IPlugin {

auto.logger.log.info("Delete release branch 🗑️ ");

await auto.git.github.git.deleteRef({
owner: auto.git.options.owner,
repo: auto.git.options.repo,
ref: `heads/${headBranch}`,
});
try {
await auto.git.github.git.deleteRef({
owner: auto.git.options.owner,
repo: auto.git.options.repo,
ref: `heads/${headBranch}`,
});
} catch (e) {
// Silently ignore reference not found error since the ref might already be deleted
if (!e || e.status !== 422 || e.message !== "Reference does not exist") {
throw e;
}
}
});
}
}

0 comments on commit 2615786

Please sign in to comment.