mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2024-11-26 22:19:03 +00:00
run package command
This commit is contained in:
parent
838fc48abe
commit
74ae89bb37
159
dist/index.js
vendored
159
dist/index.js
vendored
@ -6,41 +6,88 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
var __createBinding =
|
||||||
|
(this && this.__createBinding) ||
|
||||||
|
(Object.create
|
||||||
|
? function (o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
if (
|
||||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
!desc ||
|
||||||
|
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
||||||
|
) {
|
||||||
|
desc = {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () {
|
||||||
|
return m[k];
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Object.defineProperty(o, k2, desc);
|
Object.defineProperty(o, k2, desc);
|
||||||
}) : (function(o, m, k, k2) {
|
}
|
||||||
|
: function (o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
o[k2] = m[k];
|
o[k2] = m[k];
|
||||||
}));
|
});
|
||||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
var __setModuleDefault =
|
||||||
|
(this && this.__setModuleDefault) ||
|
||||||
|
(Object.create
|
||||||
|
? function (o, v) {
|
||||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
}) : function(o, v) {
|
}
|
||||||
|
: function (o, v) {
|
||||||
o["default"] = v;
|
o["default"] = v;
|
||||||
});
|
});
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar =
|
||||||
|
(this && this.__importStar) ||
|
||||||
|
function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
if (mod != null)
|
||||||
|
for (var k in mod)
|
||||||
|
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
||||||
|
__createBinding(result, mod, k);
|
||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter =
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
(this && this.__awaiter) ||
|
||||||
|
function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) {
|
||||||
|
return value instanceof P
|
||||||
|
? value
|
||||||
|
: new P(function (resolve) {
|
||||||
|
resolve(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
function fulfilled(value) {
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
try {
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
step(generator.next(value));
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function rejected(value) {
|
||||||
|
try {
|
||||||
|
step(generator["throw"](value));
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function step(result) {
|
||||||
|
result.done
|
||||||
|
? resolve(result.value)
|
||||||
|
: adopt(result.value).then(fulfilled, rejected);
|
||||||
|
}
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault =
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
(this && this.__importDefault) ||
|
||||||
};
|
function (mod) {
|
||||||
|
return mod && mod.__esModule ? mod : { default: mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const fs_1 = __nccwpck_require__(7147);
|
const fs_1 = __nccwpck_require__(7147);
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
@ -50,6 +97,7 @@ const parse_diff_1 = __importDefault(__nccwpck_require__(4833));
|
|||||||
const minimatch_1 = __importDefault(__nccwpck_require__(2002));
|
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 octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
const octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
||||||
const configuration = new openai_1.Configuration({
|
const configuration = new openai_1.Configuration({
|
||||||
apiKey: OPENAI_API_KEY,
|
apiKey: OPENAI_API_KEY,
|
||||||
@ -58,7 +106,9 @@ const openai = new openai_1.OpenAIApi(configuration);
|
|||||||
function getPRDetails() {
|
function getPRDetails() {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const { repository, number } = JSON.parse((0, fs_1.readFileSync)(process.env.GITHUB_EVENT_PATH || "", "utf8"));
|
const { repository, number } = JSON.parse(
|
||||||
|
(0, fs_1.readFileSync)(process.env.GITHUB_EVENT_PATH || "", "utf8")
|
||||||
|
);
|
||||||
const prResponse = yield octokit.pulls.get({
|
const prResponse = yield octokit.pulls.get({
|
||||||
owner: repository.owner.login,
|
owner: repository.owner.login,
|
||||||
repo: repository.name,
|
repo: repository.name,
|
||||||
@ -69,7 +119,8 @@ function getPRDetails() {
|
|||||||
repo: repository.name,
|
repo: repository.name,
|
||||||
pull_number: number,
|
pull_number: number,
|
||||||
title: (_a = prResponse.data.title) !== null && _a !== void 0 ? _a : "",
|
title: (_a = prResponse.data.title) !== null && _a !== void 0 ? _a : "",
|
||||||
description: (_b = prResponse.data.body) !== null && _b !== void 0 ? _b : "",
|
description:
|
||||||
|
(_b = prResponse.data.body) !== null && _b !== void 0 ? _b : "",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -89,8 +140,7 @@ function analyzeCode(parsedDiff, prDetails) {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const comments = [];
|
const comments = [];
|
||||||
for (const file of parsedDiff) {
|
for (const file of parsedDiff) {
|
||||||
if (file.to === "/dev/null")
|
if (file.to === "/dev/null") continue; // Ignore deleted files
|
||||||
continue; // Ignore deleted files
|
|
||||||
for (const chunk of file.chunks) {
|
for (const chunk of file.chunks) {
|
||||||
const prompt = createPrompt(file, chunk, prDetails);
|
const prompt = createPrompt(file, chunk, prDetails);
|
||||||
const aiResponse = yield getAIResponse(prompt);
|
const aiResponse = yield getAIResponse(prompt);
|
||||||
@ -127,7 +177,9 @@ function createPrompt(file, chunk, prDetails) {
|
|||||||
- Use the given description only for the overall context and only comment the code.
|
- Use the given description only for the overall context and only comment the code.
|
||||||
- IMPORTANT: NEVER suggest adding comments to the code.
|
- IMPORTANT: NEVER suggest adding comments to the code.
|
||||||
|
|
||||||
Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response.
|
Review the following code diff in the file "${
|
||||||
|
file.to
|
||||||
|
}" and take the pull request title and description into account when writing the response.
|
||||||
|
|
||||||
Pull request title: ${prDetails.title}
|
Pull request title: ${prDetails.title}
|
||||||
Pull request description:
|
Pull request description:
|
||||||
@ -151,7 +203,7 @@ function getAIResponse(prompt) {
|
|||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const queryConfig = {
|
const queryConfig = {
|
||||||
model: "gpt-4",
|
model: OPENAI_API_MODEL,
|
||||||
temperature: 0.2,
|
temperature: 0.2,
|
||||||
max_tokens: 700,
|
max_tokens: 700,
|
||||||
top_p: 1,
|
top_p: 1,
|
||||||
@ -159,16 +211,25 @@ function getAIResponse(prompt) {
|
|||||||
presence_penalty: 0,
|
presence_penalty: 0,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = yield openai.createChatCompletion(Object.assign(Object.assign({}, queryConfig), { messages: [
|
const response = yield openai.createChatCompletion(
|
||||||
|
Object.assign(Object.assign({}, queryConfig), {
|
||||||
|
messages: [
|
||||||
{
|
{
|
||||||
role: "system",
|
role: "system",
|
||||||
content: prompt,
|
content: prompt,
|
||||||
},
|
},
|
||||||
] }));
|
],
|
||||||
const res = ((_b = (_a = response.data.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "[]";
|
})
|
||||||
|
);
|
||||||
|
const res =
|
||||||
|
((_b =
|
||||||
|
(_a = response.data.choices[0].message) === null || _a === void 0
|
||||||
|
? void 0
|
||||||
|
: _a.content) === null || _b === void 0
|
||||||
|
? void 0
|
||||||
|
: _b.trim()) || "[]";
|
||||||
return JSON.parse(res);
|
return JSON.parse(res);
|
||||||
}
|
} catch (error) {
|
||||||
catch (error) {
|
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -202,11 +263,21 @@ function main() {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const prDetails = yield getPRDetails();
|
const prDetails = yield getPRDetails();
|
||||||
let diff;
|
let diff;
|
||||||
const eventData = JSON.parse((0, fs_1.readFileSync)((_a = process.env.GITHUB_EVENT_PATH) !== null && _a !== void 0 ? _a : "", "utf8"));
|
const eventData = JSON.parse(
|
||||||
|
(0, fs_1.readFileSync)(
|
||||||
|
(_a = process.env.GITHUB_EVENT_PATH) !== null && _a !== void 0
|
||||||
|
? _a
|
||||||
|
: "",
|
||||||
|
"utf8"
|
||||||
|
)
|
||||||
|
);
|
||||||
if (eventData.action === "opened") {
|
if (eventData.action === "opened") {
|
||||||
diff = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number);
|
diff = yield getDiff(
|
||||||
}
|
prDetails.owner,
|
||||||
else if (eventData.action === "synchronize") {
|
prDetails.repo,
|
||||||
|
prDetails.pull_number
|
||||||
|
);
|
||||||
|
} else if (eventData.action === "synchronize") {
|
||||||
const newBaseSha = eventData.before;
|
const newBaseSha = eventData.before;
|
||||||
const newHeadSha = eventData.after;
|
const newHeadSha = eventData.after;
|
||||||
const response = yield octokit.repos.compareCommits({
|
const response = yield octokit.repos.compareCommits({
|
||||||
@ -220,8 +291,7 @@ function main() {
|
|||||||
.request({ url: response.data.diff_url })
|
.request({ url: response.data.diff_url })
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
: null;
|
: null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME);
|
console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -235,11 +305,22 @@ function main() {
|
|||||||
.split(",")
|
.split(",")
|
||||||
.map((s) => s.trim());
|
.map((s) => s.trim());
|
||||||
const filteredDiff = parsedDiff.filter((file) => {
|
const filteredDiff = parsedDiff.filter((file) => {
|
||||||
return !excludePatterns.some((pattern) => { var _a; return (0, minimatch_1.default)((_a = file.to) !== null && _a !== void 0 ? _a : "", pattern); });
|
return !excludePatterns.some((pattern) => {
|
||||||
|
var _a;
|
||||||
|
return (0, minimatch_1.default)(
|
||||||
|
(_a = file.to) !== null && _a !== void 0 ? _a : "",
|
||||||
|
pattern
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
const comments = yield analyzeCode(filteredDiff, prDetails);
|
const comments = yield analyzeCode(filteredDiff, prDetails);
|
||||||
if (comments.length > 0) {
|
if (comments.length > 0) {
|
||||||
yield createReviewComment(prDetails.owner, prDetails.repo, prDetails.pull_number, comments);
|
yield createReviewComment(
|
||||||
|
prDetails.owner,
|
||||||
|
prDetails.repo,
|
||||||
|
prDetails.pull_number,
|
||||||
|
comments
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user