Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(action): fixed issue with var
Browse files Browse the repository at this point in the history
DarrellRichards committed Jun 1, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent f699e0f commit ecfa3df
Showing 2 changed files with 57 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 [];
}

28 changes: 28 additions & 0 deletions src/services/ai.ts
Original file line number Diff line number Diff line change
@@ -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": "<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 {

0 comments on commit ecfa3df

Please sign in to comment.