Skip to content

Commit 7150a7b

Browse files
Improve handling of rm or mv files
1 parent ea961d2 commit 7150a7b

File tree

5 files changed

+59
-42
lines changed

5 files changed

+59
-42
lines changed

dist/github/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ const getDiff = async (prNumber, owner, repo) => {
110110
},
111111
});
112112
// We'll have to convert the diff to a string, then we can return it
113-
const diffString = diff.toString();
113+
let diffString = diff.toString();
114+
// We'll try adding a note here to see if it drives the point home to GPT
115+
diffString = `Diff for PR #${prNumber}:\n\n${diffString}`;
114116
console.log(`✅ Got diff for PR #${prNumber}`);
115117
return diffString;
116118
};
@@ -130,19 +132,20 @@ const getChangedFiles = (diff) => {
130132
exports.getChangedFiles = getChangedFiles;
131133
// We'll also need to get the whole file using the files changed from
132134
async function getFileContent(path, owner, repo) {
133-
let content = '';
134-
// loop over the array of files
135+
let content = 'Original files before the PR:\n\n';
135136
for (let i = 0; i < path.length; i++) {
136-
// get the file content
137-
const { data } = await exports.github.repos.getContent({
138-
owner,
139-
repo,
140-
path: path[i],
141-
});
142-
// decode the file content
143-
const decodedContent = Buffer.from(data.content, 'base64').toString();
144-
// add the decoded content to the content string
145-
content += decodedContent;
137+
try {
138+
const { data } = await exports.github.repos.getContent({
139+
owner,
140+
repo,
141+
path: path[i],
142+
});
143+
const decodedContent = Buffer.from(data.content, 'base64').toString();
144+
content += decodedContent;
145+
}
146+
catch (error) {
147+
console.error(`Skipping new file as it doesn't exist in the trunk yet`);
148+
}
146149
}
147150
console.log(`✅ Got file(s) contents`);
148151
return content;

dist/index.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ const getDiff = async (prNumber, owner, repo) => {
117117
},
118118
});
119119
// We'll have to convert the diff to a string, then we can return it
120-
const diffString = diff.toString();
120+
let diffString = diff.toString();
121+
// We'll try adding a note here to see if it drives the point home to GPT
122+
diffString = `Diff for PR #${prNumber}:\n\n${diffString}`;
121123
console.log(`✅ Got diff for PR #${prNumber}`);
122124
return diffString;
123125
};
@@ -137,19 +139,20 @@ const getChangedFiles = (diff) => {
137139
exports.getChangedFiles = getChangedFiles;
138140
// We'll also need to get the whole file using the files changed from
139141
async function getFileContent(path, owner, repo) {
140-
let content = '';
141-
// loop over the array of files
142+
let content = 'Original files before the PR:\n\n';
142143
for (let i = 0; i < path.length; i++) {
143-
// get the file content
144-
const { data } = await exports.github.repos.getContent({
145-
owner,
146-
repo,
147-
path: path[i],
148-
});
149-
// decode the file content
150-
const decodedContent = Buffer.from(data.content, 'base64').toString();
151-
// add the decoded content to the content string
152-
content += decodedContent;
144+
try {
145+
const { data } = await exports.github.repos.getContent({
146+
owner,
147+
repo,
148+
path: path[i],
149+
});
150+
const decodedContent = Buffer.from(data.content, 'base64').toString();
151+
content += decodedContent;
152+
}
153+
catch (error) {
154+
console.error(`Skipping new file as it doesn't exist in the trunk yet`);
155+
}
153156
}
154157
console.log(`✅ Got file(s) contents`);
155158
return content;
@@ -270,7 +273,7 @@ const openai = new openAi({
270273
});
271274
// This wil generate our prompt using the diff, assertion, and whole file
272275
const generatePrompt = (diff, assertion, file) => {
273-
const comboPrompt = `As a senior engineer, you're tasked with reviewing a documentation PR. Your review will be conducted through two distinct lenses, both centered around an assertion related to usability. The first lens will focus on examining the diff itself — providing targeted feedback on what the PR author actually contributed. The second lens will compare the diff to the entire set of changed files, assessing how the contribution fits within the larger context in relation to the usability assertion. For each lens, provide feedback and determine if the usability assertion is satisfied. You should speak directly to the author and refer to them in second person. Your output should be a JSON-formatted array with two objects and not be wrapped in backticks with the json declaration. Each object should contain the following properties: 'satisfied' (either a ✅ or ❌ to indicate if the assertion is met), 'scope' (either 'Diff' or 'Integrated'), and 'feedback' (a string providing your targeted feedback for that lens). Here's the assertion: ${assertion}\n\nHere's the diff:\n\n${diff}\n\nHere's the whole files:\n\n${file}\n\n`;
276+
const comboPrompt = `As a senior engineer, you're tasked with reviewing a documentation PR. Your review will be conducted through two distinct lenses, both centered around an assertion related to usability. The first lens will focus on examining the diff itself — providing targeted feedback on what the PR author actually contributed. The second lens will compare the diff to the entire set of changed files, assessing how the contribution fits within the larger context in relation to the usability assertion. For each lens, provide feedback and determine if the usability assertion is satisfied. You should speak directly to the author and refer to them in second person. Your output should be a JSON-formatted array with two objects. Each object should contain the following properties: 'satisfied' (either a ✅ or ❌ to indicate if the assertion is met), 'scope' (either 'Diff' or 'Integrated'), and 'feedback' (a string providing your targeted feedback for that lens). Here's the assertion: ${assertion}\n\nHere's the diff:\n\n${diff}\n\nHere's the original files:\n\n${file}\n\nBear in mind that some of the files may have been renamed. Remember, do not wrap the JSON in a code block.`;
274277
return comboPrompt;
275278
};
276279
exports.generatePrompt = generatePrompt;
@@ -312,6 +315,9 @@ const testAssertion = async (prompt) => {
312315
exports.testAssertion = testAssertion;
313316
// We decided to send things back as JSON so we can manipulate the data in the response we'll be sending back to GitHub
314317
const writeAnalysis = (analysis) => {
318+
// We've still got to double-check because ChatGPT will sometimes return a string that's not valid JSON by wrapping it in code blocks
319+
const regex = /^```(json)?/gm;
320+
analysis = analysis.replace(regex, '');
315321
const analysisJSON = JSON.parse(analysis);
316322
let message = `## DX: Assertion Testing\n\n`;
317323
const feedback = analysisJSON.map((item) => {

dist/open_ai/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const openai = new openAi({
3737
});
3838
// This wil generate our prompt using the diff, assertion, and whole file
3939
const generatePrompt = (diff, assertion, file) => {
40-
const comboPrompt = `As a senior engineer, you're tasked with reviewing a documentation PR. Your review will be conducted through two distinct lenses, both centered around an assertion related to usability. The first lens will focus on examining the diff itself — providing targeted feedback on what the PR author actually contributed. The second lens will compare the diff to the entire set of changed files, assessing how the contribution fits within the larger context in relation to the usability assertion. For each lens, provide feedback and determine if the usability assertion is satisfied. You should speak directly to the author and refer to them in second person. Your output should be a JSON-formatted array with two objects and not be wrapped in backticks with the json declaration. Each object should contain the following properties: 'satisfied' (either a ✅ or ❌ to indicate if the assertion is met), 'scope' (either 'Diff' or 'Integrated'), and 'feedback' (a string providing your targeted feedback for that lens). Here's the assertion: ${assertion}\n\nHere's the diff:\n\n${diff}\n\nHere's the whole files:\n\n${file}\n\n`;
40+
const comboPrompt = `As a senior engineer, you're tasked with reviewing a documentation PR. Your review will be conducted through two distinct lenses, both centered around an assertion related to usability. The first lens will focus on examining the diff itself — providing targeted feedback on what the PR author actually contributed. The second lens will compare the diff to the entire set of changed files, assessing how the contribution fits within the larger context in relation to the usability assertion. For each lens, provide feedback and determine if the usability assertion is satisfied. You should speak directly to the author and refer to them in second person. Your output should be a JSON-formatted array with two objects. Each object should contain the following properties: 'satisfied' (either a ✅ or ❌ to indicate if the assertion is met), 'scope' (either 'Diff' or 'Integrated'), and 'feedback' (a string providing your targeted feedback for that lens). Here's the assertion: ${assertion}\n\nHere's the diff:\n\n${diff}\n\nHere's the original files:\n\n${file}\n\nBear in mind that some of the files may have been renamed. Remember, do not wrap the JSON in a code block.`;
4141
return comboPrompt;
4242
};
4343
exports.generatePrompt = generatePrompt;
@@ -79,6 +79,9 @@ const testAssertion = async (prompt) => {
7979
exports.testAssertion = testAssertion;
8080
// We decided to send things back as JSON so we can manipulate the data in the response we'll be sending back to GitHub
8181
const writeAnalysis = (analysis) => {
82+
// We've still got to double-check because ChatGPT will sometimes return a string that's not valid JSON by wrapping it in code blocks
83+
const regex = /^```(json)?/gm;
84+
analysis = analysis.replace(regex, '');
8285
const analysisJSON = JSON.parse(analysis);
8386
let message = `## DX: Assertion Testing\n\n`;
8487
const feedback = analysisJSON.map((item) => {

src/github/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export const getDiff = async (prNumber: number, owner: string, repo: string): Pr
9393
});
9494

9595
// We'll have to convert the diff to a string, then we can return it
96-
const diffString = diff.toString();
96+
let diffString = diff.toString();
97+
// We'll try adding a note here to see if it drives the point home to GPT
98+
diffString = `Diff for PR #${prNumber}:\n\n${diffString}`;
9799
console.log(`✅ Got diff for PR #${prNumber}`);
98100
return diffString;
99101
};
@@ -113,19 +115,19 @@ export const getChangedFiles = (diff: string): string[] => {
113115

114116
// We'll also need to get the whole file using the files changed from
115117
export async function getFileContent(path: string[], owner: string, repo: string) {
116-
let content: string = '';
117-
// loop over the array of files
118+
let content: string = 'Original files before the PR:\n\n';
118119
for (let i = 0; i < path.length; i++) {
119-
// get the file content
120-
const { data }: any = await github.repos.getContent({
121-
owner,
122-
repo,
123-
path: path[i],
124-
});
125-
// decode the file content
126-
const decodedContent = Buffer.from(data.content, 'base64').toString();
127-
// add the decoded content to the content string
128-
content += decodedContent;
120+
try {
121+
const { data }: any = await github.repos.getContent({
122+
owner,
123+
repo,
124+
path: path[i],
125+
});
126+
const decodedContent = Buffer.from(data.content, 'base64').toString();
127+
content += decodedContent;
128+
} catch (error) {
129+
console.error(`Skipping new file as it doesn't exist in the trunk yet`);
130+
}
129131
}
130132
console.log(`✅ Got file(s) contents`);
131133
return content;

src/open_ai/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const openai = new openAi({
1212

1313
// This wil generate our prompt using the diff, assertion, and whole file
1414
export const generatePrompt = (diff: string, assertion: string | null, file: string): string => {
15-
const comboPrompt = `As a senior engineer, you're tasked with reviewing a documentation PR. Your review will be conducted through two distinct lenses, both centered around an assertion related to usability. The first lens will focus on examining the diff itself — providing targeted feedback on what the PR author actually contributed. The second lens will compare the diff to the entire set of changed files, assessing how the contribution fits within the larger context in relation to the usability assertion. For each lens, provide feedback and determine if the usability assertion is satisfied. You should speak directly to the author and refer to them in second person. Your output should be a JSON-formatted array with two objects and not be wrapped in backticks with the json declaration. Each object should contain the following properties: 'satisfied' (either a ✅ or ❌ to indicate if the assertion is met), 'scope' (either 'Diff' or 'Integrated'), and 'feedback' (a string providing your targeted feedback for that lens). Here's the assertion: ${assertion}\n\nHere's the diff:\n\n${diff}\n\nHere's the whole files:\n\n${file}\n\n`;
15+
const comboPrompt = `As a senior engineer, you're tasked with reviewing a documentation PR. Your review will be conducted through two distinct lenses, both centered around an assertion related to usability. The first lens will focus on examining the diff itself — providing targeted feedback on what the PR author actually contributed. The second lens will compare the diff to the entire set of changed files, assessing how the contribution fits within the larger context in relation to the usability assertion. For each lens, provide feedback and determine if the usability assertion is satisfied. You should speak directly to the author and refer to them in second person. Your output should be a JSON-formatted array with two objects. Each object should contain the following properties: 'satisfied' (either a ✅ or ❌ to indicate if the assertion is met), 'scope' (either 'Diff' or 'Integrated'), and 'feedback' (a string providing your targeted feedback for that lens). Here's the assertion: ${assertion}\n\nHere's the diff:\n\n${diff}\n\nHere's the original files:\n\n${file}\n\nBear in mind that some of the files may have been renamed. Remember, do not wrap the JSON in a code block.`;
1616
return comboPrompt;
1717
};
1818

@@ -54,6 +54,9 @@ export const testAssertion = async (prompt: string): Promise<string | null> => {
5454

5555
// We decided to send things back as JSON so we can manipulate the data in the response we'll be sending back to GitHub
5656
export const writeAnalysis = (analysis: string): string => {
57+
// We've still got to double-check because ChatGPT will sometimes return a string that's not valid JSON by wrapping it in code blocks
58+
const regex = /^```(json)?/gm;
59+
analysis = analysis.replace(regex, '');
5760
const analysisJSON = JSON.parse(analysis);
5861
let message = `## DX: Assertion Testing\n\n`;
5962
const feedback = analysisJSON.map((item: any) => {

0 commit comments

Comments
 (0)