Skip to content
Snippets Groups Projects
Unverified Commit 298ca998 authored by Gabriel-Ladzaretti's avatar Gabriel-Ladzaretti Committed by GitHub
Browse files

refactor(onboarding): warning when onboarding pr cant be found (#15724)

parent e563e22e
No related branches found
No related tags found
No related merge requests found
import type { RequestError, Response } from 'got';
import {
RenovateConfig,
defaultConfig,
......@@ -203,5 +204,38 @@ describe('workers/repository/onboarding/pr/index', () => {
'DRY-RUN: Would create onboarding PR'
);
});
describe('ensureOnboardingPr() throws', () => {
const response = partial<Response>({ statusCode: 422 });
const err = partial<RequestError>({ response });
beforeEach(() => {
jest.resetAllMocks();
GlobalConfig.reset();
git.deleteBranch.mockResolvedValue();
});
it('throws when trying to create a new PR', async () => {
platform.createPr.mockRejectedValueOnce(err);
await expect(
ensureOnboardingPr(config, packageFiles, branches)
).toReject();
expect(git.deleteBranch).toHaveBeenCalledTimes(0);
});
it('deletes branch when PR already exists but cannot find it', async () => {
err.response.body = {
errors: [{ message: 'A pull request already exists' }],
};
platform.createPr.mockRejectedValueOnce(err);
await expect(
ensureOnboardingPr(config, packageFiles, branches)
).toResolve();
expect(logger.warn).toHaveBeenCalledWith(
'Onboarding PR already exists but cannot find it. It was probably created by a different user.'
);
expect(git.deleteBranch).toHaveBeenCalledTimes(1);
});
});
});
});
......@@ -152,14 +152,16 @@ If you need any further assistance then you can also [request help here](${confi
logger.info({ pr: pr.displayNumber }, 'Onboarding PR created');
await addParticipants(config, pr);
}
} catch (err) /* istanbul ignore next */ {
} catch (err) {
if (
err.statusCode === 422 &&
err.response?.statusCode === 422 &&
err.response?.body?.errors?.[0]?.message?.startsWith(
'A pull request already exists'
)
) {
logger.debug('Onboarding PR already exists but cannot find it');
logger.warn(
'Onboarding PR already exists but cannot find it. It was probably created by a different user.'
);
await deleteBranch(config.onboardingBranch);
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment