Skip to content
Snippets Groups Projects
Commit f347e500 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix: use getBranchPr for finding open PR for rebase check

parent 830d5687
No related branches found
No related tags found
No related merge requests found
...@@ -41,13 +41,13 @@ async function processBranch(branchConfig, packageFiles) { ...@@ -41,13 +41,13 @@ async function processBranch(branchConfig, packageFiles) {
); );
// Check if branch already existed // Check if branch already existed
let pr = await prAlreadyExisted(config); const existingPr = await prAlreadyExisted(config);
if (pr) { if (existingPr) {
logger.info( logger.info(
{ prTitle: config.prTitle }, { prTitle: config.prTitle },
'Closed PR already exists. Skipping branch.' 'Closed PR already exists. Skipping branch.'
); );
if (pr.state === 'closed') { if (existingPr.state === 'closed') {
const subject = 'Renovate Ignore Notification'; const subject = 'Renovate Ignore Notification';
let content; let content;
if (config.type === 'major') { if (config.type === 'major') {
...@@ -69,38 +69,33 @@ async function processBranch(branchConfig, packageFiles) { ...@@ -69,38 +69,33 @@ async function processBranch(branchConfig, packageFiles) {
} }
content += content +=
'\n\nIf this PR was closed by mistake or you changed your mind, you can simply rename this PR and you will soon get a fresh replacement PR opened.'; '\n\nIf this PR was closed by mistake or you changed your mind, you can simply rename this PR and you will soon get a fresh replacement PR opened.';
await platform.ensureComment(pr.number, subject, content); await platform.ensureComment(existingPr.number, subject, content);
if (branchExists) { if (branchExists) {
await platform.deleteBranch(config.branchName); await platform.deleteBranch(config.branchName);
} }
} else if (pr.state === 'merged') { } else if (existingPr.state === 'merged') {
logger.info({ pr: pr.number }, 'Merged PR is blocking this branch'); logger.info(
{ pr: existingPr.number },
'Merged PR is blocking this branch'
);
} }
return 'already-existed'; return 'already-existed';
} }
if (branchExists) { if (branchExists) {
logger.debug('Checking if PR has been edited'); logger.debug('Checking if PR has been edited');
pr = await platform.findPr(config.branchName, config.prTitle, 'open'); const branchPr = await platform.getBranchPr(config.branchName);
} if (branchPr) {
if (pr) { logger.debug({ branchPr }, 'Found existing PR');
logger.debug({ pr }, 'Found existing PR'); if (!branchPr.canRebase) {
pr = await platform.getPr(pr.number);
if (pr.state.startsWith('open')) {
logger.debug('Existing PR is open');
if (!pr.canRebase) {
const subject = 'PR has been edited'; const subject = 'PR has been edited';
logger.info(subject); logger.info(subject);
let content = let content =
'As this PR has been edited, Renovate will stop updating it in order to not cause any conflicts or other problems.'; 'As this PR has been edited, Renovate will stop updating it in order to not cause any conflicts or other problems.';
content += content +=
' If you wish to abandon your edits and have Renovate recreate this PR then you should rename this PR and then close it.'; ' If you wish to abandon your edits and have Renovate recreate this PR then you should rename this PR and then close it.';
await platform.ensureComment(pr.number, subject, content); await platform.ensureComment(branchPr.number, subject, content);
return 'pr-edited'; return 'pr-edited';
} }
} else {
logger.info('PR state is not open - aborting');
logger.debug({ pr });
return 'pr-closed';
} }
} }
......
...@@ -112,19 +112,13 @@ describe('workers/branch', () => { ...@@ -112,19 +112,13 @@ describe('workers/branch', () => {
it('skips branch if edited PR found', async () => { it('skips branch if edited PR found', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false); schedule.isScheduledNow.mockReturnValueOnce(false);
platform.branchExists.mockReturnValueOnce(true); platform.branchExists.mockReturnValueOnce(true);
platform.findPr.mockReturnValueOnce({}); platform.getBranchPr.mockReturnValueOnce({
platform.getPr.mockReturnValueOnce({ state: 'open', canRebase: false }); state: 'open',
canRebase: false,
});
const res = await branchWorker.processBranch(config); const res = await branchWorker.processBranch(config);
expect(res).toEqual('pr-edited'); expect(res).toEqual('pr-edited');
}); });
it('warns if edited PR is actually closed', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false);
platform.branchExists.mockReturnValueOnce(true);
platform.findPr.mockReturnValueOnce({});
platform.getPr.mockReturnValueOnce({ state: 'closed' });
const res = await branchWorker.processBranch(config);
expect(res).not.toEqual('pr-edited');
});
it('returns if pr creation limit exceeded', async () => { it('returns if pr creation limit exceeded', async () => {
getUpdated.getUpdatedPackageFiles.mockReturnValueOnce({ getUpdated.getUpdatedPackageFiles.mockReturnValueOnce({
updatedPackageFiles: [], updatedPackageFiles: [],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment