Skip to content

Commit ec699c4

Browse files
authored
Bug (commitling) Parse JSON blocks from return response (#297)
1 parent c9b4549 commit ec699c4

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/modules/commitlint/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export const configureCommitlintIntegration = async (force = false) => {
6161

6262
// Cleanup the consistency answer. Sometimes 'gpt-3.5-turbo' sends rule's back.
6363
prompts.forEach((prompt) => (consistency = consistency.replace(prompt, '')));
64+
65+
// sometimes consistency is preceded by explanatory text like "Here is your JSON:"
66+
consistency = utils.getJSONBlock(consistency);
67+
6468
// ... remaining might be extra set of "\n"
6569
consistency = utils.removeDoubleNewlines(consistency);
6670

src/modules/commitlint/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ export const removeDoubleNewlines = (input: string): string => {
1616
return input;
1717
};
1818

19+
export const getJSONBlock = (input: string): string => {
20+
const jsonIndex = input.search('```json');
21+
if(jsonIndex > -1) {
22+
input = input.slice(jsonIndex + 8);
23+
const endJsonIndex = consistency.search('```');
24+
input = input.slice(0, endJsonIndex);
25+
}
26+
return input;
27+
};
28+
1929
export const commitlintLLMConfigExists = async (): Promise<boolean> => {
2030
let exists;
2131
try {
@@ -44,4 +54,4 @@ export const getCommitlintLLMConfig =
4454
content.toString()
4555
) as CommitlintLLMConfig;
4656
return commitLintLLMConfig;
47-
};
57+
};

0 commit comments

Comments
 (0)