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: autoclose PRs when repo disabled #21263

Merged
merged 3 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/workers/repository/finalise/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { logger } from '../../../logger';
import { platform } from '../../../modules/platform';
import { ensureComment } from '../../../modules/platform/comment';
import { scm } from '../../../modules/platform/scm';
import { getBranchList } from '../../../util/git';
import { getBranchList, setUserRepoConfig } from '../../../util/git';

async function cleanUpBranches(
{ pruneStaleBranches: enabled }: RenovateConfig,
config: RenovateConfig,
remainingBranches: string[]
): Promise<void> {
if (enabled === false) {
if (!config.pruneStaleBranches) {
logger.debug('Branch/PR pruning is disabled - skipping');
return;
}
// set Git author in case the repository is not initialized yet
setUserRepoConfig(config);
for (const branchName of remainingBranches) {
try {
const pr = await platform.findPr({
Expand Down
14 changes: 14 additions & 0 deletions lib/workers/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import fs from 'fs-extra';
import { GlobalConfig } from '../../config/global';
import { applySecretsToConfig } from '../../config/secrets';
import type { RenovateConfig } from '../../config/types';
import {
REPOSITORY_DISABLED_BY_CONFIG,
REPOSITORY_FORKED,
REPOSITORY_NO_CONFIG,
} from '../../constants/error-messages';
import { pkg } from '../../expose.cjs';
import { instrument } from '../../instrumentation';
import { logger, setMeta } from '../../logger';
Expand All @@ -18,6 +23,7 @@ import { setBranchCache } from './cache';
import { ensureDependencyDashboard } from './dependency-dashboard';
import handleError from './error';
import { finaliseRepo } from './finalise';
rarkins marked this conversation as resolved.
Show resolved Hide resolved
import { pruneStaleBranches } from './finalise/prune';
import { initRepo } from './init';
import { OnboardingState } from './onboarding/common';
import { ensureOnboardingPr } from './onboarding/pr';
Expand Down Expand Up @@ -92,6 +98,14 @@ export async function renovateRepository(
} catch (err) /* istanbul ignore next */ {
setMeta({ repository: config.repository });
const errorRes = await handleError(config, err);
const pruneWhenErrors = [
REPOSITORY_DISABLED_BY_CONFIG,
REPOSITORY_FORKED,
REPOSITORY_NO_CONFIG,
];
if (pruneWhenErrors.includes(errorRes)) {
await pruneStaleBranches(config, []);
}
repoResult = processResult(config, errorRes);
}
if (localDir && !repoConfig.persistRepoData) {
Expand Down