From 16630584261dcf868eeba5c60ce449e6ae0eda9c Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Tue, 7 Jul 2020 14:30:45 +0200 Subject: [PATCH] feat(pr): pr edited body not comment (#6695) --- .../__snapshots__/migration.spec.ts.snap | 1 + lib/config/definitions.ts | 1 - lib/config/migration.spec.ts | 1 + lib/config/migration.ts | 7 ++++ lib/workers/branch/index.spec.ts | 1 + lib/workers/branch/index.ts | 40 +++++-------------- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/lib/config/__snapshots__/migration.spec.ts.snap b/lib/config/__snapshots__/migration.spec.ts.snap index 85fcbd37bb00ed..50add5714023bd 100644 --- a/lib/config/__snapshots__/migration.spec.ts.snap +++ b/lib/config/__snapshots__/migration.spec.ts.snap @@ -149,6 +149,7 @@ Object { "separateMajorReleases": true, "separateMinorPatch": true, "suppressNotifications": Array [ + "lockFileErrors", "deprecationWarningIssues", ], "travis": Object { diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts index 246069ec48a8f8..10b6eed37baf63 100644 --- a/lib/config/definitions.ts +++ b/lib/config/definitions.ts @@ -1694,7 +1694,6 @@ const options: RenovateOptions[] = [ default: ['deprecationWarningIssues'], allowedValues: [ 'prIgnoreNotification', - 'prEditNotification', 'branchAutomergeFailure', 'lockFileErrors', 'artifactErrors', diff --git a/lib/config/migration.spec.ts b/lib/config/migration.spec.ts index a34b97b5269dd5..82e3cc4e0ef18a 100644 --- a/lib/config/migration.spec.ts +++ b/lib/config/migration.spec.ts @@ -32,6 +32,7 @@ describe('config/migration', () => { gitFs: false, separateMajorReleases: true, separatePatchReleases: true, + suppressNotifications: ['lockFileErrors', 'prEditNotification'], automerge: 'none' as never, automergeMajor: false, automergeMinor: true, diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 5e25e4acf7c7b8..4c82f73aa2d0ae 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -76,6 +76,13 @@ export function migrateConfig( ); } delete migratedConfig.pathRules; + } else if (key === 'suppressNotifications') { + if (is.nonEmptyArray(val) && val.includes('prEditNotification')) { + isMigrated = true; + migratedConfig.suppressNotifications = migratedConfig.suppressNotifications.filter( + (item) => item !== 'prEditNotification' + ); + } } else if (key === 'gomodTidy') { isMigrated = true; if (val) { diff --git a/lib/workers/branch/index.spec.ts b/lib/workers/branch/index.spec.ts index d73c3aa658c8a7..d1c14f354010d0 100644 --- a/lib/workers/branch/index.spec.ts +++ b/lib/workers/branch/index.spec.ts @@ -190,6 +190,7 @@ describe('workers/branch', () => { platform.getBranchPr.mockResolvedValueOnce({ state: PR_STATE_OPEN, isModified: true, + body: '**Rebasing**: something', } as never); const res = await branchWorker.processBranch(config); expect(res).toEqual('pr-edited'); diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index a23830b93321cd..c481e20a5f4634 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -48,6 +48,8 @@ function rebaseCheck(config: RenovateConfig, branchPr: any): boolean { return titleRebase || labelRebase || prRebaseChecked; } +const rebasingRegex = /\*\*Rebasing\*\*: .*/; + export async function processBranch( branchConfig: BranchConfig, prHourlyLimitReached?: boolean @@ -158,7 +160,6 @@ export async function processBranch( ); throw new Error(REPOSITORY_CHANGED); } - const topic = 'PR has been edited'; if ( branchPr.isModified || (branchPr.targetBranch && @@ -166,36 +167,17 @@ export async function processBranch( ) { logger.debug({ prNo: branchPr.number }, 'PR has been edited'); if (masterIssueCheck || config.rebaseRequested) { - if (config.dryRun) { - logger.info( - 'DRY-RUN: Would ensure PR edited comment removal in PR #' + - branchPr.number - ); - } else { - // Remove any "PR has been edited" comment only when rebasing - await platform.ensureCommentRemoval({ - number: branchPr.number, - topic, - }); - } + logger.debug('Manual rebase has been requested for PR'); } else { - let content = emojify( - `:construction_worker: This PR has received other commits, so Renovate will stop updating it to avoid conflicts or other problems.` + const newBody = branchPr.body?.replace( + rebasingRegex, + '**Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.' ); - content += ` If you wish to abandon your changes and have Renovate start over you may click the "rebase" checkbox in the PR body/description.`; - content += `\n\nIf you think this comment is in error and the branch is *not* modified, try deleting this comment. If it comes back again the next time Renovate runs, please submit an issue or seek config help.`; - if (!config.suppressNotifications.includes('prEditNotification')) { - if (config.dryRun) { - logger.info( - 'DRY-RUN: ensure comment in PR #' + branchPr.number - ); - } else { - await platform.ensureComment({ - number: branchPr.number, - topic, - content, - }); - } + if (newBody !== branchPr.body) { + logger.debug( + 'Updating existing PR to indicate that rebasing is not possible' + ); + await platform.updatePr(branchPr.number, branchPr.title, newBody); } return 'pr-edited'; }