diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index 376bb2c31c5239352d583a8cfcff1e9f5c6cab86..6c7a301959c3f3c89cc3bba0ac04ba0aecbd0d9b 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -1,6 +1,7 @@ import { DateTime } from 'luxon'; import * as httpMock from '../../../../test/http-mock'; -import { logger, mocked } from '../../../../test/util'; +import { logger, mocked, partial } from '../../../../test/util'; +import { GlobalConfig } from '../../../config/global'; import { REPOSITORY_NOT_FOUND, REPOSITORY_RENAMED, @@ -12,7 +13,7 @@ import * as _hostRules from '../../../util/host-rules'; import { setBaseUrl } from '../../../util/http/github'; import { toBase64 } from '../../../util/string'; import { hashBody } from '../pr-body'; -import type { CreatePRConfig, UpdatePrConfig } from '../types'; +import type { CreatePRConfig, RepoParams, UpdatePrConfig } from '../types'; import type { ApiPageCache, GhRestPr } from './types'; import * as github from '.'; @@ -777,6 +778,10 @@ describe('modules/platform/github/index', () => { }); describe('getBranchPr(branchName)', () => { + beforeEach(() => { + GlobalConfig.reset(); + }); + it('should return null if no PR exists', async () => { const scope = httpMock.scope(githubApiHost); initRepoMock(scope, 'some/repo'); @@ -868,6 +873,32 @@ describe('modules/platform/github/index', () => { expect(pr2).toEqual(pr); }); + it('dryrun - skip autoclosed PR reopening', async () => { + const scope = httpMock.scope(githubApiHost); + initRepoMock(scope, 'some/repo'); + GlobalConfig.set({ dryRun: 'full' }); + scope + .get( + '/repos/some/repo/pulls?per_page=100&state=all&sort=updated&direction=desc&page=1' + ) + .reply(200, [ + { + number: 1, + head: { ref: 'somebranch', repo: { full_name: 'some/repo' } }, + title: 'old title - autoclosed', + state: PrState.Closed, + closed_at: DateTime.now().minus({ days: 6 }).toISO(), + }, + ]); + + await github.initRepo(partial<RepoParams>({ repository: 'some/repo' })); + + await expect(github.getBranchPr('somebranch')).resolves.toBeNull(); + expect(logger.logger.info).toHaveBeenCalledWith( + 'DRY-RUN: Would try to reopen autoclosed PR' + ); + }); + it('aborts reopen if PR is too old', async () => { const scope = httpMock.scope(githubApiHost); initRepoMock(scope, 'some/repo'); diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 96176ec5e685258c8337a433a9734cdf1e553290..56cdd25856142731ba4d164c2cf8c957b6a2b8da 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -4,6 +4,7 @@ import delay from 'delay'; import JSON5 from 'json5'; import { DateTime } from 'luxon'; import semver from 'semver'; +import { GlobalConfig } from '../../../config/global'; import { PlatformId } from '../../../constants'; import { PLATFORM_INTEGRATION_UNAUTHORIZED, @@ -663,6 +664,10 @@ export async function getBranchPr(branchName: string): Promise<Pr | null> { return null; } logger.debug({ autoclosedPr }, 'Found autoclosed PR for branch'); + if (GlobalConfig.get('dryRun')) { + logger.info('DRY-RUN: Would try to reopen autoclosed PR'); + return null; + } const { sha, number } = autoclosedPr; try { await githubApi.postJson(`repos/${config.repository}/git/refs`, {