-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): reviewType and new prompt construction method (#95)
* wip(): reviewType and new prompt construction method * feat(): error if no files selected for review * feat: update tests * fix(): ci * fix(): prompt * fix(): json bug * feat(): add ... between contexts allow for R files * fix(): /n character from decoding * feat(): more speed * feat(): attempt to fix review lines changed * chore(): change name * Update src/args.ts Co-authored-by: Manon Faour <[email protected]> * chore(): updated to use risk levels
- Loading branch information
1 parent
f55fad6
commit 613d3e8
Showing
36 changed files
with
502 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const encodeAttribute = (attribute: string, jsonString: string): string => { | ||
const regex = new RegExp( | ||
`"${attribute}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"`, | ||
"g" | ||
); | ||
return jsonString.replace( | ||
regex, | ||
(match, value) => `"${attribute}": "${encodeURIComponent(value)}"` | ||
); | ||
}; | ||
|
||
const decodeAndReplaceNewlines = (value: string): string => { | ||
return decodeURIComponent(value).replace(/\\n/g, "\n"); | ||
}; | ||
|
||
const processAttributes = ( | ||
object: any, | ||
attributesToEncode: string[], | ||
processor: (value: string) => string | ||
) => { | ||
attributesToEncode.forEach((attribute) => { | ||
if (object[attribute]) { | ||
object[attribute] = processor(object[attribute]); | ||
} | ||
}); | ||
}; | ||
|
||
export const parseAttributes = <T>( | ||
jsonString: string, | ||
attributesToEncode: string[] | ||
): T => { | ||
let encodedJsonString = jsonString; | ||
|
||
// Encode the specified attributes | ||
attributesToEncode.forEach((attribute) => { | ||
encodedJsonString = encodeAttribute(attribute, encodedJsonString); | ||
}); | ||
|
||
// Parse the JSON string | ||
const parsedObject: T = JSON.parse(encodedJsonString); | ||
|
||
// Decode the specified attributes for each item and replace '\n' with actual newline characters | ||
if (Array.isArray(parsedObject)) { | ||
parsedObject.forEach((item: any) => { | ||
processAttributes(item, attributesToEncode, decodeAndReplaceNewlines); | ||
}); | ||
} | ||
|
||
return parsedObject; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.