(force = false)
| 14 | const translation = i18n[(config.OCO_LANGUAGE as I18nLocals) || 'en']; |
| 15 | |
| 16 | export const configureCommitlintIntegration = async (force = false) => { |
| 17 | const spin = spinner(); |
| 18 | spin.start('Loading @commitlint configuration'); |
| 19 | |
| 20 | const fileExists = await utils.commitlintLLMConfigExists(); |
| 21 | |
| 22 | const commitLintConfig = await getCommitLintPWDConfig(); |
| 23 | if (commitLintConfig === null) { |
| 24 | throw new Error( |
| 25 | `Failed to load @commitlint config. Please check the following: |
| 26 | * @commitlint >= 9.0.0 is installed in the local directory. |
| 27 | * 'node_modules/@commitlint/load' package exists. |
| 28 | * A valid @commitlint configuration exists. |
| 29 | ` |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | // debug complete @commitlint configuration |
| 34 | // await fs.writeFile( |
| 35 | // `${OPENCOMMIT_COMMITLINT_CONFIG}-commitlint-debug`, |
| 36 | // JSON.stringify(commitLintConfig, null, 2) |
| 37 | // ); |
| 38 | |
| 39 | const hash = await computeHash(JSON.stringify(commitLintConfig)); |
| 40 | |
| 41 | spin.stop(`Read @commitlint configuration (hash: ${hash})`); |
| 42 | |
| 43 | if (fileExists) { |
| 44 | // Check if we need to update the prompts. |
| 45 | const { hash: existingHash } = await utils.getCommitlintLLMConfig(); |
| 46 | if (hash === existingHash && !force) { |
| 47 | spin.stop( |
| 48 | 'Hashes are the same, no need to update the config. Run "force" command to bypass.' |
| 49 | ); |
| 50 | return; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | spin.start('Generating consistency with given @commitlint rules'); |
| 55 | |
| 56 | const prompts = inferPromptsFromCommitlintConfig(commitLintConfig as any); |
| 57 | |
| 58 | const consistencyPrompts = |
| 59 | commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts); |
| 60 | |
| 61 | // debug prompt which will generate a consistency |
| 62 | // await fs.writeFile( |
| 63 | // `${COMMITLINT_LLM_CONFIG}-debug`, |
| 64 | // consistencyPrompts.map((p) => p.content) |
| 65 | // ); |
| 66 | |
| 67 | const engine = getEngine(); |
| 68 | let consistency = |
| 69 | (await engine.generateCommitMessage(consistencyPrompts)) || '{}'; |
| 70 | |
| 71 | // Cleanup the consistency answer. Sometimes 'gpt-3.5-turbo' sends rule's back. |
| 72 | prompts.forEach((prompt) => (consistency = consistency.replace(prompt, ''))); |
| 73 |
no test coverage detected
searching dependent graphs…