From 2615786cd438e0001eb9610deb432f772d402159 Mon Sep 17 00:00:00 2001 From: Julien Bouyoud Date: Wed, 8 Feb 2023 12:07:10 +0100 Subject: [PATCH] feat(protected-branch): silently ignore ref not found when deleting --- plugins/protected-branch/src/index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/protected-branch/src/index.ts b/plugins/protected-branch/src/index.ts index e65305592..06af326d5 100644 --- a/plugins/protected-branch/src/index.ts +++ b/plugins/protected-branch/src/index.ts @@ -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({ @@ -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; + } + } }); } }