From fd5b265716aa59811bd9d261cb0c3f5756d0f41f Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 18 Sep 2018 09:57:04 +0200 Subject: [PATCH] fix(github): catch branch deletion and throw --- lib/platform/github/storage.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/platform/github/storage.js b/lib/platform/github/storage.js index cd491ebb4f..ea0af7e914 100644 --- a/lib/platform/github/storage.js +++ b/lib/platform/github/storage.js @@ -348,10 +348,18 @@ class Storage { // Return the commit SHA for a branch async function getBranchCommit(branchName) { - const res = await get( - `repos/${config.repository}/git/refs/heads/${branchName}` - ); - return res.body.object.sha; + try { + const res = await get( + `repos/${config.repository}/git/refs/heads/${branchName}` + ); + return res.body.object.sha; + } catch (err) /* istanbul ignore next */ { + logger.debug({ err }, 'Error getting branch commit'); + if (err.statusCode === 404) { + throw new Error('repository-changed'); + } + throw err; + } } async function getCommitMessages() { -- GitLab