Skip to content

Commit

Permalink
feat(internal): write branches cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Sep 22, 2020
1 parent 36e2792 commit 9f99c5e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/manager/common.ts
Expand Up @@ -158,6 +158,7 @@ export interface PackageDependency<T = Record<string, any>> extends Package<T> {
digestOneAndOnly?: boolean;
displayFrom?: string;
displayTo?: string;
fixedVersion?: string;
fromVersion?: string;
lockedVersion?: string;
propSource?: string;
Expand Down
23 changes: 23 additions & 0 deletions lib/util/cache/repository/index.ts
Expand Up @@ -11,7 +11,30 @@ export interface BaseBranchCache {
packageFiles: PackageFile[]; // extract result
}

export interface BranchUpgradeCache {
currentDigest?: string;
currentValue?: string;
datasource?: string;
depName?: string;
fixedVersion?: string;
fromVersion?: string;
lookupName?: string;
newDigest?: string;
newValue?: string;
toVersion?: string;
}

export interface BranchCache {
automerge: boolean;
branchName: string;
isModified: boolean;
prNo: number | null;
sha: string | null;
upgrades: BranchUpgradeCache[];
}

export interface Cache {
branches?: BranchCache[];
repository?: string;
init?: RepoInitConfig;
scan?: Record<string, BaseBranchCache>;
Expand Down
67 changes: 67 additions & 0 deletions lib/workers/repository/cache.ts
@@ -0,0 +1,67 @@
/* istanbul ignore file */

import { logger } from '../../logger';
import { platform } from '../../platform';
import {
BranchCache,
BranchUpgradeCache,
getCache,
} from '../../util/cache/repository';
import { getBranchCommit, isBranchModified } from '../../util/git';
import { BranchConfig, BranchUpgradeConfig } from '../common';

function generateBranchUpgradeCache(
upgrade: BranchUpgradeConfig
): BranchUpgradeCache {
const {
datasource,
depName,
lookupName,
fixedVersion,
fromVersion,
toVersion,
currentDigest,
newDigest,
} = upgrade;
return {
datasource,
depName,
lookupName,
fixedVersion,
fromVersion,
toVersion,
currentDigest,
newDigest,
};
}

async function generateBranchCache(branch: BranchConfig): Promise<BranchCache> {
const { branchName } = branch;
try {
const sha = getBranchCommit(branchName) || null;
let prNo = null;
if (sha) {
const branchPr = await platform.getBranchPr(branchName);
if (branchPr) {
prNo = branchPr.number;
}
}
const automerge = !!branch.automerge;
const isModified = sha ? await isBranchModified(branchName) : false;
const upgrades: BranchUpgradeCache[] = branch.upgrades
? branch.upgrades.map(generateBranchUpgradeCache)
: [];
return { branchName, sha, prNo, automerge, isModified, upgrades };
} catch (err) {
logger.error({ err, branchName }, 'Error generating branch cache');
return null;
}
}

export async function setBranchCache(branches: BranchConfig[]): Promise<void> {
const branchCache: BranchCache[] = [];
for (const branch of branches) {
branchCache.push(await generateBranchCache(branch));
}
getCache().branches = branchCache.filter(Boolean);
}
2 changes: 2 additions & 0 deletions lib/workers/repository/index.ts
Expand Up @@ -3,6 +3,7 @@ import { RenovateConfig } from '../../config';
import { logger, setMeta } from '../../logger';
import { deleteLocalFile } from '../../util/fs';
import { addSplit, getSplits, splitInit } from '../../util/split';
import { setBranchCache } from './cache';
import { ensureMasterIssue } from './dependency-dashboard';
import handleError from './error';
import { finaliseRepo } from './finalise';
Expand Down Expand Up @@ -41,6 +42,7 @@ export async function renovateRepository(
await ensureOnboardingPr(config, packageFiles, branches);
const res = await updateRepo(config, branches);
addSplit('update');
await setBranchCache(branches);
if (res !== 'automerged') {
await ensureMasterIssue(config, branches);
}
Expand Down

0 comments on commit 9f99c5e

Please sign in to comment.