Skip to content

Commit

Permalink
refactor(onboarding): warning when onboarding pr cant be found (#15724)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Ladzaretti committed May 28, 2022
1 parent e563e22 commit 298ca99
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
34 changes: 34 additions & 0 deletions lib/workers/repository/onboarding/pr/index.spec.ts
@@ -1,3 +1,4 @@
import type { RequestError, Response } from 'got';
import {
RenovateConfig,
defaultConfig,
Expand Down Expand Up @@ -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);
});
});
});
});
8 changes: 5 additions & 3 deletions lib/workers/repository/onboarding/pr/index.ts
Expand Up @@ -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;
}
Expand Down

0 comments on commit 298ca99

Please sign in to comment.