Select Git revision
extract-update.ts
-
Gabriel-Ladzaretti authoredGabriel-Ladzaretti authored
extract-update.ts 4.30 KiB
// TODO #7154
import is from '@sindresorhus/is';
import hasha from 'hasha';
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import type { PackageFile } from '../../../modules/manager/types';
import { getCache } from '../../../util/cache/repository';
import { checkGithubToken as ensureGithubToken } from '../../../util/check-token';
import { checkoutBranch, getBranchCommit } from '../../../util/git';
import type { BranchConfig } from '../../types';
import { extractAllDependencies } from '../extract';
import { branchifyUpgrades } from '../updates/branchify';
import { raiseDeprecationWarnings } from './deprecated';
import { fetchUpdates } from './fetch';
import { sortBranches } from './sort';
import { WriteUpdateResult, writeUpdates } from './write';
export interface ExtractResult {
branches: BranchConfig[];
branchList: string[];
packageFiles: Record<string, PackageFile[]>;
}
export interface StatsResult {
fileCount: number;
depCount: number;
}
export interface Stats {
managers: Record<string, StatsResult>;
total: StatsResult;
}
// istanbul ignore next
function extractStats(
packageFiles: Record<string, PackageFile[]>
): Stats | null {
if (!packageFiles) {
return null;
}
const stats: Stats = {
managers: {},
total: {
fileCount: 0,
depCount: 0,
},
};
for (const [manager, managerPackageFiles] of Object.entries(packageFiles)) {
const fileCount = managerPackageFiles.length;
let depCount = 0;
for (const file of managerPackageFiles) {
depCount += file.deps.length;
}
stats.managers[manager] = {
fileCount,
depCount,
};
stats.total.fileCount += fileCount;
stats.total.depCount += depCount;
}
return stats;
}
export async function extract(
config: RenovateConfig
): Promise<Record<string, PackageFile[]>> {
logger.debug('extract()');
const { baseBranch } = config;
const baseBranchSha = getBranchCommit(baseBranch!);
let packageFiles: Record<string, PackageFile[]>;