mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
refactor: detectSemanticCommits (#7151)
This commit is contained in:
parent
6d24e9de78
commit
c75d2c6873
3 changed files with 5 additions and 23 deletions
|
@ -218,9 +218,10 @@ export async function getRepoConfig(
|
||||||
}
|
}
|
||||||
config.baseBranch = config.defaultBranch;
|
config.baseBranch = config.defaultBranch;
|
||||||
config.baseBranchSha = await checkoutBranch(config.baseBranch);
|
config.baseBranchSha = await checkoutBranch(config.baseBranch);
|
||||||
config.semanticCommits = await detectSemanticCommits(config);
|
|
||||||
config = await checkOnboardingBranch(config);
|
config = await checkOnboardingBranch(config);
|
||||||
config = await mergeRenovateConfig(config);
|
config = await mergeRenovateConfig(config);
|
||||||
|
config.semanticCommits =
|
||||||
|
config.semanticCommits ?? (await detectSemanticCommits());
|
||||||
setResolvedConfig(config);
|
setResolvedConfig(config);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,21 +13,16 @@ beforeEach(() => {
|
||||||
|
|
||||||
describe('workers/repository/init/semantic', () => {
|
describe('workers/repository/init/semantic', () => {
|
||||||
describe('detectSemanticCommits()', () => {
|
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 () => {
|
it('detects false if unknown', async () => {
|
||||||
config.semanticCommits = null;
|
config.semanticCommits = null;
|
||||||
git.getCommitMessages.mockResolvedValue(['foo', 'bar']);
|
git.getCommitMessages.mockResolvedValue(['foo', 'bar']);
|
||||||
const res = await detectSemanticCommits(config);
|
const res = await detectSemanticCommits();
|
||||||
expect(res).toBe(false);
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
it('detects true if known', async () => {
|
it('detects true if known', async () => {
|
||||||
config.semanticCommits = null;
|
config.semanticCommits = null;
|
||||||
git.getCommitMessages.mockResolvedValue(['fix: foo', 'refactor: bar']);
|
git.getCommitMessages.mockResolvedValue(['fix: foo', 'refactor: bar']);
|
||||||
const res = await detectSemanticCommits(config);
|
const res = await detectSemanticCommits();
|
||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,24 +1,10 @@
|
||||||
import conventionalCommitsDetector from 'conventional-commits-detector';
|
import conventionalCommitsDetector from 'conventional-commits-detector';
|
||||||
import { RenovateConfig } from '../../../config';
|
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../../logger';
|
||||||
import { getCommitMessages } from '../../../util/git';
|
import { getCommitMessages } from '../../../util/git';
|
||||||
|
|
||||||
export async function detectSemanticCommits(
|
export async function detectSemanticCommits(): Promise<boolean> {
|
||||||
config: RenovateConfig
|
|
||||||
): Promise<boolean> {
|
|
||||||
logger.debug('detectSemanticCommits()');
|
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();
|
const commitMessages = await getCommitMessages();
|
||||||
if (commitMessages) {
|
|
||||||
commitMessages.length = 10;
|
|
||||||
}
|
|
||||||
logger.trace(`commitMessages=${JSON.stringify(commitMessages)}`);
|
logger.trace(`commitMessages=${JSON.stringify(commitMessages)}`);
|
||||||
const type = conventionalCommitsDetector(commitMessages);
|
const type = conventionalCommitsDetector(commitMessages);
|
||||||
logger.debug('Semantic commits detection: ' + type);
|
logger.debug('Semantic commits detection: ' + type);
|
||||||
|
|
Loading…
Reference in a new issue