Skip to content

Commit

Permalink
fix: parsing code issue + add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nherment committed Nov 30, 2023
1 parent 0980b77 commit 69eb572
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions functions/createReview/astParsing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ function getParser(fileName) {
switch (fileExtension) {
case '.ts':
case '.tsx':
logger.info(`Using TS parser for file ${fileName}`)
return Parser.extend(tsPlugin())
case '.jsx':
logger.info(`Using JSX parser for file ${fileName}`)
return Parser.extend(jsxPlugin())
case '.js':
logger.info(`Using standard parser for file ${fileName}`)
return Parser
}
return null
Expand All @@ -36,14 +39,16 @@ export function generateAST(fileContent, fileDiff) {
const parser = getParser(fileDiff.afterName)
if (!parser) return
let ast
const sourceType = isESMFile(fileContent) ? 'module' : 'commonjs'
try {
ast = parser.parse(fileContent, {
sourceType: isESMFile(fileContent) ? 'module' : 'commonjs',
sourceType: sourceType,
locations: true
})
} catch (err) {
logger.info(err)
logger.info(
`Failed to parse the file content for [${fileDiff.afterName}] into AST. Falling back to the loose parser. Error: ${err.message}`
`Failed to parse the file content for [${fileDiff.afterName}] with sourceType=${sourceType} into AST. Falling back to the loose parser. Error: ${err.message}`
)
ast = LooseParser.parse(fileContent, { locations: true })
}
Expand Down
2 changes: 2 additions & 0 deletions functions/createReview/astParsing/rules/no_loop_await.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function isCalleeFunction(node, callFunctionName) {

export function isArrayFunctionCall(node, functionName) {
return (
!!node &&
!!node.type &&
node.type === 'ExpressionStatement' &&
node.expression.type === 'CallExpression' &&
(isCalleeOfType(node, 'ArrayExpression') ||
Expand Down
4 changes: 4 additions & 0 deletions functions/webhook/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default async app => {
await triggerLLMReview(context)
} else if (shouldTriggerRuleBasedReview(context.payload)) {
await triggerRuleBasedReview(context)
} else {
logger.info(
`Ignoring event '${context.name}' -> '${context.payload.action}' with id=${context.id}`
)
}
} catch (error) {
logger.error(error)
Expand Down
2 changes: 2 additions & 0 deletions functions/webhook/triggerReviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function shouldTriggerRuleBasedReview(payload) {
}

export async function triggerLLMReview(context) {
logger.info('Triggering LLM code review')
const data = await fetchGithubData(context)
data.reviewType = REVIEW_TYPE.LLM
const messageId = await publishMessage(data)
Expand All @@ -112,6 +113,7 @@ export async function triggerLLMReview(context) {
}

export async function triggerRuleBasedReview(context) {
logger.info('Triggering a rule based code review')
const data = await fetchGithubData(context)
data.reviewType = REVIEW_TYPE.RuleBased
await publishMessage(data)
Expand Down

0 comments on commit 69eb572

Please sign in to comment.