fix: don’t skip modified branch from old PR (#8885)

This commit is contained in:
Rhys Arkins 2021-02-28 08:36:13 +01:00 committed by GitHub
parent e136cd4424
commit f3daa9e555
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View file

@ -219,6 +219,22 @@ describe('workers/branch', () => {
const res = await branchWorker.processBranch(config);
expect(res).toEqual(ProcessBranchResult.PrEdited);
});
it('continues branch if branch edited and but PR found', async () => {
git.branchExists.mockReturnValueOnce(true);
git.isBranchModified.mockResolvedValueOnce(true);
git.getBranchCommit.mockReturnValueOnce('abc123');
platform.findPr.mockResolvedValueOnce({ sha: 'abc123' } as any);
const res = await branchWorker.processBranch(config);
expect(res).toEqual(ProcessBranchResult.Error);
});
it('skips branch if branch edited and and PR found with sha mismatch', async () => {
git.branchExists.mockReturnValueOnce(true);
git.isBranchModified.mockResolvedValueOnce(true);
git.getBranchCommit.mockReturnValueOnce('abc123');
platform.findPr.mockResolvedValueOnce({ sha: 'def456' } as any);
const res = await branchWorker.processBranch(config);
expect(res).toEqual(ProcessBranchResult.PrEdited);
});
it('returns if branch creation limit exceeded', async () => {
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({
...updatedPackageFiles,

View file

@ -25,6 +25,7 @@ import { readLocalFile, writeLocalFile } from '../../util/fs';
import {
checkoutBranch,
deleteBranch,
getBranchCommit,
getRepoStatus,
branchExists as gitBranchExists,
isBranchModified,
@ -208,8 +209,28 @@ export async function processBranch(
}
}
} else if (branchIsModified) {
logger.debug('Branch has been edited');
return ProcessBranchResult.PrEdited;
const oldPr = await platform.findPr({
branchName: config.branchName,
state: PrState.NotOpen,
});
if (!oldPr) {
logger.debug('Branch has been edited but found no PR - skipping');
return ProcessBranchResult.PrEdited;
}
const branchSha = getBranchCommit(config.branchName);
const oldPrSha = oldPr?.sha;
if (!oldPrSha || oldPrSha === branchSha) {
logger.debug(
{ oldPrNumber: oldPr.number, oldPrSha, branchSha },
'Found old PR matching this branch - will override it'
);
} else {
logger.debug(
{ oldPrNumber: oldPr.number, oldPrSha, branchSha },
'Found old PR but the SHA is different'
);
return ProcessBranchResult.PrEdited;
}
}
}