Skip to content

Commit

Permalink
feat(pr): pr edited body not comment (#6695)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jul 7, 2020
1 parent c3f8d00 commit 1663058
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
1 change: 1 addition & 0 deletions lib/config/__snapshots__/migration.spec.ts.snap
Expand Up @@ -149,6 +149,7 @@ Object {
"separateMajorReleases": true,
"separateMinorPatch": true,
"suppressNotifications": Array [
"lockFileErrors",
"deprecationWarningIssues",
],
"travis": Object {
Expand Down
1 change: 0 additions & 1 deletion lib/config/definitions.ts
Expand Up @@ -1694,7 +1694,6 @@ const options: RenovateOptions[] = [
default: ['deprecationWarningIssues'],
allowedValues: [
'prIgnoreNotification',
'prEditNotification',
'branchAutomergeFailure',
'lockFileErrors',
'artifactErrors',
Expand Down
1 change: 1 addition & 0 deletions lib/config/migration.spec.ts
Expand Up @@ -32,6 +32,7 @@ describe('config/migration', () => {
gitFs: false,
separateMajorReleases: true,
separatePatchReleases: true,
suppressNotifications: ['lockFileErrors', 'prEditNotification'],
automerge: 'none' as never,
automergeMajor: false,
automergeMinor: true,
Expand Down
7 changes: 7 additions & 0 deletions lib/config/migration.ts
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/workers/branch/index.spec.ts
Expand Up @@ -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');
Expand Down
40 changes: 11 additions & 29 deletions lib/workers/branch/index.ts
Expand Up @@ -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
Expand Down Expand Up @@ -158,44 +160,24 @@ export async function processBranch(
);
throw new Error(REPOSITORY_CHANGED);
}
const topic = 'PR has been edited';
if (
branchPr.isModified ||
(branchPr.targetBranch &&
branchPr.targetBranch !== branchConfig.baseBranch)
) {
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';
}
Expand Down

0 comments on commit 1663058

Please sign in to comment.