-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Octokit } from "@octokit/rest" | ||
import { ChatCompletionRequestMessage } from "openai-streams" | ||
import { generateChatGpt } from "../utils/generateChatGpt" | ||
import { getCodeDiff } from "../utils/getCodeDiff" | ||
|
||
export const startDescription = "\n\n<!-- start pr-codex -->" | ||
export const endDescription = "<!-- end pr-codex -->" | ||
const systemPrompt = | ||
"You are a Git diff assistant. Given a code diff, you answer any question related to it. Be concise. Always wrap file names, functions, objects and similar in backticks (`)." | ||
|
||
export async function replyIssueComment(payload: any, octokit: Octokit) { | ||
// Get relevant PR information | ||
const { repository, issue, sender, comment } = payload | ||
|
||
const question = comment.body.split("/codex-ask")[1].trim() | ||
|
||
if (question) { | ||
const { owner, repo, issue_number } = { | ||
owner: repository.owner.login, | ||
repo: repository.name, | ||
issue_number: issue.number | ||
} | ||
|
||
// Get the diff content using Octokit and GitHub API | ||
const { codeDiff } = await getCodeDiff(owner, repo, issue_number, octokit) | ||
|
||
// If there are changes, trigger workflow | ||
if (codeDiff?.length != 0) { | ||
const messages: ChatCompletionRequestMessage[] = [ | ||
{ | ||
role: "system", | ||
content: systemPrompt | ||
}, | ||
{ | ||
role: "user", | ||
content: `${question}\n\nHere is the code diff:\n\n${codeDiff}` | ||
} | ||
] | ||
|
||
const codexResponse = await generateChatGpt(messages) | ||
|
||
const description = `> ${question}\n\n@${sender.login} ${codexResponse}` | ||
|
||
await octokit.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number, | ||
body: description | ||
}) | ||
|
||
return codexResponse | ||
} | ||
throw new Error("No changes in PR") | ||
} | ||
} |