File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+
1929export 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+ } ;
You can’t perform that action at this time.
0 commit comments