From ecfa3df8aed953c48328e700c0a8787efbd8c20c Mon Sep 17 00:00:00 2001 From: Darrell Richards Date: Sat, 1 Jun 2024 17:27:46 -0400 Subject: [PATCH] chore(action): fixed issue with var --- src/index.ts | 31 +++++++++++++++++++++++++++++-- src/services/ai.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 773c70b..3efec7b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import * as core from "@actions/core" import { createReviewComment, gitDiff, PRDetails } from "./services/github"; import { filter, minimatch } from "minimatch"; -import { prSummaryCreation, validateCodeViaAI } from "./services/ai"; +import { prSummaryCreation, summaryAllMessages, validateCodeViaAI } from "./services/ai"; const excludedFiles = core.getInput("expluded_files").split(",").map((s: string) => s.trim()); @@ -19,10 +19,35 @@ export interface Details { async function validateCode(diff: File[], details: Details) { const neededComments = []; + const foundSummary = []; for (const file of diff) { for (const chunk of file.chunks) { const message = await prSummaryCreation(file, chunk, details); console.log('message', message); + if (message) { + const mappedResults = message.flatMap((result: any) => { + if (!result.changes) { + return []; + } + + if (!result.typeChanges) { + return []; + } + + if (!result.checklist) { + return []; + } + + + return { + changes: result.changes, + typeChanges: result.typeChanges, + checklist: result.checklist, + }; + }); + + foundSummary.push(...mappedResults); + } // const results = await validateCodeViaAI(file, chunk, details); // if (results) { @@ -54,7 +79,9 @@ async function validateCode(diff: File[], details: Details) { } - console.log() + if (foundSummary && foundSummary.length > 0) { + summaryAllMessages(foundSummary); + } return []; } diff --git a/src/services/ai.ts b/src/services/ai.ts index c311bd0..e751977 100644 --- a/src/services/ai.ts +++ b/src/services/ai.ts @@ -82,6 +82,34 @@ export async function prSummaryCreation(file: File, chunk: Chunk, details: Detai return JSON.parse(resss).summary; } +export async function summaryAllMessages(summaries: any[]) { + const message = ` + Your requirement is to merge all the summaries into one summary. + Instructions below: + - Provide a detailed summary of all the pull request summaries. + - Please write the result in Github Markdown Format. + - Provide the written summary in the following JSON format: {"summary": ""}. + + Summaries to review: ${summaries.map((s) => s.changes).join(", ")} + ` + + const response = await openai.chat.completions.create({ + model: "gpt-4-1106-preview", + response_format: { + type: "json_object", + }, + messages: [ + { + role: "system", + content: message, + }, + ], + }); + + const resss = response.choices[0].message?.content?.trim() || "{}"; + console.log('resss', JSON.parse(resss)); +} + export async function validateCodeViaAI(file: File, chunk: Chunk, details: Details) { try {