From 91be1678acb3a2b4e41355cfcd7dd0c112812f31 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 23 Jul 2020 12:43:06 +0200 Subject: [PATCH] refactor: targetBranch mandatory in platform.createPr (#6829) --- lib/platform/azure/index.spec.ts | 2 ++ lib/platform/azure/index.ts | 2 +- lib/platform/bitbucket-server/index.spec.ts | 2 ++ lib/platform/bitbucket-server/index.ts | 2 +- lib/platform/bitbucket/index.spec.ts | 1 + lib/platform/bitbucket/index.ts | 2 +- lib/platform/common.ts | 2 +- lib/platform/gitea/index.spec.ts | 6 ++++++ lib/platform/gitea/index.ts | 2 +- lib/platform/github/index.spec.ts | 2 ++ lib/platform/github/index.ts | 2 +- lib/platform/gitlab/__snapshots__/index.spec.ts.snap | 12 ++++++------ lib/platform/gitlab/index.spec.ts | 3 +++ lib/platform/gitlab/index.ts | 2 +- lib/workers/repository/error.ts | 2 +- lib/workers/repository/onboarding/pr/index.ts | 1 + 16 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/platform/azure/index.spec.ts b/lib/platform/azure/index.spec.ts index 3b464d0698..878668f1cf 100644 --- a/lib/platform/azure/index.spec.ts +++ b/lib/platform/azure/index.spec.ts @@ -500,6 +500,7 @@ describe('platform/azure', () => { ); const pr = await azure.createPr({ branchName: 'some-branch', + targetBranch: 'master', prTitle: 'The Title', prBody: 'Hello world', labels: ['deps', 'renovate'], @@ -528,6 +529,7 @@ describe('platform/azure', () => { ); const pr = await azure.createPr({ branchName: 'some-branch', + targetBranch: 'master', prTitle: 'The Title', prBody: 'Hello world', labels: ['deps', 'renovate'], diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 1c500fc994..184fb10ad7 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -336,7 +336,7 @@ export async function getBranchStatus( export async function createPr({ branchName, - targetBranch = config.defaultBranch, + targetBranch, prTitle: title, prBody: body, labels, diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index 697d935904..062e4976bb 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -1119,6 +1119,7 @@ describe(getName(__filename), () => { const { number: id } = await bitbucket.createPr({ branchName: 'branch', + targetBranch: 'master', prTitle: 'title', prBody: 'body', }); @@ -1142,6 +1143,7 @@ describe(getName(__filename), () => { const { number: id } = await bitbucket.createPr({ branchName: 'branch', + targetBranch: 'master', prTitle: 'title', prBody: 'body', labels: null, diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 813e9ee45b..e407724c29 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -794,7 +794,7 @@ const escapeHash = (input: string): string => export async function createPr({ branchName, - targetBranch = config.defaultBranch, + targetBranch, prTitle: title, prBody: rawDescription, }: CreatePRConfig): Promise<Pr> { diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index e33c5a82fb..04a7878af3 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -681,6 +681,7 @@ describe('platform/bitbucket', () => { .reply(200, { id: 5 }); const { number } = await bitbucket.createPr({ branchName: 'branch', + targetBranch: 'master', prTitle: 'title', prBody: 'body', }); diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 7b6583568e..65ee99b9c2 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -658,7 +658,7 @@ export function ensureCommentRemoval({ // Creates PR and returns PR number export async function createPr({ branchName, - targetBranch = config.defaultBranch, + targetBranch, prTitle: title, prBody: description, }: CreatePRConfig): Promise<Pr> { diff --git a/lib/platform/common.ts b/lib/platform/common.ts index d154ddf205..3cd7437755 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -72,7 +72,7 @@ export type PlatformPrOptions = { }; export interface CreatePRConfig { branchName: string; - targetBranch?: string; + targetBranch: string; prTitle: string; prBody: string; labels?: string[] | null; diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index a03e2c7f39..7d7cb2fe19 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -716,6 +716,7 @@ describe('platform/gitea', () => { await gitea.setBaseBranch('devel'); const res = await gitea.createPr({ branchName: mockNewPR.head.label, + targetBranch: 'master', prTitle: mockNewPR.title, prBody: mockNewPR.body, }); @@ -743,6 +744,7 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.createPr({ branchName: mockNewPR.head.label, + targetBranch: 'master', prTitle: mockNewPR.title, prBody: mockNewPR.body, labels: mockLabels.map((l) => l.name), @@ -766,6 +768,7 @@ describe('platform/gitea', () => { await gitea.getPrList(); await gitea.createPr({ branchName: mockNewPR.head.label, + targetBranch: 'master', prTitle: mockNewPR.title, prBody: mockNewPR.body, }); @@ -782,6 +785,7 @@ describe('platform/gitea', () => { await initFakeRepo(); const res = await gitea.createPr({ branchName: mockNewPR.head.label, + targetBranch: 'master', prTitle: mockNewPR.title, prBody: mockNewPR.body, }); @@ -796,6 +800,7 @@ describe('platform/gitea', () => { await initFakeRepo(); const res = await gitea.createPr({ branchName: mockNewPR.head.label, + targetBranch: 'master', prTitle: 'new-title', prBody: 'new-body', }); @@ -816,6 +821,7 @@ describe('platform/gitea', () => { await expect( gitea.createPr({ branchName: mockNewPR.head.label, + targetBranch: 'master', prTitle: mockNewPR.title, prBody: mockNewPR.body, }) diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index b38845c870..72053545cb 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -486,7 +486,7 @@ const platform: Platform = { async createPr({ branchName, - targetBranch = config.defaultBranch, + targetBranch, prTitle: title, prBody: rawBody, labels: labelNames, diff --git a/lib/platform/github/index.spec.ts b/lib/platform/github/index.spec.ts index 95397b73ef..1310d3bfeb 100644 --- a/lib/platform/github/index.spec.ts +++ b/lib/platform/github/index.spec.ts @@ -1620,6 +1620,7 @@ describe('platform/github', () => { await github.initRepo({ repository: 'some/repo', token: 'token' } as any); const pr = await github.createPr({ branchName: 'some-branch', + targetBranch: 'master', prTitle: 'The Title', prBody: 'Hello world', labels: null, @@ -1636,6 +1637,7 @@ describe('platform/github', () => { await github.initRepo({ repository: 'some/repo', token: 'token' } as any); const pr = await github.createPr({ branchName: 'some-branch', + targetBranch: 'master', prTitle: 'PR draft', prBody: 'This is a result of a draft', labels: null, diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 8d1b2c0be5..ade3fe6f4a 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -1407,7 +1407,7 @@ export async function ensureCommentRemoval({ // Creates PR and returns PR number export async function createPr({ branchName, - targetBranch = config.defaultBranch, + targetBranch, prTitle: title, prBody: rawBody, labels, diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index d18ffba7cd..918580ccc6 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -146,11 +146,11 @@ exports[`platform/gitlab addReviewers(issueNo, reviewers) should add the given r exports[`platform/gitlab createPr(branchName, title, body) auto-accepts the MR when requested 1`] = ` Array [ Object { - "body": "{\\"source_branch\\":\\"some-branch\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":\\"\\"}", + "body": "{\\"source_branch\\":\\"some-branch\\",\\"target_branch\\":\\"master\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":\\"\\"}", "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "content-length": "117", + "content-length": "142", "content-type": "application/json", "host": "gitlab.com", "private-token": "abc123", @@ -211,11 +211,11 @@ Object { exports[`platform/gitlab createPr(branchName, title, body) returns the PR 2`] = ` Array [ Object { - "body": "{\\"source_branch\\":\\"some-branch\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":null}", + "body": "{\\"source_branch\\":\\"some-branch\\",\\"target_branch\\":\\"master\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":null}", "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "content-length": "119", + "content-length": "144", "content-type": "application/json", "host": "gitlab.com", "private-token": "abc123", @@ -240,11 +240,11 @@ Object { exports[`platform/gitlab createPr(branchName, title, body) uses default branch 2`] = ` Array [ Object { - "body": "{\\"source_branch\\":\\"some-branch\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":\\"\\"}", + "body": "{\\"source_branch\\":\\"some-branch\\",\\"target_branch\\":\\"master\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":\\"\\"}", "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "content-length": "117", + "content-length": "142", "content-type": "application/json", "host": "gitlab.com", "private-token": "abc123", diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index e891e7ad3d..ca818f05ae 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -974,6 +974,7 @@ describe('platform/gitlab', () => { }); const pr = await gitlab.createPr({ branchName: 'some-branch', + targetBranch: 'master', prTitle: 'some-title', prBody: 'the-body', labels: null, @@ -991,6 +992,7 @@ describe('platform/gitlab', () => { }); const pr = await gitlab.createPr({ branchName: 'some-branch', + targetBranch: 'master', prTitle: 'some-title', prBody: 'the-body', labels: [], @@ -1022,6 +1024,7 @@ describe('platform/gitlab', () => { .reply(200); await gitlab.createPr({ branchName: 'some-branch', + targetBranch: 'master', prTitle: 'some-title', prBody: 'the-body', labels: [], diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 937b6e96b1..4d112fd047 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -356,7 +356,7 @@ export async function getBranchStatus( export async function createPr({ branchName, - targetBranch = config.defaultBranch, + targetBranch, prTitle: title, prBody: rawDescription, labels, diff --git a/lib/workers/repository/error.ts b/lib/workers/repository/error.ts index 469f4248fa..f0a39befbd 100644 --- a/lib/workers/repository/error.ts +++ b/lib/workers/repository/error.ts @@ -175,7 +175,7 @@ export default async function handleError( return EXTERNAL_HOST_ERROR; } if ( - err.message.includes('The remote end hung up unexpectedly') || + err.message.includes('remote end hung up unexpectedly') || err.message.includes('access denied or repository not exported') ) { logger.warn({ err }, 'Git error - aborting'); diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index ec720cc199..1ed8f339f5 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -128,6 +128,7 @@ If you need any further assistance then you can also [request help here](${confi } else { const pr = await platform.createPr({ branchName: config.onboardingBranch, + targetBranch: config.defaultBranch, prTitle: config.onboardingPrTitle, prBody, labels, -- GitLab