Skip to content

Commit

Permalink
fix(cache): reset semanticCommits after clone (#19457)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Dec 17, 2022
1 parent 99a7c8a commit ef7f520
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
4 changes: 3 additions & 1 deletion lib/util/git/index.ts
Expand Up @@ -28,6 +28,7 @@ import { api as semverCoerced } from '../../modules/versioning/semver-coerced';
import { ExternalHostError } from '../../types/errors/external-host-error';
import type { GitProtocol } from '../../types/git';
import { incLimitedValue } from '../../workers/global/limits';
import { getCache } from '../cache/repository';
import { newlineRegex, regEx } from '../regex';
import { parseGitAuthor } from './author';
import { getCachedBehindBaseResult } from './behind-base-branch-cache';
Expand Down Expand Up @@ -460,6 +461,7 @@ export async function syncGit(): Promise<void> {
logger.warn({ err }, 'Cannot retrieve latest commit');
}
config.currentBranch = config.currentBranch || (await getDefaultBranch(git));
delete getCache()?.semanticCommits;
}

// istanbul ignore next
Expand Down Expand Up @@ -493,7 +495,7 @@ export async function getCommitMessages(): Promise<string[]> {
await syncGit();
logger.debug('getCommitMessages');
const res = await git.log({
n: 10,
n: 20,
format: { message: '%s' },
});
return res.all.map((commit) => commit.message);
Expand Down
@@ -1,8 +1,8 @@
import { RenovateConfig, getConfig, git } from '../../../../test/util';
import { initRepoCache } from '../../../util/cache/repository/init';
import { RenovateConfig, getConfig, git } from '../../../test/util';
import { initRepoCache } from '../cache/repository/init';
import { detectSemanticCommits } from './semantic';

jest.mock('../../../util/git');
jest.mock('.');

let config: RenovateConfig;

Expand All @@ -13,7 +13,7 @@ beforeEach(() => {
config.warnings = [];
});

describe('workers/repository/init/semantic', () => {
describe('util/git/semantic', () => {
describe('detectSemanticCommits()', () => {
beforeEach(async () => {
await initRepoCache({ repoFingerprint: '0123456789abcdef' });
Expand Down
@@ -1,25 +1,28 @@
import conventionalCommitsDetector from 'conventional-commits-detector';
import { logger } from '../../../logger';
import { getCache } from '../../../util/cache/repository';
import { getCommitMessages } from '../../../util/git';
import { logger } from '../../logger';
import { getCache } from '../../util/cache/repository';
import { getCommitMessages } from '.';

type DetectedSemanticCommit = 'enabled' | 'disabled';

export async function detectSemanticCommits(): Promise<DetectedSemanticCommit> {
logger.debug('detectSemanticCommits()');
const cache = getCache();
if (cache.semanticCommits) {
logger.debug(
`semanticCommits: returning "${cache.semanticCommits}" from cache`
);
return cache.semanticCommits;
}
const commitMessages = await getCommitMessages();
logger.trace(`commitMessages=${JSON.stringify(commitMessages)}`);
const type = conventionalCommitsDetector(commitMessages);
logger.debug('Semantic commits detection: ' + type);
logger.debug(`semanticCommits: detected "${type}"`);
if (type === 'angular') {
logger.debug('angular semantic commits detected');
logger.debug(`semanticCommits: enabled`);
cache.semanticCommits = 'enabled';
} else {
logger.debug('No semantic commits detected');
logger.debug(`semanticCommits: disabled`);
cache.semanticCommits = 'disabled';
}
return cache.semanticCommits;
Expand Down
4 changes: 4 additions & 0 deletions lib/workers/repository/index.ts
Expand Up @@ -8,6 +8,7 @@ import { logger, setMeta } from '../../logger';
import { removeDanglingContainers } from '../../util/exec/docker';
import { deleteLocalFile, privateCacheDir } from '../../util/fs';
import { isCloned } from '../../util/git';
import { detectSemanticCommits } from '../../util/git/semantic';
import { clearDnsCache, printDnsStats } from '../../util/http/dns';
import * as queue from '../../util/http/queue';
import * as throttle from '../../util/http/throttle';
Expand Down Expand Up @@ -49,6 +50,9 @@ export async function renovateRepository(
'extract',
() => extractDependencies(config)
);
if (config.semanticCommits === 'auto') {
config.semanticCommits = await detectSemanticCommits();
}
if (
GlobalConfig.get('dryRun') !== 'lookup' &&
GlobalConfig.get('dryRun') !== 'extract'
Expand Down
4 changes: 0 additions & 4 deletions lib/workers/repository/init/config.ts
@@ -1,17 +1,13 @@
import type { RenovateConfig } from '../../../config/types';
import { checkOnboardingBranch } from '../onboarding/branch';
import { mergeRenovateConfig } from './merge';
import { detectSemanticCommits } from './semantic';

// istanbul ignore next
export async function getRepoConfig(
config_: RenovateConfig
): Promise<RenovateConfig> {
let config = { ...config_ };
config.baseBranch = config.defaultBranch;
if (config.semanticCommits === 'auto') {
config.semanticCommits = await detectSemanticCommits();
}
config = await checkOnboardingBranch(config);
config = await mergeRenovateConfig(config);
return config;
Expand Down
1 change: 0 additions & 1 deletion lib/workers/repository/init/index.spec.ts
Expand Up @@ -14,7 +14,6 @@ jest.mock('../init/apis');
jest.mock('../init/config');
jest.mock('../init/merge');
jest.mock('../../../config/secrets');
jest.mock('../init/semantic');

const apis = mocked(_apis);
const config = mocked(_config);
Expand Down

0 comments on commit ef7f520

Please sign in to comment.