mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-21 18:16:47 +00:00
Merge pull request #18 from arunsnt/CICO-111286
CICO-111286: Fix line number error
This commit is contained in:
commit
52f21b7ca5
3 changed files with 24 additions and 85 deletions
43
dist/index.js
vendored
43
dist/index.js
vendored
|
@ -51,7 +51,7 @@ const minimatch_1 = __importDefault(__nccwpck_require__(2002));
|
||||||
const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN");
|
const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN");
|
||||||
const OPENAI_API_KEY = core.getInput("OPENAI_API_KEY");
|
const OPENAI_API_KEY = core.getInput("OPENAI_API_KEY");
|
||||||
const OPENAI_API_MODEL = core.getInput("OPENAI_API_MODEL");
|
const OPENAI_API_MODEL = core.getInput("OPENAI_API_MODEL");
|
||||||
const FRAMEWORK = core.getInput("framework");
|
const FRAMEWORK = core.getInput("framework"); // New input for framework
|
||||||
const octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
const octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
||||||
const openai = new openai_1.default({
|
const openai = new openai_1.default({
|
||||||
apiKey: OPENAI_API_KEY,
|
apiKey: OPENAI_API_KEY,
|
||||||
|
@ -106,6 +106,7 @@ function analyzeCode(parsedDiff, prDetails) {
|
||||||
return comments;
|
return comments;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Function to get Ruby on Rails guidelines
|
||||||
function getRailsGuidelines() {
|
function getRailsGuidelines() {
|
||||||
return `
|
return `
|
||||||
- Avoid Environment Specific Code:
|
- Avoid Environment Specific Code:
|
||||||
|
@ -363,7 +364,7 @@ ${chunk.changes
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
function getAIResponse(prompt) {
|
function getAIResponse(prompt) {
|
||||||
var _a, _b;
|
var _a, _b, _c;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const queryConfig = {
|
const queryConfig = {
|
||||||
model: OPENAI_API_MODEL,
|
model: OPENAI_API_MODEL,
|
||||||
|
@ -383,16 +384,8 @@ function getAIResponse(prompt) {
|
||||||
// Log the raw response for debugging
|
// Log the raw response for debugging
|
||||||
console.log('Raw response:', JSON.stringify(response, null, 2));
|
console.log('Raw response:', JSON.stringify(response, null, 2));
|
||||||
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
||||||
let jsonContent = null;
|
// Extract JSON content from Markdown code block
|
||||||
// Check if the response is in a code block
|
const jsonContent = (_c = res.match(/```json([\s\S]*)```/)) === null || _c === void 0 ? void 0 : _c[1];
|
||||||
const codeBlockMatch = res.match(/```json([\s\S]*)```/);
|
|
||||||
if (codeBlockMatch) {
|
|
||||||
jsonContent = codeBlockMatch[1];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// If not, assume the response is direct JSON
|
|
||||||
jsonContent = res;
|
|
||||||
}
|
|
||||||
if (!jsonContent) {
|
if (!jsonContent) {
|
||||||
console.error("Failed to extract JSON content from response.");
|
console.error("Failed to extract JSON content from response.");
|
||||||
return null;
|
return null;
|
||||||
|
@ -441,34 +434,13 @@ function createComment(file, chunk, aiResponses) {
|
||||||
}
|
}
|
||||||
function createReviewComment(owner, repo, pull_number, comments) {
|
function createReviewComment(owner, repo, pull_number, comments) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const validComments = comments.filter(comment => comment.path && comment.line > 0 && comment.body.trim() !== "");
|
|
||||||
if (validComments.length === 0) {
|
|
||||||
console.log("No valid comments to add");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log("Attempting to create review comments:", JSON.stringify(validComments, null, 2));
|
|
||||||
for (const comment of validComments) {
|
|
||||||
try {
|
|
||||||
yield octokit.pulls.createReview({
|
yield octokit.pulls.createReview({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
pull_number,
|
pull_number,
|
||||||
body: comment.body,
|
comments,
|
||||||
path: comment.path,
|
event: "COMMENT",
|
||||||
line: comment.line,
|
|
||||||
event: 'COMMENT',
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error("Error creating review comment:", error);
|
|
||||||
console.log("Request data:", {
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
pull_number,
|
|
||||||
comment,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function main() {
|
function main() {
|
||||||
|
@ -503,7 +475,6 @@ function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parsedDiff = (0, parse_diff_1.default)(diff);
|
const parsedDiff = (0, parse_diff_1.default)(diff);
|
||||||
console.log("Parsed Diff:", JSON.stringify(parsedDiff, null, 2)); // Log parsed diff for debugging
|
|
||||||
const excludePatterns = core
|
const excludePatterns = core
|
||||||
.getInput("exclude")
|
.getInput("exclude")
|
||||||
.split(",")
|
.split(",")
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
44
src/main.ts
44
src/main.ts
|
@ -8,7 +8,7 @@ import minimatch from "minimatch";
|
||||||
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
|
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
|
||||||
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
|
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
|
||||||
const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL");
|
const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL");
|
||||||
const FRAMEWORK: string = core.getInput("framework");
|
const FRAMEWORK: string = core.getInput("framework"); // New input for framework
|
||||||
|
|
||||||
const octokit = new Octokit({ auth: GITHUB_TOKEN });
|
const octokit = new Octokit({ auth: GITHUB_TOKEN });
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ async function analyzeCode(
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to get Ruby on Rails guidelines
|
||||||
function getRailsGuidelines(): string {
|
function getRailsGuidelines(): string {
|
||||||
return `
|
return `
|
||||||
- Avoid Environment Specific Code:
|
- Avoid Environment Specific Code:
|
||||||
|
@ -368,16 +369,8 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
||||||
|
|
||||||
const res = response.choices[0].message?.content?.trim() || "";
|
const res = response.choices[0].message?.content?.trim() || "";
|
||||||
|
|
||||||
let jsonContent: string | null = null;
|
// Extract JSON content from Markdown code block
|
||||||
|
const jsonContent = res.match(/```json([\s\S]*)```/)?.[1];
|
||||||
// Check if the response is in a code block
|
|
||||||
const codeBlockMatch = res.match(/```json([\s\S]*)```/);
|
|
||||||
if (codeBlockMatch) {
|
|
||||||
jsonContent = codeBlockMatch[1];
|
|
||||||
} else {
|
|
||||||
// If not, assume the response is direct JSON
|
|
||||||
jsonContent = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!jsonContent) {
|
if (!jsonContent) {
|
||||||
console.error("Failed to extract JSON content from response.");
|
console.error("Failed to extract JSON content from response.");
|
||||||
|
@ -441,36 +434,13 @@ async function createReviewComment(
|
||||||
pull_number: number,
|
pull_number: number,
|
||||||
comments: Array<{ body: string; path: string; line: number }>
|
comments: Array<{ body: string; path: string; line: number }>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const validComments = comments.filter(comment => comment.path && comment.line > 0 && comment.body.trim() !== "");
|
|
||||||
|
|
||||||
if (validComments.length === 0) {
|
|
||||||
console.log("No valid comments to add");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Attempting to create review comments:", JSON.stringify(validComments, null, 2));
|
|
||||||
|
|
||||||
for (const comment of validComments) {
|
|
||||||
try {
|
|
||||||
await octokit.pulls.createReview({
|
await octokit.pulls.createReview({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
pull_number,
|
pull_number,
|
||||||
body: comment.body,
|
comments,
|
||||||
path: comment.path,
|
event: "COMMENT",
|
||||||
line: comment.line,
|
|
||||||
event: 'COMMENT',
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
console.error("Error creating review comment:", error);
|
|
||||||
console.log("Request data:", {
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
pull_number,
|
|
||||||
comment,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
@ -513,8 +483,6 @@ async function main() {
|
||||||
|
|
||||||
const parsedDiff = parseDiff(diff);
|
const parsedDiff = parseDiff(diff);
|
||||||
|
|
||||||
console.log("Parsed Diff:", JSON.stringify(parsedDiff, null, 2)); // Log parsed diff for debugging
|
|
||||||
|
|
||||||
const excludePatterns = core
|
const excludePatterns = core
|
||||||
.getInput("exclude")
|
.getInput("exclude")
|
||||||
.split(",")
|
.split(",")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue