This commit is contained in:
Michael Lahr 2024-03-14 10:58:32 +08:00
commit 0ab6d2521f

View file

@ -1,15 +1,15 @@
import { readFileSync } from "fs";
import {readFileSync} from "fs";
import * as core from "@actions/core";
import OpenAI from "openai";
import { Octokit } from "@octokit/rest";
import parseDiff, { Chunk, File } from "parse-diff";
import {Octokit} from "@octokit/rest";
import parseDiff, {Chunk, File} from "parse-diff";
import minimatch from "minimatch";
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
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({
apiKey: OPENAI_API_KEY,
@ -24,7 +24,7 @@ interface PRDetails {
}
async function getPRDetails(): Promise<PRDetails> {
const { repository, number } = JSON.parse(
const {repository, number} = JSON.parse(
readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8")
);
const prResponse = await octokit.pulls.get({
@ -50,7 +50,7 @@ async function getDiff(
owner,
repo,
pull_number,
mediaType: { format: "diff" },
mediaType: {format: "diff"},
});
// @ts-expect-error - response.data is a string
return response.data;
@ -128,7 +128,7 @@ async function getAIResponse(prompt: string): Promise<Array<{
...queryConfig,
// return JSON if the model supports it:
...(OPENAI_API_MODEL === "gpt-4-1106-preview"
? { response_format: { type: "json_object" } }
? {response_format: {type: "json_object"}}
: {}),
messages: [
{
@ -227,8 +227,11 @@ async function main() {
.map((s) => s.trim());
const filteredDiff = parsedDiff.filter((file) => {
return !excludePatterns.some((pattern) =>
minimatch(file.to ?? "", pattern)
return !excludePatterns.some((pattern) => {
let isMatch = minimatch(file.to ?? "", pattern);
console.log(file+","+file.to+","+pattern+": "+isMatch)
return isMatch
}
);
});