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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
Binary file added base64-key.txt
Binary file not shown.
1 change: 1 addition & 0 deletions external/tree-sitter-python
Submodule tree-sitter-python added at 6d14e4
9,743 changes: 8,247 additions & 1,496 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@
"@octokit/rest": "^20.0.2",
"@octokit/webhooks-definitions": "^3.67.3",
"@types/node": "^20.8.3",
"axios": "^1.7.7",
"chalk": "^5.3.0",
"diff": "^5.1.0",
"dotenv": "^16.3.1",
"gpt-tokenizer": "^2.1.2",
"groq-sdk": "^0.8.0",
"octokit": "^3.1.1",
"tree-sitter": "^0.21.1",
"tree-sitter-python": "^0.23.4",
"xml2js": "^0.6.2"
},
"devDependencies": {
"@types/babel__traverse": "^7.20.3",
"@types/diff": "^5.0.7",
"@types/jest": "^29.5.14",
"@types/xml2js": "^0.4.13",
"csv-writer": "^1.6.0",
"jest": "^29.7.0",
"smee-client": "^1.2.3",
"ts-jest": "^29.2.5",
"tsx": "^4.19.2",
"typescript": "^5.2.2"
}

}
61 changes: 51 additions & 10 deletions src/context/language/python-parser.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
import Parser from "tree-sitter";
import Python from "tree-sitter-python";
import { AbstractParser, EnclosingContext } from "../../constants";

export class PythonParser implements AbstractParser {
findEnclosingContext(
file: string,
lineStart: number,
lineEnd: number
): EnclosingContext {
// TODO: Implement this method for Python
return null;
private parser: Parser;

constructor() {
this.parser = new Parser();
this.parser.setLanguage(Python); // Initialize the parser with the Python grammar
}

findEnclosingContext(file: string, lineStart: number, lineEnd: number): EnclosingContext {
const tree = this.parser.parse(file); // Parse the Python file content
const rootNode = tree.rootNode;

let largestContext = { size: 0, context: null as Parser.SyntaxNode | null };
const relevantNodeTypes = ["class_definition", "function_definition"];

// Recursive function to traverse the AST and update the largest context
const visitNode = (node: Parser.SyntaxNode) => {
const startLine = node.startPosition.row + 1; // Tree-sitter rows are 0-indexed
const endLine = node.endPosition.row + 1;

// Check if the node is relevant and spans the specified range
if (relevantNodeTypes.includes(node.type) && startLine <= lineStart && endLine >= lineEnd) {
const size = endLine - startLine;
if (size < largestContext.size || largestContext.context === null) {
largestContext.size = size;
largestContext.context = node;
}
}

// Recurse into child nodes
for (const child of node.children) {
visitNode(child);
}
};

// Start the traversal
visitNode(rootNode);

return {
enclosingContext: largestContext.context,
} as EnclosingContext;
}

dryRun(file: string): { valid: boolean; error: string } {
// TODO: Implement this method for Python
return { valid: false, error: "Not implemented yet" };
try {
this.parser.parse(file); // Try parsing the Python file
return { valid: true, error: "" }; // If no errors, it's valid
} catch (e) {
return { valid: false, error: e.message }; // Catch parsing errors
}
}
}
}
6 changes: 5 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { createPrivateKey } from "crypto";
import chalk from "chalk";

dotenv.config();
console.log("GITHUB_PRIVATE_KEY:", process.env.GITHUB_PRIVATE_KEY);

const privateKeyBase64 = process.env.GITHUB_PRIVATE_KEY;
const privateKey = Buffer.from(privateKeyBase64, "base64").toString("utf-8");

export const env = {
GITHUB_APP_ID: process.env.GITHUB_APP_ID,
GITHUB_PRIVATE_KEY: process.env.GITHUB_PRIVATE_KEY,
GITHUB_PRIVATE_KEY: privateKey,
GITHUB_WEBHOOK_SECRET: process.env.GITHUB_WEBHOOK_SECRET,
GROQ_API_KEY: process.env.GROQ_API_KEY,
} as const;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"outDir": "./dist",
"sourceMap": true,
"noImplicitAny": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "es6"
},
Expand Down