refactor: detectSemanticCommits (#7151)

This commit is contained in:
Rhys Arkins 2020-09-01 10:44:52 +02:00 committed by GitHub
parent 6d24e9de78
commit c75d2c6873
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 23 deletions

View file

@ -218,9 +218,10 @@ export async function getRepoConfig(
}
config.baseBranch = config.defaultBranch;
config.baseBranchSha = await checkoutBranch(config.baseBranch);
config.semanticCommits = await detectSemanticCommits(config);
config = await checkOnboardingBranch(config);
config = await mergeRenovateConfig(config);
config.semanticCommits =
config.semanticCommits ?? (await detectSemanticCommits());
setResolvedConfig(config);
return config;
}

View file

@ -13,21 +13,16 @@ beforeEach(() => {
describe('workers/repository/init/semantic', () => {
describe('detectSemanticCommits()', () => {
it('returns config if already set', async () => {
config.semanticCommits = true;
const res = await detectSemanticCommits(config);
expect(res).toBe(true);
});
it('detects false if unknown', async () => {
config.semanticCommits = null;
git.getCommitMessages.mockResolvedValue(['foo', 'bar']);
const res = await detectSemanticCommits(config);
const res = await detectSemanticCommits();
expect(res).toBe(false);
});
it('detects true if known', async () => {
config.semanticCommits = null;
git.getCommitMessages.mockResolvedValue(['fix: foo', 'refactor: bar']);
const res = await detectSemanticCommits(config);
const res = await detectSemanticCommits();
expect(res).toBe(true);
});
});

View file

@ -1,24 +1,10 @@
import conventionalCommitsDetector from 'conventional-commits-detector';
import { RenovateConfig } from '../../../config';
import { logger } from '../../../logger';
import { getCommitMessages } from '../../../util/git';
export async function detectSemanticCommits(
config: RenovateConfig
): Promise<boolean> {
export async function detectSemanticCommits(): Promise<boolean> {
logger.debug('detectSemanticCommits()');
logger.trace({ config });
if (config.semanticCommits !== null) {
logger.debug(
{ semanticCommits: config.semanticCommits },
`semanticCommits already defined`
);
return config.semanticCommits;
}
const commitMessages = await getCommitMessages();
if (commitMessages) {
commitMessages.length = 10;
}
logger.trace(`commitMessages=${JSON.stringify(commitMessages)}`);
const type = conventionalCommitsDetector(commitMessages);
logger.debug('Semantic commits detection: ' + type);