Skip to content

Commit 2aba41e

Browse files
authored
✨ tweak: tweak update openai.js
1 parent 90f5ecf commit 2aba41e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

source/utils/openai.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ async function initGit() {
1717

1818
// git status to see if there are any changes
1919
// if there's any changes add the first file in the list of changes
20+
let firstFilePath = '';
21+
2022
async function gitStatus() {
2123
try {
2224
const { stdout: status } = await execa('git', ['status', '--porcelain']);
@@ -31,8 +33,9 @@ async function gitStatus() {
3133
.map(line => line.split(' ').slice(1).join(' ').trim())
3234
);
3335
// git add the first file in the list of changes
34-
await execa('git', ['add', filePaths[0]]);
35-
console.log(`${filePaths[0]} has been added to the staging area.`);
36+
firstFilePath = filePaths[0];
37+
await execa('git', ['add', firstFilePath]);
38+
console.log(`${firstFilePath} has been added to the staging area.`);
3639
} else {
3740
console.log('No changes to commit.');
3841
return false;
@@ -55,11 +58,18 @@ async function gitDiff() {
5558
async function generatePrompt() {
5659
const apiKey = await getOpenAIKey();
5760
const openai = new OpenAI({apiKey: apiKey});
61+
const maxDiffSize = config.maxDiffSize;
62+
5863
// get the staged changes
5964
await initGit();
6065
await gitStatus();
6166
const gitDiffContent = await gitDiff();
6267

68+
if (gitDiffContent.length > maxDiffSize) {
69+
console.log('Diff content is too large. Skipping OpenAI request.');
70+
return `✨ tweak: update ${firstFilePath}`;
71+
}
72+
6373
// use the prompt from the config file emoji and send to openai
6474
const category = await openai.chat.completions.create({
6575
messages: [

0 commit comments

Comments
 (0)