Skip to content

Commit

Permalink
chore(action): fixed issue with var
Browse files Browse the repository at this point in the history
  • Loading branch information
DarrellRichards committed Jun 4, 2024
1 parent ddd2990 commit f73b3d7
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 200 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pr-number: ${{ github.event.number }}
openai_api_key: ${{ secrets.OPEN_AI_KEY }}
openai_model: 'gpt-4o'
openai_model: "gpt-4o"
review_code: true
expluded_files: 'node_modules, package.json, package-lock.json'
expluded_files: "node_modules, package.json, package-lock.json"
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
excluded_files:
description: 'Files to exclude from review'
required: false
default: 'node_modules, package-lock.json, yarn.lock'
default: "node_modules, package-lock.json, yarn.lock"
openai_api_key:
description: 'OpenAI API key'
required: true
Expand Down
67 changes: 33 additions & 34 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from "fs"
import parseDiff, { File } from "parse-diff"
import * as core from "@actions/core"

import { commentOnPullRequest, compareCommits, createReviewComment, gitDiff, PRDetails, updateBody } from "./services/github";
import { commentOnPullRequest, compareCommits, createReviewComment, getPullRequestDiff, PRDetails, updateBody } from "./services/github";
import { minimatch } from "minimatch";
import { obtainFeedback, prSummaryCreation, summaryAllMessages, summaryOfAllFeedback, validateCodeViaAI } from "./services/ai";

Expand Down Expand Up @@ -52,9 +52,8 @@ async function validatePullRequest(diff: File[], details: Details) {


if (foundSummary && foundSummary.length > 0) {
const bodyIdea = await summaryAllMessages(foundSummary);
console.log('Summary of all messages', bodyIdea);
return bodyIdea;
const compiledSummary = await summaryAllMessages(foundSummary);
return compiledSummary;
}

return '';
Expand Down Expand Up @@ -83,7 +82,7 @@ async function validateCode(diff: File[], details: Details) {
return {
body: result.review,
path: file.to,
line: Number(result.lineNumber)
line: parseInt(result.lineNumber, 10)
};
});

Expand Down Expand Up @@ -130,28 +129,27 @@ async function validateOverallCodeReview(diff: File[], details: Details) {
async function main() {
let dif: string | null = null;
const { action, repository, number, before, after } = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf-8"))
const { title, description, patch_url, diff_url } = await PRDetails(repository, number);
const data = await gitDiff(repository.owner.login, repository.name, number);
const { title, description } = await PRDetails(repository, number);
if (action === "opened" || action === "reopened") {
const data = await getPullRequestDiff(repository.owner.login, repository.name, number);
dif = data as unknown as string;
// if (action === "opened") {

// } else if (action === "synchronize") {
// const newBaseSha = before;
// const newHeadSha = after;
} else if (action === "synchronize") {
const newBaseSha = before;
const newHeadSha = after;

// const data = await compareCommits({
// owner: repository.owner.login,
// repo: repository.name,
// before: newBaseSha,
// after: newHeadSha,
// number
// })
const data = await compareCommits({
owner: repository.owner.login,
repo: repository.name,
before: newBaseSha,
after: newHeadSha,
number
})

// dif = String(data);
// } else {
// console.log('Unknown action', process.env.GITHUB_EVENT_NAME);
// return;
// }
dif = String(data);
} else {
console.log('Unknown action', process.env.GITHUB_EVENT_NAME);
return;
}

if (!dif) {
console.log('No diff found, exiting')
Expand All @@ -173,7 +171,9 @@ async function main() {
description
});

await updateBody(repository.owner.login, repository.name, number, summary)
if (summary) {
await updateBody(repository.owner.login, repository.name, number, summary);
}
}

if (overallReview) {
Expand All @@ -184,12 +184,13 @@ async function main() {

if (detailedFeedback && detailedFeedback.length > 0) {
const resultsFullFeedback = await summaryOfAllFeedback(detailedFeedback);

await commentOnPullRequest({
owner: repository.owner.login,
repo: repository.name,
number
}, resultsFullFeedback);
if (resultsFullFeedback) {
await commentOnPullRequest({
owner: repository.owner.login,
repo: repository.name,
number
}, resultsFullFeedback);
}
}
}
}
Expand All @@ -200,10 +201,8 @@ async function main() {
description
});

if (neededComments && neededComments.length > 0) {
if (neededComments) {
await createReviewComment(repository.owner.login, repository.name, number, neededComments);
} else {
await createReviewComment(repository.owner.login, repository.name, number, neededComments)
}
}
}
Expand Down
Loading

0 comments on commit f73b3d7

Please sign in to comment.