2020-09-22 11:10:07 +00:00
|
|
|
/* istanbul ignore file */
|
|
|
|
|
|
|
|
import { logger } from '../../logger';
|
|
|
|
import { platform } from '../../platform';
|
|
|
|
import {
|
|
|
|
BranchCache,
|
|
|
|
BranchUpgradeCache,
|
|
|
|
getCache,
|
|
|
|
} from '../../util/cache/repository';
|
2020-10-02 11:22:24 +00:00
|
|
|
import {
|
|
|
|
getBranchCommit,
|
|
|
|
getBranchParentSha,
|
|
|
|
isBranchModified,
|
|
|
|
} from '../../util/git';
|
2020-09-22 11:10:07 +00:00
|
|
|
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;
|
2020-10-02 11:22:24 +00:00
|
|
|
let parentSha = null;
|
2020-09-22 11:10:07 +00:00
|
|
|
if (sha) {
|
2020-10-02 11:22:24 +00:00
|
|
|
parentSha = await getBranchParentSha(branchName);
|
2020-09-22 11:10:07 +00:00
|
|
|
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)
|
|
|
|
: [];
|
2020-10-02 11:22:24 +00:00
|
|
|
return {
|
|
|
|
branchName,
|
|
|
|
sha,
|
|
|
|
parentSha,
|
|
|
|
prNo,
|
|
|
|
automerge,
|
|
|
|
isModified,
|
|
|
|
upgrades,
|
|
|
|
};
|
2020-09-22 11:10:07 +00:00
|
|
|
} 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);
|
|
|
|
}
|