Skip to content

Commit

Permalink
feat(config): rebaseWhen = automerging (#31527)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <[email protected]>
Co-authored-by: Nabeel Saabna <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent cef4f28 commit ea816f8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3628,6 +3628,7 @@ By default this label is `"rebase"` but you can configure it to anything you wan
Possible values and meanings:

- `auto`: Renovate will autodetect the best setting. It will use `behind-base-branch` if configured to automerge or repository has been set to require PRs to be up to date. Otherwise, `conflicted` will be used instead
- `automerging`: Renovate will use `behind-base-branch` if configured to automerge, Otherwise, `never` will be used instead
- `never`: Renovate will never rebase the branch or update it unless manually requested
- `conflicted`: Renovate will rebase only if the branch is conflicted
- `behind-base-branch`: Renovate will rebase whenever the branch falls 1 or more commit behind its base branch
Expand Down
8 changes: 7 additions & 1 deletion lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,13 @@ const options: RenovateOptions[] = [
name: 'rebaseWhen',
description: 'Controls when Renovate rebases an existing branch.',
type: 'string',
allowedValues: ['auto', 'never', 'conflicted', 'behind-base-branch'],
allowedValues: [
'auto',
'never',
'conflicted',
'behind-base-branch',
'automerging',
],
default: 'auto',
},
{
Expand Down
37 changes: 37 additions & 0 deletions lib/workers/repository/update/branch/reuse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,43 @@ describe('workers/repository/update/branch/reuse', () => {
expect(result.rebaseWhen).toBe('conflicted');
});

it('converts rebaseWhen=automerging to behind-base-branch', async () => {
config.rebaseWhen = 'automerging';
config.automerge = true;
scm.branchExists.mockResolvedValueOnce(true);
scm.isBranchBehindBase.mockResolvedValueOnce(false);

const result = await shouldReuseExistingBranch(config);

expect(config.rebaseWhen).toBe('automerging');
expect(result.rebaseWhen).toBe('behind-base-branch');
});

it('converts rebaseWhen=automerging to behind-base-branch if keep-updated', async () => {
config.rebaseWhen = 'automerging';
config.keepUpdatedLabel = 'keep-updated';
config.automerge = false;
scm.branchExists.mockResolvedValueOnce(true);
scm.isBranchBehindBase.mockResolvedValueOnce(false);
platform.getBranchPr.mockResolvedValueOnce(pr);

const result = await shouldReuseExistingBranch(config);

expect(config.rebaseWhen).toBe('automerging');
expect(result.rebaseWhen).toBe('behind-base-branch');
});

it('converts rebaseWhen=automerging to never', async () => {
config.rebaseWhen = 'automerging';
scm.branchExists.mockResolvedValueOnce(true);
scm.isBranchBehindBase.mockResolvedValueOnce(false);

const result = await shouldReuseExistingBranch(config);

expect(config.rebaseWhen).toBe('automerging');
expect(result.rebaseWhen).toBe('never');
});

it('converts rebaseWhen=auto to behind-base-branch if automerge is true AND branch is new', async () => {
config.rebaseWhen = 'auto';
config.automerge = true;
Expand Down
12 changes: 7 additions & 5 deletions lib/workers/repository/update/branch/reuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function shouldReuseExistingBranch(
}

/**
* This method updates rebaseWhen value when it's set to auto(default)
* This method updates rebaseWhen value when it's set to auto(default) or automerging
*
* @param result BranchConfig
* @param keepUpdated boolean
Expand All @@ -122,16 +122,18 @@ async function determineRebaseWhenValue(
result: BranchConfig,
keepUpdated: boolean,
): Promise<void> {
if (result.rebaseWhen === 'auto') {
if (result.rebaseWhen === 'auto' || result.rebaseWhen === 'automerging') {
let reason;

let newValue = 'behind-base-branch';
if (result.automerge === true) {
reason = 'automerge=true';
} else if (await platform.getBranchForceRebase?.(result.baseBranch)) {
reason = 'platform is configured to require up-to-date branches';
} else if (keepUpdated) {
reason = 'keep-updated label is set';
} else if (result.rebaseWhen === 'automerging') {
newValue = 'never';
reason = 'no keep-updated label and automerging is set';
} else if (await platform.getBranchForceRebase?.(result.baseBranch)) {
reason = 'platform is configured to require up-to-date branches';
} else {
newValue = 'conflicted';
reason = 'no rule for behind-base-branch applies';
Expand Down

0 comments on commit ea816f8

Please sign in to comment.