Skip to content

Commit

Permalink
fix(rebaseWhen): text in PR for new branches with automerge=true (#32218
Browse files Browse the repository at this point in the history
)
  • Loading branch information
PhilipAbed authored Oct 30, 2024
1 parent 0a98b13 commit 56df90b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/workers/repository/update/branch/reuse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,15 @@ describe('workers/repository/update/branch/reuse', () => {
expect(config.rebaseWhen).toBe('auto');
expect(result.rebaseWhen).toBe('conflicted');
});

it('converts rebaseWhen=auto to behind-base-branch if automerge is true AND branch is new', async () => {
config.rebaseWhen = 'auto';
config.automerge = true;
scm.branchExists.mockResolvedValueOnce(false);
scm.isBranchBehindBase.mockResolvedValueOnce(false);
const result = await shouldReuseExistingBranch(config);
expect(config.rebaseWhen).toBe('auto');
expect(result.rebaseWhen).toBe('behind-base-branch');
});
});
});
6 changes: 4 additions & 2 deletions lib/workers/repository/update/branch/reuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ export async function shouldReuseExistingBranch(
): Promise<BranchConfig> {
const { baseBranch, branchName } = config;
const result: BranchConfig = { ...config, reuseExistingBranch: false };

const keepUpdated = await shouldKeepUpdated(result, baseBranch, branchName);
await determineRebaseWhenValue(result, keepUpdated);

// Check if branch exists
if (!(await scm.branchExists(branchName))) {
logger.debug(`Branch needs creating`);
return result;
}
logger.debug(`Branch already exists`);
const keepUpdated = await shouldKeepUpdated(result, baseBranch, branchName);
await determineRebaseWhenValue(result, keepUpdated);

if (result.rebaseWhen === 'behind-base-branch' || keepUpdated) {
if (await scm.isBranchBehindBase(branchName, baseBranch)) {
Expand Down

0 comments on commit 56df90b

Please sign in to comment.