From 83e0383b690fb452ea40cb165a56f65a695dc83c Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Tue, 25 Feb 2020 16:25:37 -0500 Subject: [PATCH] fix(backend-github): fail workflow migrations gracefully (#3325) * fix(backend-github): fail workflow migrations gracefully * fix: formatting --- packages/netlify-cms-backend-github/src/API.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/netlify-cms-backend-github/src/API.ts b/packages/netlify-cms-backend-github/src/API.ts index 38ef55fa..aa92c650 100644 --- a/packages/netlify-cms-backend-github/src/API.ts +++ b/packages/netlify-cms-backend-github/src/API.ts @@ -680,6 +680,7 @@ export default class API { if (!branch) { await this.createBranch(newBranchName, pullRequest.head.sha as string); } + const pr = (await this.getPullRequests(newBranchName, PullRequestState.All, () => true))[0] || (await this.createPR(pullRequest.title, newBranchName)); @@ -725,7 +726,13 @@ export default class API { if (!metadata.version) { console.log(`Migrating Pull Request '${number}' to version 1`); // migrate branch from cms/slug to cms/collection/slug - ({ metadata, pullRequest } = await this.migrateToVersion1(pullRequest, metadata)); + try { + ({ metadata, pullRequest } = await this.migrateToVersion1(pullRequest, metadata)); + } catch (e) { + console.log(`Failed to migrate Pull Request '${number}' to version 1. See error below.`); + console.error(e); + return; + } newNumber = pullRequest.number; console.log( `Done migrating Pull Request '${number}' to version 1. New pull request '${newNumber}' created.`,