Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"gpt-tokenizer": "^2.1.2",
"groq-sdk": "^0.8.0",
"octokit": "^3.1.1",
"python-ast": "^0.1.0",
"python-parser": "^1.0.3",
"python-shell": "^5.0.0",
"xml2js": "^0.6.2"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { processPullRequest } from "./review-agent";
import { applyReview } from "./reviews";

// This creates a new instance of the Octokit App class.
// This is a sample app
// testing part 2
const reviewApp = new App({
appId: env.GITHUB_APP_ID,
privateKey: env.GITHUB_PRIVATE_KEY,
Expand Down
84 changes: 80 additions & 4 deletions src/context/language/python-parser.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,91 @@
import { AbstractParser, EnclosingContext } from "../../constants";
import * as parser from 'python-ast';

interface Node {
type: string;
start: number;
end: number;
children: Node[];
}

// Helper function to convert a ParseTree to a Node
const parseTreeToNode = (parseTree: any): Node => {
return {
type: parseTree.type,
start: parseTree.start,
end: parseTree.end,
children: parseTree.children ? parseTree.children.map(parseTreeToNode) : [],
};
};

const processNode = (
node: Node,
lineStart: number,
lineEnd: number,
largestSize: number,
largestEnclosingContext: Node | null
) => {
// determining start and end line number
const start = node.start;
const end = start + (node.end - start);

if (node.start <= lineStart && lineEnd <= node.end) {
const size = node.end - node.start;
if (size > largestSize) {
largestSize = size;
largestEnclosingContext = node;
}
}
return { largestSize, largestEnclosingContext };
}

export class PythonParser implements AbstractParser {
findEnclosingContext(
file: string,
lineStart: number,
lineEnd: number
): EnclosingContext {
// TODO: Implement this method for Python
return null;
// parse the file as a parseTree
const ast = parser.parse(file);
// Convert ParseTree to Node
const rootNode = parseTreeToNode(ast);
let largestEnclosingContext: Node | null = null;
let largestSize = 0;
const traverseAST = (node: Node) => {
// check if the node is a current function or a class
if (node.type === 'FunctionDef' || node.type === 'ClassDef') {
({ largestSize, largestEnclosingContext } = processNode(
node,
lineStart,
lineEnd,
largestSize,
largestEnclosingContext
));
}

// Traverse the children nodes
node.children.forEach((child) => traverseAST(child));
};

traverseAST(rootNode);
return {
enclosingContext: largestEnclosingContext,
} as EnclosingContext;
}
dryRun(file: string): { valid: boolean; error: string } {
// TODO: Implement this method for Python
return { valid: false, error: "Not implemented yet" };
try {
// tries to parse the Python code here
const ast = parser.parse(file);
const rootNode = parseTreeToNode(ast);
return {
valid: true,
error: "",
};
} catch (err) {
return {
valid: false,
error: err.message,
};
}
}
}
1 change: 1 addition & 0 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The review should focus on new code added in the PR (lines starting with '+'), a

- ONLY PROVIDE CODE SUGGESTIONS
- Focus on important suggestions like fixing code problems, improving performance, improving security, improving readability
- Specifically, could make suggestions on function modulization or code logic on top of performance, readability, and security
- Avoid making suggestions that have already been implemented in the PR code. For example, if you want to add logs, or change a variable to const, or anything else, make sure it isn't already in the PR code.
- Don't suggest adding docstring, type hints, or comments.
- Suggestions should focus on improving the new code added in the PR (lines starting with '+')
Expand Down