diff --git a/lib/platform/bitbucket-server/index.js b/lib/platform/bitbucket-server/index.js index a4af93f7586f9a3b81bbfadcd24bb37b909ec8f1..c4fe76884f0dd315f8c7c5c90932e325d1ee02f1 100644 --- a/lib/platform/bitbucket-server/index.js +++ b/lib/platform/bitbucket-server/index.js @@ -490,13 +490,30 @@ async function createPr( id: `refs/heads/${base}`, }, }; - - const prInfoRes = await api.post( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ - config.repositorySlug - }/pull-requests`, - { body } - ); + let prInfoRes; + try { + prInfoRes = await api.post( + `/rest/api/1.0/projects/${config.projectKey}/repos/${ + config.repositorySlug + }/pull-requests`, + { body } + ); + } catch (err) /* istanbul ignore next */ { + if ( + err.body && + err.body.errors && + err.body.errors.length && + err.body.errors[0].exceptionName === + 'com.atlassian.bitbucket.pull.EmptyPullRequestException' + ) { + logger.info( + 'Empty pull request - deleting branch so it can be recreated next run' + ); + await deleteBranch(branchName); + throw new Error('repository-changed'); + } + throw err; + } const pr = { id: prInfoRes.body.id,