Skip to content

Commit

Permalink
feat: signoff (#6)
Browse files Browse the repository at this point in the history
* feat: signoff

* fix: formatting

* bump: package version

* fix: formatting
  • Loading branch information
mattzcarey authored Jul 10, 2023
1 parent 1f41d16 commit 37c5daf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "code-review-gpt",
"version": "0.0.14",
"version": "0.0.15",
"description": "Your AI code reviewer",
"bin": {
"code-review-gpt": "./dist/index.js"
Expand Down
7 changes: 4 additions & 3 deletions src/askAI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OpenAIChat } from "langchain/llms/openai";
import { completionPrompt } from "./constants";
import { completionPrompt, signOff } from "./constants";
import { openAIApiKey } from "./args";

const model = new OpenAIChat({
Expand All @@ -18,7 +18,9 @@ const createSummary = async (feedbacks: string[]): Promise<string> => {
feedbacks.join("\n---\n")
);

const summary = await callModel(finalPrompt);
const emojis = await callModel(finalPrompt);

const summary = `\n${emojis}${signOff}`;
console.log(summary);

return summary;
Expand All @@ -44,7 +46,6 @@ export const askAI = async (prompts: string[]): Promise<string> => {
}
};


await Promise.allSettled(feedbackPromises.map(collectAndLogFeedback));
const summary = await createSummary(feedbacks);

Expand Down
16 changes: 10 additions & 6 deletions src/commentOnPR.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { context, getOctokit } from "@actions/github";
import { getGitHubEnvVariables } from "./args";

const getToken = () => {
const { githubToken } = getGitHubEnvVariables();
if (!githubToken) {
throw new Error("GITHUB_TOKEN is not set");
}
return githubToken;
};

export const commentOnPR = async (comment: string) => {
try {
const { githubToken } = getGitHubEnvVariables();
const githubToken = getToken();
const { payload, issue } = context;

if (!githubToken) {
throw new Error("GITHUB_TOKEN is not set");
}


if (!payload.pull_request) {
console.warn("Not a pull request. Skipping commenting on PR...");
return;
}

const octokit = getOctokit(githubToken);

const { owner, repo, number: pull_number } = issue;

await octokit.rest.issues.createComment({
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ You are a senior developer and have just reviewed a pull request. This was your
Please summarise the review using 3 emojis.
`;

export const signOff = `\n---\n#### Powered by [Code Review GPT](https://github.com/mattzcarey/code-review-gpt)`;

export const maxPromptLength = 30000; //max is 8k tokens which is about 40k characters

export const supportedFiles = new Set([
Expand Down

0 comments on commit 37c5daf

Please sign in to comment.