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

feat(onboarding): merge onboardingBranch into baseBranch #20893

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a0ba81b
merge onboarding in base
RahulGautamSingh Mar 13, 2023
aed5680
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Mar 13, 2023
c596f23
add conflict-check
RahulGautamSingh Mar 13, 2023
66b6a16
remove checkoutBranch
RahulGautamSingh Mar 13, 2023
b73a5fc
do not enforece ff
RahulGautamSingh Mar 13, 2023
f66d7b7
ensure comment if conflicted
RahulGautamSingh Mar 13, 2023
699b065
move ensureComment before merging
RahulGautamSingh Mar 13, 2023
c9d6585
add tests
RahulGautamSingh Mar 13, 2023
6a6d2e9
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Mar 13, 2023
1af85ba
Apply suggestions from code review
RahulGautamSingh Mar 14, 2023
fd817db
remove automatic rebasing
RahulGautamSingh Mar 14, 2023
d7828ef
skip pr-update when conflicted
RahulGautamSingh Mar 14, 2023
cd2576d
update test
RahulGautamSingh Mar 14, 2023
94e171d
move conflict-comment in ensureOnboardingPr()
RahulGautamSingh Mar 14, 2023
597e979
coverage + remove comment
RahulGautamSingh Mar 14, 2023
826c763
Update lib/workers/repository/onboarding/pr/index.ts
rarkins Mar 15, 2023
77471fd
Update lib/util/git/index.ts
RahulGautamSingh Mar 15, 2023
aaa386a
do not notify when modified
RahulGautamSingh Mar 18, 2023
c1bef4e
Merge branch 'feat/merge-onboarding-into-base' of https://github.com/…
RahulGautamSingh Mar 18, 2023
fe8afd6
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Mar 18, 2023
9f70e5c
add test
RahulGautamSingh Mar 18, 2023
80ac8ab
Merge branch 'feat/merge-onboarding-into-base' of https://github.com/…
RahulGautamSingh Mar 18, 2023
1bbcbfb
add new test
RahulGautamSingh Mar 18, 2023
0926dff
Merge branch 'main' into feat/merge-onboarding-into-base
rarkins Mar 27, 2023
05ddfac
invalidate cachedExtract when onboardingBranch is modified
RahulGautamSingh Mar 27, 2023
85f0bde
refactor code
RahulGautamSingh Mar 28, 2023
f04590a
add and update tests
RahulGautamSingh Mar 28, 2023
3a3c0b6
renamed onboardingSha -> onboardingBranchSha
RahulGautamSingh Mar 28, 2023
50738ee
move logic to onboarding/index
RahulGautamSingh Mar 28, 2023
9f40ad8
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Mar 28, 2023
4cfaf3e
update tests
RahulGautamSingh Mar 28, 2023
b1aee87
add tests
RahulGautamSingh Mar 28, 2023
8f5e33c
revert extra changes
RahulGautamSingh Mar 28, 2023
58dcf0f
refactor
RahulGautamSingh Mar 28, 2023
0b19099
Apply suggestions from code review
RahulGautamSingh Mar 28, 2023
35d9e7d
apply suggestions
RahulGautamSingh Mar 28, 2023
30b4828
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 8, 2023
1f78d66
cache onboarding modified and conflicted states
RahulGautamSingh Apr 8, 2023
f0cf351
update tests
RahulGautamSingh Apr 8, 2023
e618ed4
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 8, 2023
80830da
apply suggestions
RahulGautamSingh Apr 11, 2023
6378d10
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 11, 2023
5a6e148
fix: check modified & conflict separately
RahulGautamSingh Apr 11, 2023
695fdb3
fix: update logic
RahulGautamSingh Apr 11, 2023
00b652c
fix: lint issue
RahulGautamSingh Apr 11, 2023
7068647
fix: delete onboardingCache if onboardingPr closed
RahulGautamSingh Apr 12, 2023
474e79d
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 12, 2023
e14ec45
fix: typo
RahulGautamSingh Apr 12, 2023
56c4eaf
refactor
RahulGautamSingh Apr 15, 2023
e51db9b
fix test
RahulGautamSingh Apr 19, 2023
4cfddc6
refactor
RahulGautamSingh Apr 19, 2023
0a26038
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 19, 2023
4bde23b
use is.undefined
RahulGautamSingh Apr 19, 2023
8afdeb4
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 27, 2023
deab039
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 27, 2023
0114fa5
fix typo
RahulGautamSingh Apr 27, 2023
bd84238
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh Apr 27, 2023
01f01d0
refactor
RahulGautamSingh Apr 27, 2023
90af567
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh May 3, 2023
46b0454
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh May 13, 2023
478dc60
fix tests
RahulGautamSingh May 14, 2023
8334f38
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh May 14, 2023
028f4e1
Apply suggestions from code review
RahulGautamSingh May 16, 2023
22634b0
fix formatting
RahulGautamSingh May 16, 2023
f0c00bd
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh May 16, 2023
9233910
Merge branch 'main' into feat/merge-onboarding-into-base
RahulGautamSingh May 16, 2023
c57c02f
Update lib/workers/repository/onboarding/branch/check.ts
RahulGautamSingh May 16, 2023
8004e47
Update lib/workers/repository/onboarding/branch/index.ts
RahulGautamSingh May 16, 2023
a4b3b82
rename for clarity
rarkins May 18, 2023
a957979
Merge branch 'main' into feat/merge-onboarding-into-base
rarkins May 18, 2023
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
6 changes: 6 additions & 0 deletions lib/util/git/index.spec.ts
Expand Up @@ -344,6 +344,12 @@ describe('util/git/index', () => {
expect(merged.all).toContain('renovate/future_branch');
});

it('does not push if pushToRemote=false', async () => {
const pushSpy = jest.spyOn(SimpleGit.prototype, 'push');
await git.mergeBranch('renovate/future_branch', false);
expect(pushSpy).toHaveBeenCalledTimes(0);
});
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

it('should throw if branch merge throws', async () => {
await expect(git.mergeBranch('not_found')).rejects.toThrow();
});
Expand Down
13 changes: 10 additions & 3 deletions lib/util/git/index.ts
Expand Up @@ -768,7 +768,10 @@ export async function deleteBranch(branchName: string): Promise<void> {
delete config.branchCommits[branchName];
}

export async function mergeBranch(branchName: string): Promise<void> {
export async function mergeBranch(
branchName: string,
pushToRemote = true
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
): Promise<void> {
let status: StatusResult | undefined;
try {
await syncGit();
Expand All @@ -784,8 +787,12 @@ export async function mergeBranch(branchName: string): Promise<void> {
])
);
status = await git.status();
await gitRetry(() => git.merge(['--ff-only', branchName]));
await gitRetry(() => git.push('origin', config.currentBranch));
if (pushToRemote) {
await gitRetry(() => git.merge(['--ff-only', branchName]));
await gitRetry(() => git.push('origin', config.currentBranch));
} else {
await gitRetry(() => git.merge([branchName]));
}
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
incLimitedValue('Commits');
} catch (err) {
logger.debug(
Expand Down
27 changes: 22 additions & 5 deletions lib/workers/repository/onboarding/branch/index.spec.ts
Expand Up @@ -258,10 +258,27 @@ describe('workers/repository/onboarding/branch/index', () => {
const res = await checkOnboardingBranch(config);
expect(res.repoIsOnboarded).toBeFalse();
expect(res.branchList).toEqual(['renovate/configure']);
expect(git.checkoutBranch).toHaveBeenCalledTimes(1);
expect(git.mergeBranch).toHaveBeenCalledTimes(1);
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
});

it('ensures comment on pr when branch is conflicted', async () => {
scm.isBranchConflicted.mockResolvedValueOnce(true);
git.getFileList.mockResolvedValue(['package.json']);
platform.getBranchPr.mockResolvedValueOnce(
mock<Pr>({
number: 12,
})
);
rebase.rebaseOnboardingBranch.mockResolvedValueOnce('123test');
const res = await checkOnboardingBranch(config);
expect(res.repoIsOnboarded).toBeFalse();
expect(res.branchList).toEqual(['renovate/configure']);
expect(git.mergeBranch).toHaveBeenCalledTimes(0);
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
expect(platform.ensureComment).toHaveBeenCalledTimes(1);
});

describe('tests onboarding rebase/retry checkbox handling', () => {
beforeEach(() => {
GlobalConfig.set({ platform: 'github' });
Expand All @@ -283,7 +300,7 @@ describe('workers/repository/onboarding/branch/index', () => {
`Platform '${pl}' does not support extended markdown`
);
expect(OnboardingState.prUpdateRequested).toBeTrue();
expect(git.checkoutBranch).toHaveBeenCalledTimes(1);
expect(git.mergeBranch).toHaveBeenCalledTimes(1);
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
});

Expand All @@ -297,7 +314,7 @@ describe('workers/repository/onboarding/branch/index', () => {
`No rebase checkbox was found in the onboarding PR`
);
expect(OnboardingState.prUpdateRequested).toBeTrue();
expect(git.checkoutBranch).toHaveBeenCalledTimes(1);
expect(git.mergeBranch).toHaveBeenCalledTimes(1);
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
});

Expand All @@ -312,7 +329,7 @@ describe('workers/repository/onboarding/branch/index', () => {
);
expect(OnboardingState.prUpdateRequested).toBeTrue();
``;
expect(git.checkoutBranch).toHaveBeenCalledTimes(1);
expect(git.mergeBranch).toHaveBeenCalledTimes(1);
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
});

Expand All @@ -323,7 +340,7 @@ describe('workers/repository/onboarding/branch/index', () => {
await checkOnboardingBranch(config);

expect(OnboardingState.prUpdateRequested).toBeFalse();
expect(git.checkoutBranch).toHaveBeenCalledTimes(1);
expect(git.mergeBranch).toHaveBeenCalledTimes(1);
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
});
});
Expand Down
27 changes: 24 additions & 3 deletions lib/workers/repository/onboarding/branch/index.ts
Expand Up @@ -8,7 +8,10 @@ import {
} from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import { Pr, platform } from '../../../../modules/platform';
import { checkoutBranch, setGitAuthor } from '../../../../util/git';
import { ensureComment } from '../../../../modules/platform/comment';
import { scm } from '../../../../modules/platform/scm';
import { emojify } from '../../../../util/emoji';
import { mergeBranch, setGitAuthor } from '../../../../util/git';
import { extractAllDependencies } from '../../extract';
import { mergeRenovateConfig } from '../../init/merge';
import { OnboardingState } from '../common';
Expand All @@ -23,6 +26,7 @@ export async function checkOnboardingBranch(
logger.debug('checkOnboarding()');
logger.trace({ config });
let onboardingBranch = config.onboardingBranch;
let isConflicted = false;
const repoIsOnboarded = await isOnboarded(config);
if (repoIsOnboarded) {
logger.debug('Repo is onboarded');
Expand All @@ -36,6 +40,21 @@ export async function checkOnboardingBranch(
setGitAuthor(config.gitAuthor);
const onboardingPr = await getOnboardingPr(config);
if (onboardingPr) {
isConflicted = await scm.isBranchConflicted(
viceice marked this conversation as resolved.
Show resolved Hide resolved
config.baseBranch!,
config.onboardingBranch!
);
if (isConflicted) {
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
// if branch is conflcted ensure comment
await ensureComment({
number: onboardingPr.number,
topic: 'Branch Conflicted',
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
content: emojify(
`:warning: This PR has a merge conflict. However, Renovate is unable to automatically fix that due to edits in this branch. Please resolve the merge conflict manually.\n\n`
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
),
});
}
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

if (config.onboardingRebaseCheckbox) {
handleOnboardingManualRebase(onboardingPr);
rarkins marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -81,9 +100,11 @@ export async function checkOnboardingBranch(
}
}
if (!GlobalConfig.get('dryRun')) {
logger.debug('Checkout onboarding branch.');
// TODO #7154
await checkoutBranch(onboardingBranch!);
if (!isConflicted) {
logger.debug('Merge onboarding branch in default branch');
await mergeBranch(onboardingBranch!, false);
}
}
// TODO #7154
const branchList = [onboardingBranch!];
Expand Down
16 changes: 0 additions & 16 deletions lib/workers/repository/onboarding/pr/index.spec.ts
Expand Up @@ -201,21 +201,6 @@ describe('workers/repository/onboarding/pr/index', () => {
}
);

it('updates PR when conflicted', async () => {
config.baseBranch = 'some-branch';
platform.getBranchPr.mockResolvedValueOnce(
partial<Pr>({
title: 'Configure Renovate',
bodyStruct,
})
);
scm.isBranchConflicted.mockResolvedValueOnce(true);
scm.isBranchModified.mockResolvedValueOnce(true);
await ensureOnboardingPr(config, {}, branches);
expect(platform.createPr).toHaveBeenCalledTimes(0);
expect(platform.updatePr).toHaveBeenCalledTimes(1);
});

it('updates PR when modified', async () => {
config.baseBranch = 'some-branch';
platform.getBranchPr.mockResolvedValueOnce(
Expand Down Expand Up @@ -251,7 +236,6 @@ describe('workers/repository/onboarding/pr/index', () => {
bodyStruct,
})
);
scm.isBranchConflicted.mockResolvedValueOnce(true);
scm.isBranchModified.mockResolvedValueOnce(true);
await ensureOnboardingPr(config, {}, branches);
expect(logger.info).toHaveBeenCalledWith(
Expand Down
12 changes: 1 addition & 11 deletions lib/workers/repository/onboarding/pr/index.ts
Expand Up @@ -102,17 +102,7 @@ If you need any further assistance then you can also [request help here](${
config.productLinks!.help
}) if you have any doubts and would like it reviewed.\n\n`
);
const isConflicted = await scm.isBranchConflicted(
config.baseBranch!,
config.onboardingBranch!
);
if (isConflicted) {
configDesc += emojify(
`:warning: This PR has a merge conflict. However, Renovate is unable to automatically fix that due to edits in this branch. Please resolve the merge conflict manually.\n\n`
);
} else {
configDesc += `Important: Now that this branch is edited, Renovate can't rebase it from the base branch any more. If you make changes to the base branch that could impact this onboarding PR, please merge them manually.\n\n`;
}
configDesc += `Important: Now that this branch is edited, Renovate can't rebase it from the base branch any more. If you make changes to the base branch that could impact this onboarding PR, please merge them manually.\n\n`;
rarkins marked this conversation as resolved.
Show resolved Hide resolved
} else {
configDesc = getConfigDesc(config, packageFiles!);
}
Expand Down