diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index 38344178d7f7d1..4fec9d8003e16d 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -1955,5 +1955,59 @@ describe('workers/repository/update/branch/index', () => { result: 'done', }); }); + + it('continues branch, skips automerge if there are artifact errors', async () => { + jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce({ + updatedPackageFiles: [{}], + artifactErrors: [{}], + } as PackageFilesResult); + npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ + artifactErrors: [], + updatedArtifacts: [], + }); + git.branchExists.mockReturnValueOnce(true); + git.isBranchModified.mockResolvedValueOnce(true); + git.getBranchCommit.mockReturnValueOnce('123test'); + platform.findPr.mockResolvedValueOnce({ sha: '123test' } as any); + const res = await branchWorker.processBranch(config); + expect(automerge.tryBranchAutomerge).not.toHaveBeenCalled(); + expect(prAutomerge.checkAutoMerge).not.toHaveBeenCalled(); + expect(res).toEqual({ + branchExists: true, + commitSha: '123test', + prNo: undefined, + result: 'done', + updatesVerified: true, + }); + }); + + it('continues to update PR, if branch got updated, even when prCreation!==immediate', async () => { + git.branchExists.mockReturnValueOnce(true); + git.isBranchModified.mockResolvedValueOnce(false); + git.getBranchCommit.mockReturnValueOnce('123test'); + npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({ + artifactErrors: [], + updatedArtifacts: [partial({})], + } as WriteExistingFilesResult); + platform.getBranchPr.mockResolvedValueOnce({ + state: 'open', + } as Pr); + jest.spyOn(getUpdated, 'getUpdatedPackageFiles').mockResolvedValueOnce({ + updatedPackageFiles: [{}], + } as PackageFilesResult); + const inconfig = { + ...config, + prCreation: 'not-pending', + } as BranchConfig; + expect(await branchWorker.processBranch(inconfig)).toEqual({ + branchExists: true, + updatesVerified: true, + prNo: undefined, + result: 'done', + commitSha: '123test', + }); + expect(automerge.tryBranchAutomerge).not.toHaveBeenCalled(); + expect(prWorker.ensurePr).toHaveBeenCalledTimes(1); + }); }); }); diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 8a7489be1525f4..a82074da5ae30b 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -553,9 +553,11 @@ export async function processBranch( await setStability(config); await setConfidence(config); - // break if we pushed a new commit because status check are pretty sure pending but maybe not reported yet + // new commit means status check are pretty sure pending but maybe not reported yet + // if PR has not been created + new commit + prCreation !== immediate skip // but do not break when there are artifact errors if ( + !branchPr && !config.artifactErrors?.length && !userRebaseRequested && commitSha && @@ -565,14 +567,15 @@ export async function processBranch( return { branchExists: true, updatesVerified, - prNo: branchPr?.number, result: BranchResult.Pending, commitSha, }; } // Try to automerge branch and finish if successful, but only if branch already existed before this run - if (branchExists || config.ignoreTests) { + // skip if we have a non-immediate pr and there is an existing PR, + // we want to update the PR and skip the Auto merge since status checks aren't done yet + if (!config.artifactErrors?.length && (!commitSha || config.ignoreTests)) { const mergeStatus = await tryBranchAutomerge(config); logger.debug(`mergeStatus=${mergeStatus}`); if (mergeStatus === 'automerged') { @@ -811,13 +814,17 @@ export async function processBranch( } } else if (config.automerge) { logger.debug('PR is configured for automerge'); - const prAutomergeResult = await checkAutoMerge(pr, config); - if (prAutomergeResult?.automerged) { - return { - branchExists, - result: BranchResult.Automerged, - commitSha, - }; + // skip automerge if there is a new commit since status checks aren't done yet + if (!commitSha || config.ignoreTests) { + logger.debug('checking auto-merge'); + const prAutomergeResult = await checkAutoMerge(pr, config); + if (prAutomergeResult?.automerged) { + return { + branchExists, + result: BranchResult.Automerged, + commitSha, + }; + } } } else { logger.debug('PR is not configured for automerge');