Skip to content

Commit 37c5daf

Browse files
authored
feat: signoff (#6)
* feat: signoff * fix: formatting * bump: package version * fix: formatting
1 parent 1f41d16 commit 37c5daf

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code-review-gpt",
3-
"version": "0.0.14",
3+
"version": "0.0.15",
44
"description": "Your AI code reviewer",
55
"bin": {
66
"code-review-gpt": "./dist/index.js"

src/askAI.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OpenAIChat } from "langchain/llms/openai";
2-
import { completionPrompt } from "./constants";
2+
import { completionPrompt, signOff } from "./constants";
33
import { openAIApiKey } from "./args";
44

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

21-
const summary = await callModel(finalPrompt);
21+
const emojis = await callModel(finalPrompt);
22+
23+
const summary = `\n${emojis}${signOff}`;
2224
console.log(summary);
2325

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

47-
4849
await Promise.allSettled(feedbackPromises.map(collectAndLogFeedback));
4950
const summary = await createSummary(feedbacks);
5051

src/commentOnPR.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import { context, getOctokit } from "@actions/github";
22
import { getGitHubEnvVariables } from "./args";
33

4+
const getToken = () => {
5+
const { githubToken } = getGitHubEnvVariables();
6+
if (!githubToken) {
7+
throw new Error("GITHUB_TOKEN is not set");
8+
}
9+
return githubToken;
10+
};
11+
412
export const commentOnPR = async (comment: string) => {
513
try {
6-
const { githubToken } = getGitHubEnvVariables();
14+
const githubToken = getToken();
715
const { payload, issue } = context;
816

9-
if (!githubToken) {
10-
throw new Error("GITHUB_TOKEN is not set");
11-
}
12-
13-
1417
if (!payload.pull_request) {
1518
console.warn("Not a pull request. Skipping commenting on PR...");
1619
return;
1720
}
1821

1922
const octokit = getOctokit(githubToken);
23+
2024
const { owner, repo, number: pull_number } = issue;
2125

2226
await octokit.rest.issues.createComment({

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ You are a senior developer and have just reviewed a pull request. This was your
2525
Please summarise the review using 3 emojis.
2626
`;
2727

28+
export const signOff = `\n---\n#### Powered by [Code Review GPT](https://github.com/mattzcarey/code-review-gpt)`;
29+
2830
export const maxPromptLength = 30000; //max is 8k tokens which is about 40k characters
2931

3032
export const supportedFiles = new Set([

0 commit comments

Comments
 (0)