Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create PR if stale branch can't automerge #9723

Merged
merged 1 commit into from Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/workers/branch/automerge.ts
Expand Up @@ -11,6 +11,7 @@ export type AutomergeResult =
| 'branch status error'
| 'failed'
| 'no automerge'
| 'stale'
| 'not ready';

export async function tryBranchAutomerge(
Expand Down Expand Up @@ -48,7 +49,7 @@ export async function tryBranchAutomerge(
err.message.includes('Not possible to fast-forward')
) {
logger.warn({ err }, 'Branch is not up to date - cannot automerge');
return 'not ready';
return 'stale';
}
if (err.message.includes('Protected branch')) {
if (err.message.includes('status check')) {
Expand Down
25 changes: 25 additions & 0 deletions lib/workers/branch/index.spec.ts
Expand Up @@ -448,6 +448,31 @@ describe(getName(__filename), () => {
expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
expect(prAutomerge.checkAutoMerge).toHaveBeenCalledTimes(1);
});
it('ensures PR when impossible to automerge', async () => {
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({
updatedPackageFiles: [{}],
} as PackageFilesResult);
npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({
artifactErrors: [],
updatedArtifacts: [{}],
} as WriteExistingFilesResult);
git.branchExists.mockReturnValue(true);
automerge.tryBranchAutomerge.mockResolvedValueOnce('stale');
prWorker.ensurePr.mockResolvedValueOnce({
prResult: PrResult.Created,
pr: {},
} as EnsurePrResult);
prAutomerge.checkAutoMerge.mockResolvedValueOnce({ automerged: false });
commit.commitFilesToBranch.mockResolvedValueOnce(null);
await branchWorker.processBranch({
...config,
automerge: true,
rebaseWhen: 'conflicted',
});
expect(prWorker.ensurePr).toHaveBeenCalledTimes(1);
expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
expect(prAutomerge.checkAutoMerge).toHaveBeenCalledTimes(1);
});
it('ensures PR and adds lock file error comment if no releaseTimestamp', async () => {
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({
updatedPackageFiles: [{}],
Expand Down
10 changes: 10 additions & 0 deletions lib/workers/branch/index.ts
Expand Up @@ -380,6 +380,16 @@ export async function processBranch(
logger.debug('Branch is automerged - returning');
return { branchExists: false, result: BranchResult.Automerged };
}
if (
mergeStatus === 'stale' &&
['conflicted', 'never'].includes(config.rebaseWhen)
) {
logger.warn(
'Branch cannot automerge because it is stale and rebaseWhen setting disallows rebasing - raising a PR instead'
);
config.forcePr = true;
config.branchAutomergeFailureMessage = mergeStatus;
}
if (
mergeStatus === 'automerge aborted - PR exists' ||
mergeStatus === 'branch status error' ||
Expand Down