diff --git a/lib/modules/platform/github/common.ts b/lib/modules/platform/github/common.ts index 121b52274b8740cad0e19078298c69a2263519c9..fa993fca1ea291b6a9f605c51d946b9d1625c409 100644 --- a/lib/modules/platform/github/common.ts +++ b/lib/modules/platform/github/common.ts @@ -8,6 +8,7 @@ import type { GhRestPr } from './types'; * @see https://docs.github.com/en/rest/reference/pulls#list-pull-requests */ export function coerceRestPr(pr: GhRestPr | null | undefined): Pr | null { + // istanbul ignore if if (!pr) { return null; } diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index 696919b49b42715645d41a5a2e7506b9733cccd5..4f591154a4e8a417157886702a44c4cd5d323ea8 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -2504,7 +2504,7 @@ describe('modules/platform/github/index', () => { ) .reply(200, []) .get('/repos/some/repo/pulls/1234') - .reply(200); + .reply(404); await github.initRepo({ repository: 'some/repo' }); const pr = await github.getPr(1234); expect(pr).toBeNull(); diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 977af32b3ccb5e120b7300535e364a6e3665cfee..db1b1baf49da2488575b3244d36d9b0172212d5e 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -582,12 +582,17 @@ function cachePr(pr?: Pr | null): void { // Fetch fresh Pull Request and cache it when possible async function fetchPr(prNo: number): Promise<Pr | null> { - const { body: ghRestPr } = await githubApi.getJson<GhRestPr>( - `repos/${config.parentRepo ?? config.repository}/pulls/${prNo}` - ); - const result = coerceRestPr(ghRestPr); - cachePr(result); - return result; + try { + const { body: ghRestPr } = await githubApi.getJson<GhRestPr>( + `repos/${config.parentRepo ?? config.repository}/pulls/${prNo}` + ); + const result = coerceRestPr(ghRestPr); + cachePr(result); + return result; + } catch (err) { + logger.warn({ err, prNo }, `GitHub fetchPr error`); + return null; + } } // Gets details for a PR