Skip to content

Commit

Permalink
fix: Revert "feat: Enhance lookup logs to show branches extended info" (
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Aug 21, 2023
1 parent 375d267 commit ba8c2ba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 154 deletions.
68 changes: 0 additions & 68 deletions lib/workers/repository/finalize/__fixtures__/branches.json

This file was deleted.

6 changes: 5 additions & 1 deletion lib/workers/repository/finalize/index.ts
Expand Up @@ -6,7 +6,10 @@ import { clearRenovateRefs } from '../../../util/git';
import { configMigration } from '../config-migration';
import { PackageFiles } from '../package-files';
import { pruneStaleBranches } from './prune';
import { runRenovateRepoStats } from './repository-statistics';
import {
runBranchSummary,
runRenovateRepoStats,
} from './repository-statistics';

// istanbul ignore next
export async function finalizeRepo(
Expand All @@ -31,6 +34,7 @@ export async function finalizeRepo(
logger.debug('Repo is activated');
config.repoIsActivated = true;
}
runBranchSummary(config);
runRenovateRepoStats(config, prList);
}

Expand Down
26 changes: 6 additions & 20 deletions lib/workers/repository/finalize/repository-statistics.spec.ts
Expand Up @@ -18,7 +18,6 @@ jest.mock('../../../modules/platform/github/pr');
jest.mock('../../../util/http/github');

const prJson = Fixtures.getJson('./pr-list.json');
const branchesJson = Fixtures.getJson('./branches.json');
const result = Object.keys(prJson).map((key) => {
return prJson[key];
});
Expand Down Expand Up @@ -67,7 +66,7 @@ describe('workers/repository/finalize/repository-statistics', () => {
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(true);

runBranchSummary(config, []);
runBranchSummary(config);

expect(logger.debug).toHaveBeenCalledWith(
{
Expand Down Expand Up @@ -128,7 +127,7 @@ describe('workers/repository/finalize/repository-statistics', () => {
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(false);

runBranchSummary(config, []);
runBranchSummary(config);

expect(logger.debug).toHaveBeenCalledWith(
{
Expand All @@ -154,10 +153,11 @@ describe('workers/repository/finalize/repository-statistics', () => {
);
});

it('logs extended branch info', () => {
it('logs extended branch info if branchSummaryExtended', () => {
const defaultBranch = 'main';
const config: RenovateConfig = {
defaultBranch,
branchSummaryExtended: true,
};
const branchCache = partial<BranchCache>({
result: 'done',
Expand All @@ -171,6 +171,7 @@ describe('workers/repository/finalize/repository-statistics', () => {
},
]),
});

const branches: BranchCache[] = [{ ...branchCache, branchName: 'b1' }];
const cache = partial<RepoCacheData>({
scan: {},
Expand All @@ -179,22 +180,7 @@ describe('workers/repository/finalize/repository-statistics', () => {
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(false);

runBranchSummary(config, []);

expect(logger.debug).toHaveBeenCalledTimes(2);
});

it('logs extended branch info on lookup only', () => {
const config: RenovateConfig = {
defaultBranch: 'main',
};
const cache = partial<RepoCacheData>({
scan: {},
});
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(false);

runBranchSummary(config, branchesJson);
runBranchSummary(config);

expect(logger.debug).toHaveBeenCalledTimes(2);
});
Expand Down
66 changes: 3 additions & 63 deletions lib/workers/repository/finalize/repository-statistics.ts
@@ -1,18 +1,15 @@
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import type { Pr } from '../../../modules/platform';
import { coerceArray } from '../../../util/array';
import { getCache, isCacheModified } from '../../../util/cache/repository';
import type {
BranchCache,
BranchUpgradeCache,
} from '../../../util/cache/repository/types';
import type {
BaseBranchMetadata,
BranchConfig,
BranchMetadata,
BranchSummary,
BranchUpgradeConfig,
} from '../../types';

export function runRenovateRepoStats(
Expand Down Expand Up @@ -66,55 +63,6 @@ function branchCacheToMetadata({
};
}

function filterDependencyLookupData(
branches: BranchConfig[]
): Partial<BranchConfig>[] {
const branchesFiltered: Partial<BranchConfig>[] = [];
for (const branch of branches) {
const upgradesFiltered: Partial<BranchUpgradeConfig>[] = [];
const { branchName, prTitle, upgrades } = branch;

for (const upgrade of coerceArray(upgrades)) {
const {
datasource,
depName,
fixedVersion,
currentVersion,
currentValue,
newValue,
newVersion,
packageFile,
updateType,
packageName,
} = upgrade;

const filteredUpgrade: Partial<BranchUpgradeConfig> = {
datasource,
depName,
fixedVersion,
currentVersion,
currentValue,
newValue,
newVersion,
packageFile,
updateType,
packageName,
};
upgradesFiltered.push(filteredUpgrade);
}

const filteredBranch: Partial<BranchConfig> = {
branchName,
prTitle,
result: 'no-work',
upgrades: upgradesFiltered as BranchUpgradeConfig[],
};
branchesFiltered.push(filteredBranch);
}

return branchesFiltered;
}

function filterDependencyDashboardData(
branches: BranchCache[]
): Partial<BranchCache>[] {
Expand All @@ -123,7 +71,7 @@ function filterDependencyDashboardData(
const upgradesFiltered: Partial<BranchUpgradeCache>[] = [];
const { branchName, prNo, prTitle, result, upgrades, prBlockedBy } = branch;

for (const upgrade of coerceArray(upgrades)) {
for (const upgrade of upgrades ?? []) {
const {
datasource,
depName,
Expand Down Expand Up @@ -168,10 +116,7 @@ function filterDependencyDashboardData(
return branchesFiltered;
}

export function runBranchSummary(
config: RenovateConfig,
lookupBranchConfig: BranchConfig[]
): void {
export function runBranchSummary(config: RenovateConfig): void {
const defaultBranch = config.defaultBranch;
const { scan, branches } = getCache();

Expand Down Expand Up @@ -201,13 +146,8 @@ export function runBranchSummary(

logger.debug(res, 'Branch summary');

let branchesInformation;
if (branches?.length) {
branchesInformation = filterDependencyDashboardData(branches);
} else if (lookupBranchConfig?.length) {
branchesInformation = filterDependencyLookupData(lookupBranchConfig);
}
if (branchesInformation) {
const branchesInformation = filterDependencyDashboardData(branches);
logger.debug({ branchesInformation }, 'branches info extended');
}
}
2 changes: 0 additions & 2 deletions lib/workers/repository/index.ts
Expand Up @@ -23,7 +23,6 @@ import { ensureDependencyDashboard } from './dependency-dashboard';
import handleError from './error';
import { finalizeRepo } from './finalize';
import { pruneStaleBranches } from './finalize/prune';
import { runBranchSummary } from './finalize/repository-statistics';
import { initRepo } from './init';
import { OnboardingState } from './onboarding/common';
import { ensureOnboardingPr } from './onboarding/pr';
Expand Down Expand Up @@ -95,7 +94,6 @@ export async function renovateRepository(
// TODO #22198
repoResult = processResult(config, res!);
}
runBranchSummary(config, branches);
} catch (err) /* istanbul ignore next */ {
setMeta({ repository: config.repository });
const errorRes = await handleError(config, err);
Expand Down

0 comments on commit ba8c2ba

Please sign in to comment.