From 74a8e8fdfc045a23e277d9a6b408683a1f62759e Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Tue, 7 Jul 2020 11:45:57 +0200 Subject: [PATCH 1/2] feat(pr): pr edited body not comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a PR is edited, update the body “Rebasing” description instead of adding a PR comment. Closes #6694 --- .../__snapshots__/migration.spec.ts.snap | 1 + lib/config/definitions.ts | 1 - lib/config/migration.spec.ts | 1 + lib/config/migration.ts | 6 +++ lib/workers/branch/index.spec.ts | 1 + lib/workers/branch/index.ts | 38 +++++-------------- 6 files changed, 18 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..4244f329f1d4d8 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -76,6 +76,12 @@ export function migrateConfig( ); } delete migratedConfig.pathRules; + } else if (key === 'suppressNotifications') { + if (is.nonEmptyArray(val) && val.includes('prEditNotification')) { + 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..7a8dea6b0d4435 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -158,7 +158,6 @@ export async function processBranch( ); throw new Error(REPOSITORY_CHANGED); } - const topic = 'PR has been edited'; if ( branchPr.isModified || (branchPr.targetBranch && @@ -166,36 +165,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( + /\*\*Rebasing\*\*: .*/, + '**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'; } From 8b96f2763f8cdbbf45e13913c7df28d6e4bea694 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Tue, 7 Jul 2020 13:19:40 +0200 Subject: [PATCH 2/2] suggestions from code review --- lib/config/migration.ts | 1 + lib/workers/branch/index.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 4244f329f1d4d8..4c82f73aa2d0ae 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -78,6 +78,7 @@ 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' ); diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index 7a8dea6b0d4435..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 @@ -168,7 +170,7 @@ export async function processBranch( logger.debug('Manual rebase has been requested for PR'); } else { const newBody = branchPr.body?.replace( - /\*\*Rebasing\*\*: .*/, + rebasingRegex, '**Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.' ); if (newBody !== branchPr.body) {