mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 09:36:47 +00:00
Fixed incorrect parameters passing
This commit is contained in:
parent
e8074efc8b
commit
bbd546b889
3 changed files with 18 additions and 48 deletions
32
dist/index.js
vendored
32
dist/index.js
vendored
|
@ -28,9 +28,6 @@ require("./sourcemap-register.js");
|
||||||
* - OPENAI_BASE_URL: Base URL for the OpenAI API (optional)
|
* - OPENAI_BASE_URL: Base URL for the OpenAI API (optional)
|
||||||
* - DEBUG_HTTP: Enable HTTP request debugging (optional)
|
* - DEBUG_HTTP: Enable HTTP request debugging (optional)
|
||||||
*
|
*
|
||||||
* Example Usage:
|
|
||||||
* npx ts-node main.ts
|
|
||||||
*
|
|
||||||
* Note: It is recommended to set the GITHUB_TOKEN and OPENAI_API_KEY environment variables to avoid exposing sensitive information.
|
* Note: It is recommended to set the GITHUB_TOKEN and OPENAI_API_KEY environment variables to avoid exposing sensitive information.
|
||||||
*/
|
*/
|
||||||
var __createBinding =
|
var __createBinding =
|
||||||
|
@ -168,26 +165,18 @@ require("./sourcemap-register.js");
|
||||||
* @returns {Promise<PRDetails>} - A promise that resolves to the pull request details.
|
* @returns {Promise<PRDetails>} - A promise that resolves to the pull request details.
|
||||||
*
|
*
|
||||||
* @throws {Error} - Throws an error if the event type is unsupported.
|
* @throws {Error} - Throws an error if the event type is unsupported.
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
* const prDetails = await getPrDetails("opened");
|
|
||||||
* console.log(prDetails);
|
|
||||||
*/
|
*/
|
||||||
function getPrDetails(event) {
|
function getPrDetails(eventName, eventData) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const eventPath = process.env.GITHUB_EVENT_PATH || "";
|
const eventPath = process.env.GITHUB_EVENT_PATH || "";
|
||||||
const eventData = JSON.parse(
|
switch (eventName) {
|
||||||
(0, fs_1.readFileSync)(eventPath, "utf8")
|
|
||||||
);
|
|
||||||
console.log("GitHub Event Data:", eventData); // Log the event data for debugging
|
|
||||||
switch (event) {
|
|
||||||
case "opened":
|
case "opened":
|
||||||
case "synchronize":
|
case "synchronize":
|
||||||
return getPrFromEvent(eventData);
|
return getPrFromEvent(eventData);
|
||||||
case "push":
|
case "push":
|
||||||
return getPrFromApi(eventData);
|
return getPrFromApi(eventData);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported event: ${event}`);
|
throw new Error(`Unsupported event: action=${eventName}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -293,11 +282,6 @@ require("./sourcemap-register.js");
|
||||||
* @param {File[]} parsedDiff - An array of parsed diff files to be analyzed.
|
* @param {File[]} parsedDiff - An array of parsed diff files to be analyzed.
|
||||||
* @param {PRDetails} prDetails - Details of the pull request, including owner, repo, pull number, title, and description.
|
* @param {PRDetails} prDetails - Details of the pull request, including owner, repo, pull number, title, and description.
|
||||||
* @returns {Promise<Array<{ body: string; path: string; line: number }>>} - A promise that resolves to an array of review comments.
|
* @returns {Promise<Array<{ body: string; path: string; line: number }>>} - A promise that resolves to an array of review comments.
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
* const parsedDiff = parseDiff(diff);
|
|
||||||
* const prDetails = await getPRDetails();
|
|
||||||
* const comments = await analyzeCode(parsedDiff, prDetails);
|
|
||||||
*/
|
*/
|
||||||
function analyzeCode(parsedDiff, prDetails) {
|
function analyzeCode(parsedDiff, prDetails) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
@ -498,10 +482,6 @@ ${chunk.changes
|
||||||
*
|
*
|
||||||
* @param {File[]} parsedDiff - An array of parsed diff files to be filtered.
|
* @param {File[]} parsedDiff - An array of parsed diff files to be filtered.
|
||||||
* @returns {File[]} - An array of filtered diff files.
|
* @returns {File[]} - An array of filtered diff files.
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
* const parsedDiff = parseDiff(diff);
|
|
||||||
* const filteredDiff = filterDiffs(parsedDiff);
|
|
||||||
*/
|
*/
|
||||||
function filterDiffs(parsedDiff) {
|
function filterDiffs(parsedDiff) {
|
||||||
const excludePatterns = core
|
const excludePatterns = core
|
||||||
|
@ -549,8 +529,10 @@ ${chunk.changes
|
||||||
"utf8"
|
"utf8"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
console.log("GitHub triggered event data:", eventData);
|
const eventName = process.env.GITHUB_EVENT_NAME;
|
||||||
const prDetails = yield getPrDetails(eventData);
|
console.log("GitHub event name:", eventName);
|
||||||
|
console.log("GitHub event data:", eventData);
|
||||||
|
const prDetails = yield getPrDetails(eventName, eventData);
|
||||||
if (!prDetails) {
|
if (!prDetails) {
|
||||||
console.log(
|
console.log(
|
||||||
"No associated pull request found for this push event."
|
"No associated pull request found for this push event."
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
32
src/main.ts
32
src/main.ts
|
@ -82,25 +82,20 @@ interface PRDetails {
|
||||||
* @returns {Promise<PRDetails>} - A promise that resolves to the pull request details.
|
* @returns {Promise<PRDetails>} - A promise that resolves to the pull request details.
|
||||||
*
|
*
|
||||||
* @throws {Error} - Throws an error if the event type is unsupported.
|
* @throws {Error} - Throws an error if the event type is unsupported.
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
* const prDetails = await getPrDetails("opened");
|
|
||||||
* console.log(prDetails);
|
|
||||||
*/
|
*/
|
||||||
async function getPrDetails(event: GitHubEvent): Promise<PRDetails> {
|
async function getPrDetails(
|
||||||
|
eventName: GitHubEvent,
|
||||||
|
eventData: any
|
||||||
|
): Promise<PRDetails> {
|
||||||
const eventPath = process.env.GITHUB_EVENT_PATH || "";
|
const eventPath = process.env.GITHUB_EVENT_PATH || "";
|
||||||
const eventData = JSON.parse(readFileSync(eventPath, "utf8"));
|
switch (eventName) {
|
||||||
|
|
||||||
console.log("GitHub Event Data:", eventData); // Log the event data for debugging
|
|
||||||
|
|
||||||
switch (event) {
|
|
||||||
case "opened":
|
case "opened":
|
||||||
case "synchronize":
|
case "synchronize":
|
||||||
return getPrFromEvent(eventData);
|
return getPrFromEvent(eventData);
|
||||||
case "push":
|
case "push":
|
||||||
return getPrFromApi(eventData);
|
return getPrFromApi(eventData);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported event: ${event}`);
|
throw new Error(`Unsupported event: action=${eventName}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,11 +196,6 @@ async function getDiff(
|
||||||
* @param {File[]} parsedDiff - An array of parsed diff files to be analyzed.
|
* @param {File[]} parsedDiff - An array of parsed diff files to be analyzed.
|
||||||
* @param {PRDetails} prDetails - Details of the pull request, including owner, repo, pull number, title, and description.
|
* @param {PRDetails} prDetails - Details of the pull request, including owner, repo, pull number, title, and description.
|
||||||
* @returns {Promise<Array<{ body: string; path: string; line: number }>>} - A promise that resolves to an array of review comments.
|
* @returns {Promise<Array<{ body: string; path: string; line: number }>>} - A promise that resolves to an array of review comments.
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
* const parsedDiff = parseDiff(diff);
|
|
||||||
* const prDetails = await getPRDetails();
|
|
||||||
* const comments = await analyzeCode(parsedDiff, prDetails);
|
|
||||||
*/
|
*/
|
||||||
async function analyzeCode(
|
async function analyzeCode(
|
||||||
parsedDiff: File[],
|
parsedDiff: File[],
|
||||||
|
@ -405,10 +395,6 @@ async function createReviewComment(
|
||||||
*
|
*
|
||||||
* @param {File[]} parsedDiff - An array of parsed diff files to be filtered.
|
* @param {File[]} parsedDiff - An array of parsed diff files to be filtered.
|
||||||
* @returns {File[]} - An array of filtered diff files.
|
* @returns {File[]} - An array of filtered diff files.
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
* const parsedDiff = parseDiff(diff);
|
|
||||||
* const filteredDiff = filterDiffs(parsedDiff);
|
|
||||||
*/
|
*/
|
||||||
function filterDiffs(parsedDiff: File[]): File[] {
|
function filterDiffs(parsedDiff: File[]): File[] {
|
||||||
const excludePatterns = core
|
const excludePatterns = core
|
||||||
|
@ -443,9 +429,11 @@ async function main() {
|
||||||
const eventData = JSON.parse(
|
const eventData = JSON.parse(
|
||||||
readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8")
|
readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8")
|
||||||
);
|
);
|
||||||
console.log("GitHub triggered event data:", eventData);
|
const eventName = process.env.GITHUB_EVENT_NAME as GitHubEvent;
|
||||||
|
console.log("GitHub event name:", eventName);
|
||||||
|
console.log("GitHub event data:", eventData);
|
||||||
|
|
||||||
const prDetails = await getPrDetails(eventData);
|
const prDetails = await getPrDetails(eventName, eventData);
|
||||||
if (!prDetails) {
|
if (!prDetails) {
|
||||||
console.log("No associated pull request found for this push event.");
|
console.log("No associated pull request found for this push event.");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue