Skip to content

Commit

Permalink
fix: don't fail on deleting non existent branch
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Dec 13, 2019
1 parent 10a735d commit 1e77d4b
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions packages/netlify-cms-backend-github/src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,22 +932,10 @@ export default class API {
async deleteUnpublishedEntry(collectionName, slug) {
const contentKey = this.generateContentKey(collectionName, slug);
const branchName = this.generateBranchName(contentKey);
return (
this.retrieveMetadata(contentKey)
.then(metadata => (metadata && metadata.pr ? this.closePR(metadata.pr) : Promise.resolve()))
.then(() => this.deleteBranch(branchName))
.then(() => this.deleteMetadata(contentKey))
// If the PR doesn't exist, then this has already been deleted -
// deletion should be idempotent, so we can consider this a
// success.
.catch(err => {
if (err.message === 'Reference does not exist') {
return Promise.resolve();
}
console.error(err);
return Promise.reject(err);
})
);
return this.retrieveMetadata(contentKey)
.then(metadata => (metadata && metadata.pr ? this.closePR(metadata.pr) : Promise.resolve()))
.then(() => this.deleteBranch(branchName))
.then(() => this.deleteMetadata(contentKey));
}

async publishUnpublishedEntry(collectionName, slug) {
Expand Down Expand Up @@ -1003,7 +991,16 @@ export default class API {
}

deleteBranch(branchName) {
return this.deleteRef('heads', branchName);
return this.deleteRef('heads', branchName).catch(err => {
// If the branch doesn't exist, then it has already been deleted -
// deletion should be idempotent, so we can consider this a
// success.
if (err.message === 'Reference does not exist') {
return Promise.resolve();
}
console.error(err);
return Promise.reject(err);
});
}

async createPR(title, head) {
Expand Down

0 comments on commit 1e77d4b

Please sign in to comment.