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: log extended branch summary #22056

Merged
merged 19 commits into from May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/util/cache/repository/types.ts
@@ -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 @@ -44,15 +51,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 @@ -84,7 +91,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 @@ -93,6 +100,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
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
Expand Up @@ -166,6 +166,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
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);
});
});
});
35 changes: 34 additions & 1 deletion lib/workers/repository/finalize/repository-statistics.ts
Expand Up @@ -60,7 +60,35 @@ function branchCacheToMetadata({
};
}

export function runBranchSummary({ defaultBranch }: RenovateConfig): void {
function filterDependencyDashboardData(
branches: BranchCache[]
): Partial<BranchCache>[] {
let dependencyDashboardData = [...branches];
dependencyDashboardData = dependencyDashboardData.map((branch) => {
const b = { ...branch };
rarkins marked this conversation as resolved.
Show resolved Hide resolved
delete b.isModified;
delete b.automerge;
delete b.isBehindBase;
delete b.isConflicted;
delete b.baseBranch;
delete b.baseBranchSha;
delete b.branchFingerprint;
delete b.pristine;
delete b.prCache;
delete b.sha;
b.upgrades = b.upgrades?.map((upgrade) => {
const u = { ...upgrade };
delete u.sourceUrl;
delete u.depType;
return u;
});
return b;
});
return dependencyDashboardData;
}

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

const baseMetadata: BaseBranchMetadata[] = [];
Expand Down Expand Up @@ -88,4 +116,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
Expand Up @@ -131,10 +131,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