mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +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.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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue