Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 25494e6

Browse files
authored
skip review of lower complexity changes (#212)
1 parent f63fbce commit 25494e6

File tree

3 files changed

+122
-8
lines changed

3 files changed

+122
-8
lines changed

dist/index.js

Lines changed: 49 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ export class Prompts {
2727
}
2828

2929
render_summarize_file_diff(inputs: Inputs): string {
30-
return inputs.render(this.summarize_file_diff)
30+
const prompt = `${this.summarize_file_diff}
31+
32+
Below the summary, I would also like you to classify the
33+
complexity of the diff as \`COMPLEX\` or \`SIMPLE\` based
34+
on whether the diff is a simple change that looks good as it
35+
is or a complex change that needs thorough review.
36+
37+
Use the following format to classify the complexity of the
38+
diff and add no additional text:
39+
[COMPLEXITY]: <COMPLEX or SIMPLE>
40+
`
41+
42+
return inputs.render(prompt)
3143
}
3244

3345
render_summarize(inputs: Inputs): string {

src/review.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ ${hunks.old_hunk}
217217
filename: string,
218218
file_content: string,
219219
file_diff: string
220-
): Promise<[string, string] | null> => {
220+
): Promise<[string, string, boolean] | null> => {
221221
const ins = inputs.clone()
222222
if (file_diff.length === 0) {
223223
core.warning(`summarize: file_diff is empty, skip ${filename}`)
@@ -226,6 +226,7 @@ ${hunks.old_hunk}
226226
}
227227

228228
ins.filename = filename
229+
229230
// render prompt based on inputs so far
230231
let tokens = tokenizer.get_token_count(
231232
prompts.render_summarize_file_diff(ins)
@@ -268,7 +269,24 @@ ${hunks.old_hunk}
268269
summaries_failed.push(`${filename} (nothing obtained from openai)`)
269270
return null
270271
} else {
271-
return [filename, summarize_resp]
272+
// parse the comment to look for complexity classification
273+
// Format is : [COMPLEXITY]: <COMPLEX or SIMPLE>
274+
// if the change is complex return true, else false
275+
const complexityRegex = /\[COMPLEXITY\]:\s*(COMPLEX|SIMPLE)/
276+
const complexityMatch = summarize_resp.match(complexityRegex)
277+
278+
if (complexityMatch) {
279+
const complexity = complexityMatch[1]
280+
const is_complex = complexity === 'COMPLEX' ? true : false
281+
282+
// remove this line from the comment
283+
const summary = summarize_resp.replace(complexityRegex, '').trim()
284+
core.info(`filename: ${filename}, complexity: ${complexity}`)
285+
return [filename, summary, is_complex]
286+
} else {
287+
// Handle the case when the [COMPLEXITY] tag is not found
288+
return [filename, summarize_resp, true]
289+
}
272290
}
273291
} catch (error) {
274292
core.warning(`summarize: error from openai: ${error}`)
@@ -293,7 +311,7 @@ ${hunks.old_hunk}
293311

294312
const summaries = (await Promise.all(summaryPromises)).filter(
295313
summary => summary !== null
296-
) as [string, string][]
314+
) as [string, string, boolean][]
297315

298316
if (summaries.length > 0) {
299317
// join summaries into one in the batches of 20
@@ -420,6 +438,23 @@ ${
420438
`
421439

422440
if (options.summary_only !== true) {
441+
const files_and_changes_review = files_and_changes.filter(([filename]) => {
442+
const is_complex =
443+
summaries.find(
444+
([summaryFilename]) => summaryFilename === filename
445+
)?.[2] ?? true
446+
return is_complex
447+
})
448+
449+
const reviews_skipped = files_and_changes
450+
.filter(
451+
([filename]) =>
452+
!files_and_changes_review.some(
453+
([reviewFilename]) => reviewFilename === filename
454+
)
455+
)
456+
.map(([filename]) => filename)
457+
423458
// failed reviews array
424459
const reviews_failed: string[] = []
425460
const do_review = async (
@@ -684,7 +719,12 @@ ${comment_chain}
684719
}
685720

686721
const reviewPromises = []
687-
for (const [filename, file_content, , patches] of files_and_changes) {
722+
for (const [
723+
filename,
724+
file_content,
725+
,
726+
patches
727+
] of files_and_changes_review) {
688728
if (options.max_files <= 0 || reviewPromises.length < options.max_files) {
689729
reviewPromises.push(
690730
openai_concurrency_limit(async () =>
@@ -710,6 +750,22 @@ ${
710750
711751
* ${reviews_failed.join('\n* ')}
712752
753+
</details>
754+
`
755+
: ''
756+
}
757+
758+
${
759+
reviews_skipped.length > 0
760+
? `<details>
761+
<summary>Files not reviewed due to simple changes (${
762+
reviews_skipped.length
763+
})</summary>
764+
765+
### Skipped review
766+
767+
* ${reviews_skipped.join('\n* ')}
768+
713769
</details>
714770
`
715771
: ''

0 commit comments

Comments
 (0)