Skip to content

Commit

Permalink
feat: checkedBranches (#21845)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
  • Loading branch information
3 people committed May 2, 2023
1 parent 65176e7 commit 5511f33
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/usage/self-hosted-configuration.md
Expand Up @@ -219,6 +219,15 @@ Results which are soft expired are reused in the following manner:
- The `etag` from the cached results will be reused, and may result in a 304 response, meaning cached results are revalidated
- If an error occurs when querying the `npmjs` registry, then soft expired results will be reused if they are present

## checkedBranches

This array will allow you to set the names of the branches you want to rebase/create, as if you selected their checkboxes in the Dependency Dashboard issue.

It has been designed with the intention of being run on one repository, in a one-off manner, e.g. to "force" the rebase of a known existing branch.
It is highly unlikely that you should ever need to add this to your permanent global config.

Example: `renovate --checked-branches=renovate/chalk-4.x renovate-reproductions/checked` will rebase the `renovate/chalk-4.x` branch in the `renovate-reproductions/checked` repository.`

## containerbaseDir

This directory is used to cache downloads when `binarySource=docker` or `binarySource=install`.
Expand Down
10 changes: 10 additions & 0 deletions lib/config/options/index.ts
Expand Up @@ -2624,6 +2624,16 @@ const options: RenovateOptions[] = [
type: 'boolean',
default: false,
},
{
name: 'checkedBranches',
description:
'A list of branch names to mark for creation or rebasing as if it was selected in the Dependency Dashboard issue.',
type: 'array',
subType: 'string',
experimental: true,
globalOnly: true,
default: [],
},
];

export function getOptions(): RenovateOptions[] {
Expand Down
2 changes: 2 additions & 0 deletions lib/config/types.ts
Expand Up @@ -260,6 +260,8 @@ export interface RenovateConfig
skipInstalls?: boolean | null;

constraintsFiltering?: ConstraintsFilter;

checkedBranches?: string[];
}

export interface AllConfig
Expand Down
25 changes: 25 additions & 0 deletions lib/workers/repository/dependency-dashboard.spec.ts
Expand Up @@ -104,6 +104,31 @@ describe('workers/repository/dependency-dashboard', () => {
});
});

it('reads dashboard body and apply checkedBranches', async () => {
const conf: RenovateConfig = {};
conf.prCreation = 'approval';
conf.checkedBranches = ['branch1', 'branch2'];
platform.findIssue.mockResolvedValueOnce({
title: '',
number: 1,
body: Fixtures.get('dependency-dashboard-with-8-PR.txt'),
});
await dependencyDashboard.readDashboardBody(conf);
expect(conf).toEqual({
checkedBranches: ['branch1', 'branch2'],
dependencyDashboardAllPending: false,
dependencyDashboardAllRateLimited: false,
dependencyDashboardChecks: {
branch1: 'global-config',
branch2: 'global-config',
},
dependencyDashboardIssue: 1,
dependencyDashboardRebaseAllOpen: false,
dependencyDashboardTitle: 'Dependency Dashboard',
prCreation: 'approval',
});
});

it('reads dashboard body all pending approval', async () => {
const conf: RenovateConfig = {};
conf.prCreation = 'approval';
Expand Down
17 changes: 16 additions & 1 deletion lib/workers/repository/dependency-dashboard.ts
Expand Up @@ -113,7 +113,22 @@ export async function readDashboardBody(
const issue = await platform.findIssue(config.dependencyDashboardTitle);
if (issue) {
config.dependencyDashboardIssue = issue.number;
Object.assign(config, parseDashboardIssue(issue.body!));
const dashboardChecks = parseDashboardIssue(issue.body!);

if (config.checkedBranches) {
const checkedBranchesRec: Record<string, string> = Object.fromEntries(
config.checkedBranches.map((branchName) => [
branchName,
'global-config',
])
);
dashboardChecks.dependencyDashboardChecks = {
...dashboardChecks.dependencyDashboardChecks,
...checkedBranchesRec,
};
}

Object.assign(config, dashboardChecks);
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions lib/workers/repository/update/branch/index.spec.ts
Expand Up @@ -2015,6 +2015,27 @@ describe('workers/repository/update/branch/index', () => {
expect(commit.commitFilesToBranch).toHaveBeenCalled();
});

it('continues when checked by checkedBranches', async () => {
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce(
updatedPackageFiles
);
npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({
artifactErrors: [],
updatedArtifacts: [],
});
scm.branchExists.mockResolvedValue(true);
commit.commitFilesToBranch.mockResolvedValueOnce(null);
expect(
await branchWorker.processBranch({
...config,
dependencyDashboardChecks: {
'renovate/some-branch': 'global-config',
},
})
).toMatchObject({ result: 'done' });
expect(commit.commitFilesToBranch).toHaveBeenCalled();
});

it('does nothing when branchPrefixOld/branch and its pr exists', async () => {
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({
...updatedPackageFiles,
Expand Down
3 changes: 3 additions & 0 deletions lib/workers/repository/update/branch/index.ts
Expand Up @@ -367,6 +367,9 @@ export async function processBranch(
if (userRebaseRequested) {
logger.debug('Manual rebase requested via Dependency Dashboard');
config.reuseExistingBranch = false;
} else if (dependencyDashboardCheck === 'global-config') {
logger.debug(`Manual create/rebase requested via checkedBranches`);
config.reuseExistingBranch = false;
} else if (userApproveAllPendingPR) {
logger.debug(
'A user manually approved all pending PRs via the Dependency Dashboard.'
Expand Down

0 comments on commit 5511f33

Please sign in to comment.