mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-28 20:14:14 +00:00
debug
This commit is contained in:
parent
a9a064dfa1
commit
0ab6d2521f
1 changed files with 174 additions and 171 deletions
21
src/main.ts
21
src/main.ts
|
@ -1,15 +1,15 @@
|
||||||
import { readFileSync } from "fs";
|
import {readFileSync} from "fs";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { Octokit } from "@octokit/rest";
|
import {Octokit} from "@octokit/rest";
|
||||||
import parseDiff, { Chunk, File } from "parse-diff";
|
import parseDiff, {Chunk, File} from "parse-diff";
|
||||||
import minimatch from "minimatch";
|
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 octokit = new Octokit({ auth: GITHUB_TOKEN });
|
const octokit = new Octokit({auth: GITHUB_TOKEN});
|
||||||
|
|
||||||
const openai = new OpenAI({
|
const openai = new OpenAI({
|
||||||
apiKey: OPENAI_API_KEY,
|
apiKey: OPENAI_API_KEY,
|
||||||
|
@ -24,7 +24,7 @@ interface PRDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPRDetails(): Promise<PRDetails> {
|
async function getPRDetails(): Promise<PRDetails> {
|
||||||
const { repository, number } = JSON.parse(
|
const {repository, number} = JSON.parse(
|
||||||
readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8")
|
readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8")
|
||||||
);
|
);
|
||||||
const prResponse = await octokit.pulls.get({
|
const prResponse = await octokit.pulls.get({
|
||||||
|
@ -50,7 +50,7 @@ async function getDiff(
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
pull_number,
|
pull_number,
|
||||||
mediaType: { format: "diff" },
|
mediaType: {format: "diff"},
|
||||||
});
|
});
|
||||||
// @ts-expect-error - response.data is a string
|
// @ts-expect-error - response.data is a string
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -128,7 +128,7 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
||||||
...queryConfig,
|
...queryConfig,
|
||||||
// return JSON if the model supports it:
|
// return JSON if the model supports it:
|
||||||
...(OPENAI_API_MODEL === "gpt-4-1106-preview"
|
...(OPENAI_API_MODEL === "gpt-4-1106-preview"
|
||||||
? { response_format: { type: "json_object" } }
|
? {response_format: {type: "json_object"}}
|
||||||
: {}),
|
: {}),
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
|
@ -227,8 +227,11 @@ async function main() {
|
||||||
.map((s) => s.trim());
|
.map((s) => s.trim());
|
||||||
|
|
||||||
const filteredDiff = parsedDiff.filter((file) => {
|
const filteredDiff = parsedDiff.filter((file) => {
|
||||||
return !excludePatterns.some((pattern) =>
|
return !excludePatterns.some((pattern) => {
|
||||||
minimatch(file.to ?? "", pattern)
|
let isMatch = minimatch(file.to ?? "", pattern);
|
||||||
|
console.log(file+","+file.to+","+pattern+": "+isMatch)
|
||||||
|
return isMatch
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue