Skip to content

Commit

Permalink
feat: log extended branch summary (#22056)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipAbed authored May 18, 2023
1 parent 4528048 commit c6d7168
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 9 deletions.
22 changes: 18 additions & 4 deletions lib/util/cache/repository/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type {
RepositoryCacheConfig,
RepositoryCacheType,
UpdateType,
} from '../../../config/types';
import type { PackageFile } from '../../../modules/manager/types';
import type { RepoInitConfig } from '../../../workers/repository/init/types';
import type { PrBlockedBy } from '../../../workers/types';

export interface BaseBranchCache {
sha: string; // branch commit sha
Expand All @@ -17,13 +19,18 @@ export interface BranchUpgradeCache {
currentValue?: string;
datasource?: string;
depName?: string;
depType?: string;
displayPending?: unknown;
fixedVersion?: string;
currentVersion?: string;
packageName?: string;
newDigest?: string;
newValue?: string;
newVersion?: string;
sourceUrl?: string;
packageFile?: string;
remediationNotPossible?: unknown;
updateType?: UpdateType;
}

export interface OnboardingBranchCache {
Expand All @@ -45,15 +52,15 @@ export interface BranchCache {
/**
* Whether this branch has automerge enabled
*/
automerge: boolean;
automerge?: boolean;
/**
* Name of base branch
*/
baseBranch: string;
baseBranch?: string;
/**
* The base branch's most recent commit SHA
*/
baseBranchSha: string | null;
baseBranchSha?: string | null;
/**
* Hash of the manager fingerprints and the filtered update branch config
*/
Expand Down Expand Up @@ -85,7 +92,7 @@ export interface BranchCache {
/**
* The branch's most recent commit SHA
*/
sha: string | null;
sha?: string | null;
/**
* Details on the dependency upgrades that have been applied in this branch
*/
Expand All @@ -94,6 +101,13 @@ export interface BranchCache {
* Object that has PR info
*/
prCache?: PrCache | null;

/**
* Dependency dashboard information
*/
prBlockedBy?: PrBlockedBy;
prTitle?: string;
result?: string;
}

export interface RepoCacheData {
Expand Down
21 changes: 20 additions & 1 deletion lib/workers/repository/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,37 @@ function generateBranchUpgradeCache(
const {
datasource,
depName,
depType,
displayPending,
packageName,
fixedVersion,
currentVersion,
newVersion,
currentValue,
newValue,
currentDigest,
newDigest,
packageFile,
sourceUrl,
remediationNotPossible,
updateType,
} = upgrade;
const result: BranchUpgradeCache = {
datasource,
depName,
depType,
displayPending,
fixedVersion,
currentVersion,
currentValue,
newValue,
newVersion,
currentDigest,
newDigest,
packageFile,
sourceUrl,
remediationNotPossible,
updateType,
};
if (packageName) {
result.packageName = packageName;
Expand All @@ -49,7 +63,7 @@ function generateBranchUpgradeCache(
async function generateBranchCache(
branch: BranchConfig
): Promise<BranchCache | null> {
const { baseBranch, branchName } = branch;
const { baseBranch, branchName, prBlockedBy, prTitle, result } = branch;
try {
const branchSha = await scm.getBranchCommit(branchName);
const baseBranchSha = await scm.getBranchCommit(baseBranch);
Expand Down Expand Up @@ -79,12 +93,14 @@ async function generateBranchCache(
baseBranchSha
) ?? undefined;
}

const automerge = !!branch.automerge;
const upgrades: BranchUpgradeCache[] = branch.upgrades
? branch.upgrades.map(generateBranchUpgradeCache)
: [];
const branchFingerprint = branch.branchFingerprint;
const prCache = getPrCache(branchName);

return {
automerge,
baseBranchSha,
Expand All @@ -94,9 +110,12 @@ async function generateBranchCache(
isBehindBase,
isConflicted,
isModified,
prBlockedBy,
pristine,
prCache,
prNo,
prTitle,
result,
sha: branchSha,
upgrades,
};
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/dependency-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function appendRepoProblems(config: RenovateConfig, issueBody: string): string {
)
);
if (repoProblems.size) {
logger.debug({ repoProblems }, 'repository problems');
newIssueBody += '## Repository problems\n\n';
newIssueBody +=
'These problems occurred while renovating this repository.\n\n';
Expand Down
34 changes: 34 additions & 0 deletions lib/workers/repository/finalize/repository-statistics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as cache from '../../../util/cache/repository';
import type {
BaseBranchCache,
BranchCache,
BranchUpgradeCache,
RepoCacheData,
} from '../../../util/cache/repository/types';
import {
Expand Down Expand Up @@ -103,6 +104,7 @@ describe('workers/repository/finalize/repository-statistics', () => {
isModified: false,
automerge: false,
pristine: false,
upgrades: [],
});
const expectedMeta = {
automerge: branchCache.automerge,
Expand Down Expand Up @@ -152,5 +154,37 @@ describe('workers/repository/finalize/repository-statistics', () => {
`Branch summary`
);
});

it('logs extended branch info if branchSummaryExtended', () => {
const defaultBranch = 'main';
const config: RenovateConfig = {
defaultBranch,
branchSummaryExtended: true,
};
const branchCache = partial<BranchCache>({
result: 'done',
upgrades: partial<BranchUpgradeCache[]>([
{
datasource: 'npm',
depName: 'minimist',
currentValue: '1.2.3',
sourceUrl: 'someUrl',
depType: 'dependencies',
},
]),
});

const branches: BranchCache[] = [{ ...branchCache, branchName: 'b1' }];
const cache = partial<RepoCacheData>({
scan: {},
branches,
});
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(false);

runBranchSummary(config);

expect(logger.debug).toHaveBeenCalledTimes(2);
});
});
});
66 changes: 64 additions & 2 deletions lib/workers/repository/finalize/repository-statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import type { Pr } from '../../../modules/platform';
import { getCache, isCacheModified } from '../../../util/cache/repository';
import type { BranchCache } from '../../../util/cache/repository/types';
import type {
BranchCache,
BranchUpgradeCache,
} from '../../../util/cache/repository/types';
import type {
BaseBranchMetadata,
BranchMetadata,
Expand Down Expand Up @@ -60,7 +63,61 @@ function branchCacheToMetadata({
};
}

export function runBranchSummary({ defaultBranch }: RenovateConfig): void {
function filterDependencyDashboardData(
branches: BranchCache[]
): Partial<BranchCache>[] {
const branchesFiltered: Partial<BranchCache>[] = [];
for (const branch of branches) {
const upgradesFiltered: Partial<BranchUpgradeCache>[] = [];
const { branchName, prNo, prTitle, result, upgrades, prBlockedBy } = branch;

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

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

const filteredBranch: Partial<BranchCache> = {
branchName,
prNo,
prTitle,
result,
prBlockedBy,
upgrades: upgradesFiltered,
};
branchesFiltered.push(filteredBranch);
}

return branchesFiltered;
}

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

const baseMetadata: BaseBranchMetadata[] = [];
Expand Down Expand Up @@ -88,4 +145,9 @@ export function runBranchSummary({ defaultBranch }: RenovateConfig): void {
};

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

if (branches?.length) {
const branchesInformation = filterDependencyDashboardData(branches);
logger.debug({ branchesInformation }, 'branches info extended');
}
}
4 changes: 2 additions & 2 deletions lib/workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ export interface BranchConfig

export interface BranchMetadata {
branchName: string;
branchSha: string | null;
branchSha?: string | null;
baseBranch?: string;
baseBranchSha?: string | null;
automerge: boolean;
automerge?: boolean;
isModified?: boolean;
isPristine?: boolean;
}
Expand Down

0 comments on commit c6d7168

Please sign in to comment.