From 3d9fe3c7d9800af55a045fc62f481b9c2295de08 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Wed, 8 Mar 2023 18:54:36 +0530 Subject: [PATCH 1/3] change baseBranch on update --- lib/modules/platform/azure/index.spec.ts | 4 ++ lib/modules/platform/azure/index.ts | 5 +- .../platform/bitbucket-server/index.spec.ts | 33 ++++++++++-- .../platform/bitbucket-server/index.ts | 5 ++ lib/modules/platform/bitbucket/index.spec.ts | 50 ++++++++++++++++--- lib/modules/platform/bitbucket/index.ts | 12 ++++- lib/modules/platform/codecommit/index.spec.ts | 5 ++ lib/modules/platform/codecommit/index.ts | 1 + lib/modules/platform/gitea/index.spec.ts | 9 +++- lib/modules/platform/gitea/index.ts | 3 ++ lib/modules/platform/gitea/types.ts | 2 +- lib/modules/platform/github/index.spec.ts | 2 + lib/modules/platform/github/index.ts | 2 + lib/modules/platform/gitlab/index.spec.ts | 22 ++++++-- lib/modules/platform/gitlab/index.ts | 2 + lib/modules/platform/types.ts | 1 + .../repository/config-migration/pr/index.ts | 1 + lib/workers/repository/error-config.ts | 1 + lib/workers/repository/finalise/prune.ts | 2 + lib/workers/repository/onboarding/pr/index.ts | 1 + lib/workers/repository/update/pr/index.ts | 3 +- .../repository/update/pr/pr-fingerprint.ts | 2 + 22 files changed, 149 insertions(+), 19 deletions(-) diff --git a/lib/modules/platform/azure/index.spec.ts b/lib/modules/platform/azure/index.spec.ts index 0767c3157ba400..29442a39475cde 100644 --- a/lib/modules/platform/azure/index.spec.ts +++ b/lib/modules/platform/azure/index.spec.ts @@ -808,6 +808,7 @@ describe('modules/platform/azure/index', () => { number: 1234, prTitle: 'The New Title', prBody: 'Hello world again', + targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); @@ -824,6 +825,7 @@ describe('modules/platform/azure/index', () => { await azure.updatePr({ number: 1234, prTitle: 'The New Title - autoclose', + targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); @@ -842,6 +844,7 @@ describe('modules/platform/azure/index', () => { prTitle: 'The New Title', prBody: 'Hello world again', state: 'closed', + targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); @@ -860,6 +863,7 @@ describe('modules/platform/azure/index', () => { prTitle: 'The New Title', prBody: 'Hello world again', state: 'open', + targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); diff --git a/lib/modules/platform/azure/index.ts b/lib/modules/platform/azure/index.ts index e20acd9cf72f3d..b67f10cda81617 100644 --- a/lib/modules/platform/azure/index.ts +++ b/lib/modules/platform/azure/index.ts @@ -490,12 +490,15 @@ export async function updatePr({ prTitle: title, prBody: body, state, + targetBranch, }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); const azureApiGit = await azureApi.gitApi(); + const targetRefName = getNewBranchName(targetBranch); const objToUpdate: GitPullRequest = { title, + targetRefName, }; if (body) { @@ -504,7 +507,7 @@ export async function updatePr({ if (state === 'open') { await azureApiGit.updatePullRequest( - { status: PullRequestStatus.Active }, + { status: PullRequestStatus.Active, targetRefName }, config.repoId, prNo ); diff --git a/lib/modules/platform/bitbucket-server/index.spec.ts b/lib/modules/platform/bitbucket-server/index.spec.ts index 7b9b5a346321fa..3d59c9e185a797 100644 --- a/lib/modules/platform/bitbucket-server/index.spec.ts +++ b/lib/modules/platform/bitbucket-server/index.spec.ts @@ -1417,6 +1417,7 @@ describe('modules/platform/bitbucket-server/index', () => { number: 5, prTitle: 'title', prBody: 'body', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1443,6 +1444,7 @@ describe('modules/platform/bitbucket-server/index', () => { prTitle: 'title', prBody: 'body', state: 'closed', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1469,6 +1471,7 @@ describe('modules/platform/bitbucket-server/index', () => { prTitle: 'title', prBody: 'body', state: 'open', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1480,6 +1483,7 @@ describe('modules/platform/bitbucket-server/index', () => { number: null as any, prTitle: 'title', prBody: 'body', + targetBranch: 'target_branch', }) ).rejects.toThrow(REPOSITORY_NOT_FOUND); }); @@ -1492,7 +1496,12 @@ describe('modules/platform/bitbucket-server/index', () => { ) .reply(404); await expect( - bitbucket.updatePr({ number: 4, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 4, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrow(REPOSITORY_NOT_FOUND); }); @@ -1509,7 +1518,12 @@ describe('modules/platform/bitbucket-server/index', () => { .reply(404); await expect( - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrow(REPOSITORY_NOT_FOUND); }); @@ -1558,6 +1572,7 @@ describe('modules/platform/bitbucket-server/index', () => { prTitle: 'title', prBody: 'body', state: 'open', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1575,7 +1590,12 @@ describe('modules/platform/bitbucket-server/index', () => { .reply(409); await expect( - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrow(REPOSITORY_CHANGED); }); @@ -1592,7 +1612,12 @@ describe('modules/platform/bitbucket-server/index', () => { .reply(405); await expect( - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrowErrorMatchingSnapshot(); }); }); diff --git a/lib/modules/platform/bitbucket-server/index.ts b/lib/modules/platform/bitbucket-server/index.ts index acdc8bd71fce18..ce049614b1415c 100644 --- a/lib/modules/platform/bitbucket-server/index.ts +++ b/lib/modules/platform/bitbucket-server/index.ts @@ -851,6 +851,7 @@ export async function updatePr({ prBody: rawDescription, state, bitbucketInvalidReviewers, + targetBranch, }: UpdatePrConfig & { bitbucketInvalidReviewers: string[] | undefined; }): Promise { @@ -878,6 +879,9 @@ export async function updatePr({ (name: string) => !bitbucketInvalidReviewers?.includes(name) ) .map((name: string) => ({ user: { name } })), + toRef: { + id: `refs/heads/${targetBranch}`, + }, }, } ); @@ -919,6 +923,7 @@ export async function updatePr({ prBody: rawDescription, state, bitbucketInvalidReviewers: invalidReviewers, + targetBranch, }); } else { throw new Error(REPOSITORY_CHANGED); diff --git a/lib/modules/platform/bitbucket/index.spec.ts b/lib/modules/platform/bitbucket/index.spec.ts index 6007fe9fdbcdcc..6b7b2e1cb2d036 100644 --- a/lib/modules/platform/bitbucket/index.spec.ts +++ b/lib/modules/platform/bitbucket/index.spec.ts @@ -1080,7 +1080,12 @@ describe('modules/platform/bitbucket/index', () => { .put('/2.0/repositories/some/repo/pullrequests/5') .reply(200); await expect( - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).toResolve(); }); @@ -1143,7 +1148,12 @@ describe('modules/platform/bitbucket/index', () => { .put('/2.0/repositories/some/repo/pullrequests/5') .reply(200); await expect( - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).toResolve(); }); @@ -1187,7 +1197,12 @@ describe('modules/platform/bitbucket/index', () => { .reply(200); await expect( - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).toResolve(); }); @@ -1219,7 +1234,12 @@ describe('modules/platform/bitbucket/index', () => { ) .reply(401); await expect(() => - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrow(new Error('Response code 401 (Unauthorized)')); }); @@ -1244,7 +1264,12 @@ describe('modules/platform/bitbucket/index', () => { }, }); await expect(() => - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrowErrorMatchingSnapshot(); }); @@ -1269,7 +1294,12 @@ describe('modules/platform/bitbucket/index', () => { }, }); await expect(() => - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrow(new Error('Response code 400 (Bad Request)')); }); @@ -1279,7 +1309,12 @@ describe('modules/platform/bitbucket/index', () => { .get('/2.0/repositories/some/repo/pullrequests/5') .reply(500, undefined); await expect(() => - bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) + bitbucket.updatePr({ + number: 5, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).rejects.toThrowErrorMatchingSnapshot(); }); @@ -1298,6 +1333,7 @@ describe('modules/platform/bitbucket/index', () => { number: pr.id, prTitle: pr.title, state: 'closed', + targetBranch: 'target_branch', }) ).toBeUndefined(); }); diff --git a/lib/modules/platform/bitbucket/index.ts b/lib/modules/platform/bitbucket/index.ts index 9755dc18060d73..cb611b60b87ae9 100644 --- a/lib/modules/platform/bitbucket/index.ts +++ b/lib/modules/platform/bitbucket/index.ts @@ -839,6 +839,7 @@ export async function updatePr({ prTitle: title, prBody: description, state, + targetBranch }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); // Updating a PR in Bitbucket will clear the reviewers if reviewers is not present @@ -856,7 +857,11 @@ export async function updatePr({ title, description: sanitize(description), reviewers: pr.reviewers, - }, + destination: { + branch: { + name: targetBranch, + }, + }, }, } ); } catch (err) { @@ -873,6 +878,11 @@ export async function updatePr({ title, description: sanitize(description), reviewers: sanitizedReviewers, + destination: { + branch: { + name: targetBranch, + }, + }, }, } ); diff --git a/lib/modules/platform/codecommit/index.spec.ts b/lib/modules/platform/codecommit/index.spec.ts index 6dfc43483ab9df..4f066ff7e2f464 100644 --- a/lib/modules/platform/codecommit/index.spec.ts +++ b/lib/modules/platform/codecommit/index.spec.ts @@ -698,6 +698,7 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'body', state: 'open', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -725,6 +726,7 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'new description', state: 'open', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -751,6 +753,7 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'new description', state: 'open', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -767,6 +770,7 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'body', state: 'open', + targetBranch: 'target_branch', }) ).toResolve(); }); @@ -781,6 +785,7 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'body', state: 'closed', + targetBranch: 'target_branch', }) ).toResolve(); }); diff --git a/lib/modules/platform/codecommit/index.ts b/lib/modules/platform/codecommit/index.ts index ed5a48fdfe8cdc..2a6699d7e0b09c 100644 --- a/lib/modules/platform/codecommit/index.ts +++ b/lib/modules/platform/codecommit/index.ts @@ -392,6 +392,7 @@ export async function updatePr({ prTitle: title, prBody: body, state, + targetBranch }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index 060c7e57b111ef..bdf61a46185a48 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -1185,7 +1185,11 @@ describe('modules/platform/gitea/index', () => { it('should update pull request with title', async () => { helper.searchPRs.mockResolvedValueOnce(mockPRs); await initFakeRepo(); - await gitea.updatePr({ number: 1, prTitle: 'New Title' }); + await gitea.updatePr({ + number: 1, + prTitle: 'New Title', + targetBranch: 'target_branch', + }); expect(helper.updatePR).toHaveBeenCalledTimes(1); expect(helper.updatePR).toHaveBeenCalledWith(mockRepo.full_name, 1, { @@ -1200,6 +1204,7 @@ describe('modules/platform/gitea/index', () => { number: 1, prTitle: 'New Title', prBody: 'New Body', + targetBranch: 'target_branch', }); expect(helper.updatePR).toHaveBeenCalledTimes(1); @@ -1216,6 +1221,7 @@ describe('modules/platform/gitea/index', () => { number: 3, prTitle: 'New Title', prBody: 'New Body', + targetBranch: 'target_branch', }); expect(helper.updatePR).toHaveBeenCalledTimes(1); @@ -1233,6 +1239,7 @@ describe('modules/platform/gitea/index', () => { prTitle: 'New Title', prBody: 'New Body', state: 'closed', + targetBranch: 'target_branch', }); expect(helper.updatePR).toHaveBeenCalledWith(mockRepo.full_name, 1, { diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index d650a6955104c0..a5c9ffecf60398 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -584,6 +584,7 @@ const platform: Platform = { number: pr.number, prTitle: title, prBody: body, + targetBranch }); pr.title = title; pr.bodyStruct = getPrBodyStruct(body); @@ -606,6 +607,7 @@ const platform: Platform = { prTitle, prBody: body, state, + targetBranch }: UpdatePrConfig): Promise { let title = prTitle; if ((await getPrList()).find((pr) => pr.number === number)?.isDraft) { @@ -616,6 +618,7 @@ const platform: Platform = { title, ...(body && { body }), ...(state && { state }), + base: targetBranch }); }, diff --git a/lib/modules/platform/gitea/types.ts b/lib/modules/platform/gitea/types.ts index de89f4f46a8765..bc6d78fc8cab8d 100644 --- a/lib/modules/platform/gitea/types.ts +++ b/lib/modules/platform/gitea/types.ts @@ -169,7 +169,6 @@ export interface IssueSearchParams { } export interface PRCreateParams extends PRUpdateParams { - base?: string; head?: string; } @@ -179,6 +178,7 @@ export interface PRUpdateParams { assignees?: string[]; labels?: number[]; state?: PRState; + base?: string; } export interface PRSearchParams { diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index acdf7859662641..782823e5a7b70a 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -2715,6 +2715,7 @@ describe('modules/platform/github/index', () => { number: 1234, prTitle: 'The New Title', prBody: 'Hello world again', + targetBranch: 'target_branch' }; const scope = httpMock.scope(githubApiHost); initRepoMock(scope, 'some/repo'); @@ -2730,6 +2731,7 @@ describe('modules/platform/github/index', () => { prTitle: 'The New Title', prBody: 'Hello world again', state: 'closed', + targetBranch: 'target_branch' }; const scope = httpMock.scope(githubApiHost); initRepoMock(scope, 'some/repo'); diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 7422d4a6ff93d0..23cc687096681d 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -1529,6 +1529,7 @@ export async function updatePr({ prTitle: title, prBody: rawBody, state, + targetBranch }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); const body = sanitize(rawBody); @@ -1541,6 +1542,7 @@ export async function updatePr({ } const options: any = { body: patchBody, + base: targetBranch }; // istanbul ignore if if (config.forkToken) { diff --git a/lib/modules/platform/gitlab/index.spec.ts b/lib/modules/platform/gitlab/index.spec.ts index 4a1fe03a7d9de0..e406e43a36e7d8 100644 --- a/lib/modules/platform/gitlab/index.spec.ts +++ b/lib/modules/platform/gitlab/index.spec.ts @@ -1981,7 +1981,12 @@ describe('modules/platform/gitlab/index', () => { .put('/api/v4/projects/undefined/merge_requests/1') .reply(200); await expect( - gitlab.updatePr({ number: 1, prTitle: 'title', prBody: 'body' }) + gitlab.updatePr({ + number: 1, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).toResolve(); }); @@ -2003,7 +2008,12 @@ describe('modules/platform/gitlab/index', () => { .put('/api/v4/projects/undefined/merge_requests/1') .reply(200); await expect( - gitlab.updatePr({ number: 1, prTitle: 'title', prBody: 'body' }) + gitlab.updatePr({ + number: 1, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).toResolve(); }); @@ -2025,7 +2035,12 @@ describe('modules/platform/gitlab/index', () => { .put('/api/v4/projects/undefined/merge_requests/1') .reply(200); await expect( - gitlab.updatePr({ number: 1, prTitle: 'title', prBody: 'body' }) + gitlab.updatePr({ + number: 1, + prTitle: 'title', + prBody: 'body', + targetBranch: 'target_branch', + }) ).toResolve(); }); @@ -2052,6 +2067,7 @@ describe('modules/platform/gitlab/index', () => { prTitle: 'title', prBody: 'body', state: 'closed', + targetBranch: 'target_branch', }) ).toResolve(); }); diff --git a/lib/modules/platform/gitlab/index.ts b/lib/modules/platform/gitlab/index.ts index cf41c134d7dddc..7f5f2bf0803d98 100644 --- a/lib/modules/platform/gitlab/index.ts +++ b/lib/modules/platform/gitlab/index.ts @@ -641,6 +641,7 @@ export async function updatePr({ prBody: description, state, platformOptions, + targetBranch, }: UpdatePrConfig): Promise { let title = prTitle; if ((await getPrList()).find((pr) => pr.number === iid)?.isDraft) { @@ -658,6 +659,7 @@ export async function updatePr({ title, description: sanitize(description), ...(newState && { state_event: newState }), + target_branch: targetBranch, }, } ); diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index 07272f44987eba..fb37a7cbe3fa72 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -105,6 +105,7 @@ export interface CreatePRConfig { } export interface UpdatePrConfig { number: number; + targetBranch: string; platformOptions?: PlatformPrOptions; prTitle: string; prBody?: string; diff --git a/lib/workers/repository/config-migration/pr/index.ts b/lib/workers/repository/config-migration/pr/index.ts index c24a1dd1aa472d..417965ef8b6a14 100644 --- a/lib/workers/repository/config-migration/pr/index.ts +++ b/lib/workers/repository/config-migration/pr/index.ts @@ -85,6 +85,7 @@ ${ number: existingPr.number, prTitle, prBody, + targetBranch: 'target_branch' }); logger.info({ pr: existingPr.number }, 'Migration PR updated'); } diff --git a/lib/workers/repository/error-config.ts b/lib/workers/repository/error-config.ts index 0fba9c00eefbbf..69cf34427a00da 100644 --- a/lib/workers/repository/error-config.ts +++ b/lib/workers/repository/error-config.ts @@ -34,6 +34,7 @@ export async function raiseConfigWarningIssue( number: pr.number, prTitle: config.onboardingPrTitle!, prBody: body, + targetBranch: 'target_branch', }); } catch (err) /* istanbul ignore next */ { logger.warn({ err }, 'Error updating onboarding PR'); diff --git a/lib/workers/repository/finalise/prune.ts b/lib/workers/repository/finalise/prune.ts index 3546ec41b746da..561955ff409a7c 100644 --- a/lib/workers/repository/finalise/prune.ts +++ b/lib/workers/repository/finalise/prune.ts @@ -37,6 +37,7 @@ async function cleanUpBranches( number: pr.number, prTitle: newPrTitle, state: 'open', + targetBranch: 'target_branch', }); } @@ -65,6 +66,7 @@ async function cleanUpBranches( number: pr.number, prTitle: newPrTitle, state: 'closed', + targetBranch: 'target_branch', }); await scm.deleteBranch(branchName); } diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index d1d7ce2b71422e..d0360bc7ea34a8 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -153,6 +153,7 @@ If you need any further assistance then you can also [request help here](${ number: existingPr.number, prTitle: existingPr.title, prBody, + targetBranch: 'target_branch', }); logger.info({ pr: existingPr.number }, 'Onboarding PR updated'); } diff --git a/lib/workers/repository/update/pr/index.ts b/lib/workers/repository/update/pr/index.ts index db1e0cbe9277a4..785794b6adc72c 100644 --- a/lib/workers/repository/update/pr/index.ts +++ b/lib/workers/repository/update/pr/index.ts @@ -321,7 +321,7 @@ export async function ensurePr( existingPrTitle === newPrTitle && existingPrBodyHash === newPrBodyHash ) { - // adds or-cache for existing PRs + // adds pr-cache for existing PRs setPrCache(branchName, prFingerprint, false); logger.debug( `Pull Request #${existingPr.number} does not need updating` @@ -350,6 +350,7 @@ export async function ensurePr( logger.info(`DRY-RUN: Would update PR #${existingPr.number}`); } else { await platform.updatePr({ + targetBranch: config.baseBranch ?? '', number: existingPr.number, prTitle, prBody, diff --git a/lib/workers/repository/update/pr/pr-fingerprint.ts b/lib/workers/repository/update/pr/pr-fingerprint.ts index 62a5878e14fc1c..0556ff093a4045 100644 --- a/lib/workers/repository/update/pr/pr-fingerprint.ts +++ b/lib/workers/repository/update/pr/pr-fingerprint.ts @@ -41,6 +41,7 @@ export interface PrFingerprintConfig { pendingVersions?: string[]; filteredUpgrades?: FilteredBranchUpgradeConfig[]; + baseBranch?: string; } export function generatePrFingerprintConfig( @@ -76,6 +77,7 @@ export function generatePrFingerprintConfig( updateType: config.updateType, warnings: config.warnings, pendingVersions: config.pendingVersions, + baseBranch: config.baseBranch, }; } From d3bc572b9778b3f6127a8e4fe56e335e469088f6 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 9 Mar 2023 02:50:23 +0530 Subject: [PATCH 2/3] Revert "change baseBranch on update" This reverts commit 3d9fe3c7d9800af55a045fc62f481b9c2295de08. --- lib/modules/platform/azure/index.spec.ts | 4 -- lib/modules/platform/azure/index.ts | 5 +- .../platform/bitbucket-server/index.spec.ts | 33 ++---------- .../platform/bitbucket-server/index.ts | 5 -- lib/modules/platform/bitbucket/index.spec.ts | 50 +++---------------- lib/modules/platform/bitbucket/index.ts | 12 +---- lib/modules/platform/codecommit/index.spec.ts | 5 -- lib/modules/platform/codecommit/index.ts | 1 - lib/modules/platform/gitea/index.spec.ts | 9 +--- lib/modules/platform/gitea/index.ts | 3 -- lib/modules/platform/gitea/types.ts | 2 +- lib/modules/platform/github/index.spec.ts | 2 - lib/modules/platform/github/index.ts | 2 - lib/modules/platform/gitlab/index.spec.ts | 22 ++------ lib/modules/platform/gitlab/index.ts | 2 - lib/modules/platform/types.ts | 1 - .../repository/config-migration/pr/index.ts | 1 - lib/workers/repository/error-config.ts | 1 - lib/workers/repository/finalise/prune.ts | 2 - lib/workers/repository/onboarding/pr/index.ts | 1 - lib/workers/repository/update/pr/index.ts | 3 +- .../repository/update/pr/pr-fingerprint.ts | 2 - 22 files changed, 19 insertions(+), 149 deletions(-) diff --git a/lib/modules/platform/azure/index.spec.ts b/lib/modules/platform/azure/index.spec.ts index 29442a39475cde..0767c3157ba400 100644 --- a/lib/modules/platform/azure/index.spec.ts +++ b/lib/modules/platform/azure/index.spec.ts @@ -808,7 +808,6 @@ describe('modules/platform/azure/index', () => { number: 1234, prTitle: 'The New Title', prBody: 'Hello world again', - targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); @@ -825,7 +824,6 @@ describe('modules/platform/azure/index', () => { await azure.updatePr({ number: 1234, prTitle: 'The New Title - autoclose', - targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); @@ -844,7 +842,6 @@ describe('modules/platform/azure/index', () => { prTitle: 'The New Title', prBody: 'Hello world again', state: 'closed', - targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); @@ -863,7 +860,6 @@ describe('modules/platform/azure/index', () => { prTitle: 'The New Title', prBody: 'Hello world again', state: 'open', - targetBranch: 'target_branch', }); expect(updatePullRequest.mock.calls).toMatchSnapshot(); }); diff --git a/lib/modules/platform/azure/index.ts b/lib/modules/platform/azure/index.ts index b67f10cda81617..e20acd9cf72f3d 100644 --- a/lib/modules/platform/azure/index.ts +++ b/lib/modules/platform/azure/index.ts @@ -490,15 +490,12 @@ export async function updatePr({ prTitle: title, prBody: body, state, - targetBranch, }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); const azureApiGit = await azureApi.gitApi(); - const targetRefName = getNewBranchName(targetBranch); const objToUpdate: GitPullRequest = { title, - targetRefName, }; if (body) { @@ -507,7 +504,7 @@ export async function updatePr({ if (state === 'open') { await azureApiGit.updatePullRequest( - { status: PullRequestStatus.Active, targetRefName }, + { status: PullRequestStatus.Active }, config.repoId, prNo ); diff --git a/lib/modules/platform/bitbucket-server/index.spec.ts b/lib/modules/platform/bitbucket-server/index.spec.ts index 3d59c9e185a797..7b9b5a346321fa 100644 --- a/lib/modules/platform/bitbucket-server/index.spec.ts +++ b/lib/modules/platform/bitbucket-server/index.spec.ts @@ -1417,7 +1417,6 @@ describe('modules/platform/bitbucket-server/index', () => { number: 5, prTitle: 'title', prBody: 'body', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1444,7 +1443,6 @@ describe('modules/platform/bitbucket-server/index', () => { prTitle: 'title', prBody: 'body', state: 'closed', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1471,7 +1469,6 @@ describe('modules/platform/bitbucket-server/index', () => { prTitle: 'title', prBody: 'body', state: 'open', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1483,7 +1480,6 @@ describe('modules/platform/bitbucket-server/index', () => { number: null as any, prTitle: 'title', prBody: 'body', - targetBranch: 'target_branch', }) ).rejects.toThrow(REPOSITORY_NOT_FOUND); }); @@ -1496,12 +1492,7 @@ describe('modules/platform/bitbucket-server/index', () => { ) .reply(404); await expect( - bitbucket.updatePr({ - number: 4, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 4, prTitle: 'title', prBody: 'body' }) ).rejects.toThrow(REPOSITORY_NOT_FOUND); }); @@ -1518,12 +1509,7 @@ describe('modules/platform/bitbucket-server/index', () => { .reply(404); await expect( - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).rejects.toThrow(REPOSITORY_NOT_FOUND); }); @@ -1572,7 +1558,6 @@ describe('modules/platform/bitbucket-server/index', () => { prTitle: 'title', prBody: 'body', state: 'open', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -1590,12 +1575,7 @@ describe('modules/platform/bitbucket-server/index', () => { .reply(409); await expect( - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).rejects.toThrow(REPOSITORY_CHANGED); }); @@ -1612,12 +1592,7 @@ describe('modules/platform/bitbucket-server/index', () => { .reply(405); await expect( - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).rejects.toThrowErrorMatchingSnapshot(); }); }); diff --git a/lib/modules/platform/bitbucket-server/index.ts b/lib/modules/platform/bitbucket-server/index.ts index ce049614b1415c..acdc8bd71fce18 100644 --- a/lib/modules/platform/bitbucket-server/index.ts +++ b/lib/modules/platform/bitbucket-server/index.ts @@ -851,7 +851,6 @@ export async function updatePr({ prBody: rawDescription, state, bitbucketInvalidReviewers, - targetBranch, }: UpdatePrConfig & { bitbucketInvalidReviewers: string[] | undefined; }): Promise { @@ -879,9 +878,6 @@ export async function updatePr({ (name: string) => !bitbucketInvalidReviewers?.includes(name) ) .map((name: string) => ({ user: { name } })), - toRef: { - id: `refs/heads/${targetBranch}`, - }, }, } ); @@ -923,7 +919,6 @@ export async function updatePr({ prBody: rawDescription, state, bitbucketInvalidReviewers: invalidReviewers, - targetBranch, }); } else { throw new Error(REPOSITORY_CHANGED); diff --git a/lib/modules/platform/bitbucket/index.spec.ts b/lib/modules/platform/bitbucket/index.spec.ts index 6b7b2e1cb2d036..6007fe9fdbcdcc 100644 --- a/lib/modules/platform/bitbucket/index.spec.ts +++ b/lib/modules/platform/bitbucket/index.spec.ts @@ -1080,12 +1080,7 @@ describe('modules/platform/bitbucket/index', () => { .put('/2.0/repositories/some/repo/pullrequests/5') .reply(200); await expect( - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).toResolve(); }); @@ -1148,12 +1143,7 @@ describe('modules/platform/bitbucket/index', () => { .put('/2.0/repositories/some/repo/pullrequests/5') .reply(200); await expect( - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).toResolve(); }); @@ -1197,12 +1187,7 @@ describe('modules/platform/bitbucket/index', () => { .reply(200); await expect( - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).toResolve(); }); @@ -1234,12 +1219,7 @@ describe('modules/platform/bitbucket/index', () => { ) .reply(401); await expect(() => - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).rejects.toThrow(new Error('Response code 401 (Unauthorized)')); }); @@ -1264,12 +1244,7 @@ describe('modules/platform/bitbucket/index', () => { }, }); await expect(() => - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).rejects.toThrowErrorMatchingSnapshot(); }); @@ -1294,12 +1269,7 @@ describe('modules/platform/bitbucket/index', () => { }, }); await expect(() => - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).rejects.toThrow(new Error('Response code 400 (Bad Request)')); }); @@ -1309,12 +1279,7 @@ describe('modules/platform/bitbucket/index', () => { .get('/2.0/repositories/some/repo/pullrequests/5') .reply(500, undefined); await expect(() => - bitbucket.updatePr({ - number: 5, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' }) ).rejects.toThrowErrorMatchingSnapshot(); }); @@ -1333,7 +1298,6 @@ describe('modules/platform/bitbucket/index', () => { number: pr.id, prTitle: pr.title, state: 'closed', - targetBranch: 'target_branch', }) ).toBeUndefined(); }); diff --git a/lib/modules/platform/bitbucket/index.ts b/lib/modules/platform/bitbucket/index.ts index cb611b60b87ae9..9755dc18060d73 100644 --- a/lib/modules/platform/bitbucket/index.ts +++ b/lib/modules/platform/bitbucket/index.ts @@ -839,7 +839,6 @@ export async function updatePr({ prTitle: title, prBody: description, state, - targetBranch }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); // Updating a PR in Bitbucket will clear the reviewers if reviewers is not present @@ -857,11 +856,7 @@ export async function updatePr({ title, description: sanitize(description), reviewers: pr.reviewers, - destination: { - branch: { - name: targetBranch, - }, - }, }, + }, } ); } catch (err) { @@ -878,11 +873,6 @@ export async function updatePr({ title, description: sanitize(description), reviewers: sanitizedReviewers, - destination: { - branch: { - name: targetBranch, - }, - }, }, } ); diff --git a/lib/modules/platform/codecommit/index.spec.ts b/lib/modules/platform/codecommit/index.spec.ts index 4f066ff7e2f464..6dfc43483ab9df 100644 --- a/lib/modules/platform/codecommit/index.spec.ts +++ b/lib/modules/platform/codecommit/index.spec.ts @@ -698,7 +698,6 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'body', state: 'open', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -726,7 +725,6 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'new description', state: 'open', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -753,7 +751,6 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'new description', state: 'open', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -770,7 +767,6 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'body', state: 'open', - targetBranch: 'target_branch', }) ).toResolve(); }); @@ -785,7 +781,6 @@ describe('modules/platform/codecommit/index', () => { prTitle: 'title', prBody: 'body', state: 'closed', - targetBranch: 'target_branch', }) ).toResolve(); }); diff --git a/lib/modules/platform/codecommit/index.ts b/lib/modules/platform/codecommit/index.ts index 2a6699d7e0b09c..ed5a48fdfe8cdc 100644 --- a/lib/modules/platform/codecommit/index.ts +++ b/lib/modules/platform/codecommit/index.ts @@ -392,7 +392,6 @@ export async function updatePr({ prTitle: title, prBody: body, state, - targetBranch }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index bdf61a46185a48..060c7e57b111ef 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -1185,11 +1185,7 @@ describe('modules/platform/gitea/index', () => { it('should update pull request with title', async () => { helper.searchPRs.mockResolvedValueOnce(mockPRs); await initFakeRepo(); - await gitea.updatePr({ - number: 1, - prTitle: 'New Title', - targetBranch: 'target_branch', - }); + await gitea.updatePr({ number: 1, prTitle: 'New Title' }); expect(helper.updatePR).toHaveBeenCalledTimes(1); expect(helper.updatePR).toHaveBeenCalledWith(mockRepo.full_name, 1, { @@ -1204,7 +1200,6 @@ describe('modules/platform/gitea/index', () => { number: 1, prTitle: 'New Title', prBody: 'New Body', - targetBranch: 'target_branch', }); expect(helper.updatePR).toHaveBeenCalledTimes(1); @@ -1221,7 +1216,6 @@ describe('modules/platform/gitea/index', () => { number: 3, prTitle: 'New Title', prBody: 'New Body', - targetBranch: 'target_branch', }); expect(helper.updatePR).toHaveBeenCalledTimes(1); @@ -1239,7 +1233,6 @@ describe('modules/platform/gitea/index', () => { prTitle: 'New Title', prBody: 'New Body', state: 'closed', - targetBranch: 'target_branch', }); expect(helper.updatePR).toHaveBeenCalledWith(mockRepo.full_name, 1, { diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index a5c9ffecf60398..d650a6955104c0 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -584,7 +584,6 @@ const platform: Platform = { number: pr.number, prTitle: title, prBody: body, - targetBranch }); pr.title = title; pr.bodyStruct = getPrBodyStruct(body); @@ -607,7 +606,6 @@ const platform: Platform = { prTitle, prBody: body, state, - targetBranch }: UpdatePrConfig): Promise { let title = prTitle; if ((await getPrList()).find((pr) => pr.number === number)?.isDraft) { @@ -618,7 +616,6 @@ const platform: Platform = { title, ...(body && { body }), ...(state && { state }), - base: targetBranch }); }, diff --git a/lib/modules/platform/gitea/types.ts b/lib/modules/platform/gitea/types.ts index bc6d78fc8cab8d..de89f4f46a8765 100644 --- a/lib/modules/platform/gitea/types.ts +++ b/lib/modules/platform/gitea/types.ts @@ -169,6 +169,7 @@ export interface IssueSearchParams { } export interface PRCreateParams extends PRUpdateParams { + base?: string; head?: string; } @@ -178,7 +179,6 @@ export interface PRUpdateParams { assignees?: string[]; labels?: number[]; state?: PRState; - base?: string; } export interface PRSearchParams { diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index 782823e5a7b70a..acdf7859662641 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -2715,7 +2715,6 @@ describe('modules/platform/github/index', () => { number: 1234, prTitle: 'The New Title', prBody: 'Hello world again', - targetBranch: 'target_branch' }; const scope = httpMock.scope(githubApiHost); initRepoMock(scope, 'some/repo'); @@ -2731,7 +2730,6 @@ describe('modules/platform/github/index', () => { prTitle: 'The New Title', prBody: 'Hello world again', state: 'closed', - targetBranch: 'target_branch' }; const scope = httpMock.scope(githubApiHost); initRepoMock(scope, 'some/repo'); diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 23cc687096681d..7422d4a6ff93d0 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -1529,7 +1529,6 @@ export async function updatePr({ prTitle: title, prBody: rawBody, state, - targetBranch }: UpdatePrConfig): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); const body = sanitize(rawBody); @@ -1542,7 +1541,6 @@ export async function updatePr({ } const options: any = { body: patchBody, - base: targetBranch }; // istanbul ignore if if (config.forkToken) { diff --git a/lib/modules/platform/gitlab/index.spec.ts b/lib/modules/platform/gitlab/index.spec.ts index e406e43a36e7d8..4a1fe03a7d9de0 100644 --- a/lib/modules/platform/gitlab/index.spec.ts +++ b/lib/modules/platform/gitlab/index.spec.ts @@ -1981,12 +1981,7 @@ describe('modules/platform/gitlab/index', () => { .put('/api/v4/projects/undefined/merge_requests/1') .reply(200); await expect( - gitlab.updatePr({ - number: 1, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + gitlab.updatePr({ number: 1, prTitle: 'title', prBody: 'body' }) ).toResolve(); }); @@ -2008,12 +2003,7 @@ describe('modules/platform/gitlab/index', () => { .put('/api/v4/projects/undefined/merge_requests/1') .reply(200); await expect( - gitlab.updatePr({ - number: 1, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + gitlab.updatePr({ number: 1, prTitle: 'title', prBody: 'body' }) ).toResolve(); }); @@ -2035,12 +2025,7 @@ describe('modules/platform/gitlab/index', () => { .put('/api/v4/projects/undefined/merge_requests/1') .reply(200); await expect( - gitlab.updatePr({ - number: 1, - prTitle: 'title', - prBody: 'body', - targetBranch: 'target_branch', - }) + gitlab.updatePr({ number: 1, prTitle: 'title', prBody: 'body' }) ).toResolve(); }); @@ -2067,7 +2052,6 @@ describe('modules/platform/gitlab/index', () => { prTitle: 'title', prBody: 'body', state: 'closed', - targetBranch: 'target_branch', }) ).toResolve(); }); diff --git a/lib/modules/platform/gitlab/index.ts b/lib/modules/platform/gitlab/index.ts index 7f5f2bf0803d98..cf41c134d7dddc 100644 --- a/lib/modules/platform/gitlab/index.ts +++ b/lib/modules/platform/gitlab/index.ts @@ -641,7 +641,6 @@ export async function updatePr({ prBody: description, state, platformOptions, - targetBranch, }: UpdatePrConfig): Promise { let title = prTitle; if ((await getPrList()).find((pr) => pr.number === iid)?.isDraft) { @@ -659,7 +658,6 @@ export async function updatePr({ title, description: sanitize(description), ...(newState && { state_event: newState }), - target_branch: targetBranch, }, } ); diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index fb37a7cbe3fa72..07272f44987eba 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -105,7 +105,6 @@ export interface CreatePRConfig { } export interface UpdatePrConfig { number: number; - targetBranch: string; platformOptions?: PlatformPrOptions; prTitle: string; prBody?: string; diff --git a/lib/workers/repository/config-migration/pr/index.ts b/lib/workers/repository/config-migration/pr/index.ts index 417965ef8b6a14..c24a1dd1aa472d 100644 --- a/lib/workers/repository/config-migration/pr/index.ts +++ b/lib/workers/repository/config-migration/pr/index.ts @@ -85,7 +85,6 @@ ${ number: existingPr.number, prTitle, prBody, - targetBranch: 'target_branch' }); logger.info({ pr: existingPr.number }, 'Migration PR updated'); } diff --git a/lib/workers/repository/error-config.ts b/lib/workers/repository/error-config.ts index 69cf34427a00da..0fba9c00eefbbf 100644 --- a/lib/workers/repository/error-config.ts +++ b/lib/workers/repository/error-config.ts @@ -34,7 +34,6 @@ export async function raiseConfigWarningIssue( number: pr.number, prTitle: config.onboardingPrTitle!, prBody: body, - targetBranch: 'target_branch', }); } catch (err) /* istanbul ignore next */ { logger.warn({ err }, 'Error updating onboarding PR'); diff --git a/lib/workers/repository/finalise/prune.ts b/lib/workers/repository/finalise/prune.ts index 561955ff409a7c..3546ec41b746da 100644 --- a/lib/workers/repository/finalise/prune.ts +++ b/lib/workers/repository/finalise/prune.ts @@ -37,7 +37,6 @@ async function cleanUpBranches( number: pr.number, prTitle: newPrTitle, state: 'open', - targetBranch: 'target_branch', }); } @@ -66,7 +65,6 @@ async function cleanUpBranches( number: pr.number, prTitle: newPrTitle, state: 'closed', - targetBranch: 'target_branch', }); await scm.deleteBranch(branchName); } diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index d0360bc7ea34a8..d1d7ce2b71422e 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -153,7 +153,6 @@ If you need any further assistance then you can also [request help here](${ number: existingPr.number, prTitle: existingPr.title, prBody, - targetBranch: 'target_branch', }); logger.info({ pr: existingPr.number }, 'Onboarding PR updated'); } diff --git a/lib/workers/repository/update/pr/index.ts b/lib/workers/repository/update/pr/index.ts index 785794b6adc72c..db1e0cbe9277a4 100644 --- a/lib/workers/repository/update/pr/index.ts +++ b/lib/workers/repository/update/pr/index.ts @@ -321,7 +321,7 @@ export async function ensurePr( existingPrTitle === newPrTitle && existingPrBodyHash === newPrBodyHash ) { - // adds pr-cache for existing PRs + // adds or-cache for existing PRs setPrCache(branchName, prFingerprint, false); logger.debug( `Pull Request #${existingPr.number} does not need updating` @@ -350,7 +350,6 @@ export async function ensurePr( logger.info(`DRY-RUN: Would update PR #${existingPr.number}`); } else { await platform.updatePr({ - targetBranch: config.baseBranch ?? '', number: existingPr.number, prTitle, prBody, diff --git a/lib/workers/repository/update/pr/pr-fingerprint.ts b/lib/workers/repository/update/pr/pr-fingerprint.ts index 0556ff093a4045..62a5878e14fc1c 100644 --- a/lib/workers/repository/update/pr/pr-fingerprint.ts +++ b/lib/workers/repository/update/pr/pr-fingerprint.ts @@ -41,7 +41,6 @@ export interface PrFingerprintConfig { pendingVersions?: string[]; filteredUpgrades?: FilteredBranchUpgradeConfig[]; - baseBranch?: string; } export function generatePrFingerprintConfig( @@ -77,7 +76,6 @@ export function generatePrFingerprintConfig( updateType: config.updateType, warnings: config.warnings, pendingVersions: config.pendingVersions, - baseBranch: config.baseBranch, }; } From 1859a1b3abe43bbe257fbd2498f1345363cd1412 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Mon, 13 Mar 2023 00:33:40 +0530 Subject: [PATCH 3/3] add onboarding-branch to branch-cache --- .../repository/finalise/repository-statistics.ts | 4 ++++ lib/workers/repository/index.ts | 10 ++++++++++ lib/workers/repository/onboarding/branch/index.ts | 5 +++++ lib/workers/types.ts | 2 ++ 4 files changed, 21 insertions(+) diff --git a/lib/workers/repository/finalise/repository-statistics.ts b/lib/workers/repository/finalise/repository-statistics.ts index f69225f5dbc3c2..6ba4840dff3a56 100644 --- a/lib/workers/repository/finalise/repository-statistics.ts +++ b/lib/workers/repository/finalise/repository-statistics.ts @@ -46,6 +46,8 @@ function branchCacheToMetadata({ baseBranchSha, branchName, isModified, + isConflicted, + isBehindBase, pristine: isPristine, sha: branchSha, }: BranchCache): BranchMetadata { @@ -57,6 +59,8 @@ function branchCacheToMetadata({ branchSha, isModified, isPristine, + isConflicted, + isBehindBase, }; } diff --git a/lib/workers/repository/index.ts b/lib/workers/repository/index.ts index 0d6f4dd0e7af91..d8f0c7878132c2 100644 --- a/lib/workers/repository/index.ts +++ b/lib/workers/repository/index.ts @@ -14,6 +14,7 @@ import * as queue from '../../util/http/queue'; import * as throttle from '../../util/http/throttle'; import * as schemaUtil from '../../util/schema'; import { addSplit, getSplits, splitInit } from '../../util/split'; +import type { BranchConfig } from '../types'; import { setBranchCache } from './cache'; import { ensureDependencyDashboard } from './dependency-dashboard'; import handleError from './error'; @@ -73,6 +74,15 @@ export async function renovateRepository( setMeta({ repository: config.repository }); addSplit('update'); if (performExtract) { + if (!config.repoIsOnboarded) { + branches.push({ + branchName: config.onboardingBranch!, + baseBranch: config.defaultBranch!, + automerge: false, + upgrades: [], + manager: '' as never, // onboarding branch won't have this field + } satisfies BranchConfig); + } await setBranchCache(branches); // update branch cache if performed extraction } if (res === 'automerged') { diff --git a/lib/workers/repository/onboarding/branch/index.ts b/lib/workers/repository/onboarding/branch/index.ts index e2b07ce4bebaaa..ee0403021cd733 100644 --- a/lib/workers/repository/onboarding/branch/index.ts +++ b/lib/workers/repository/onboarding/branch/index.ts @@ -9,8 +9,10 @@ import { import { logger } from '../../../../logger'; import { Pr, platform } from '../../../../modules/platform'; import { checkoutBranch, setGitAuthor } from '../../../../util/git'; +import { setBranchNewCommit } from '../../../../util/git/set-branch-commit'; import { extractAllDependencies } from '../../extract'; import { mergeRenovateConfig } from '../../init/merge'; +import { syncBranchState } from '../../process/write'; import { OnboardingState } from '../common'; import { getOnboardingPr, isOnboarded } from './check'; import { getOnboardingConfig } from './config'; @@ -28,6 +30,7 @@ export async function checkOnboardingBranch( logger.debug('Repo is onboarded'); return { ...config, repoIsOnboarded }; } + await syncBranchState(config.onboardingBranch!, config.baseBranch!); if (config.isFork && !config.includeForks) { throw new Error(REPOSITORY_FORKED); } @@ -47,6 +50,7 @@ export async function checkOnboardingBranch( { branch: config.onboardingBranch, commit, onboarding: true }, 'Branch updated' ); + setBranchNewCommit(config.onboardingBranch!, config.baseBranch!, commit); } // istanbul ignore if if (platform.refreshPr) { @@ -78,6 +82,7 @@ export async function checkOnboardingBranch( { branch: onboardingBranch, commit, onboarding: true }, 'Branch created' ); + setBranchNewCommit(config.onboardingBranch!, config.baseBranch!, commit); } } if (!GlobalConfig.get('dryRun')) { diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 845ef59737627c..73721a86c36bd7 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -136,6 +136,8 @@ export interface BranchMetadata { automerge: boolean; isModified?: boolean; isPristine?: boolean; + isConflicted?: boolean; + isBehindBase?: boolean; } export interface BaseBranchMetadata {