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

Commit 1b9c743

Browse files
authored
review existing code as well (#70)
<!-- This is an auto-generated comment: release notes by openai --> ### Summary by OpenAI **Release Notes** This pull request includes several changes to the codebase, including adding "typos" to the list of issues that can be uncovered, updating `max_tokens_for_extra_content` values for certain models, and adding a comment to the pull request if the review response does not include "LGTM". Additionally, the `comment` method in `src/commenter.ts` now accepts a `tag` and `mode` parameter, and the `post_comment` method has been removed. These changes aim to improve code quality and streamline the review process. <!-- end of auto-generated comment: release notes by openai -->
1 parent 31c2116 commit 1b9c743

File tree

5 files changed

+100
-88
lines changed

5 files changed

+100
-88
lines changed

action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ inputs:
7474
ability to review code changes thoroughly.You can uncover issues such as
7575
logic errors, syntax errors, out of bound errors, potential data races,
7676
livelocks, starvation, suspension, order violation, atomicity violation,
77-
consistency, complexity, error handling, and more.
77+
consistency, complexity, error handling, typos, and more.
7878
7979
You will be conducting code reviews today and write code if asked to do so.
8080
summarize_beginning:
@@ -168,7 +168,9 @@ inputs:
168168
$file_content
169169
```
170170
171-
Reply "OK" to confirm.
171+
Reply "LGTM!" if the existing code in this file looks correct. If there
172+
are serious issues in the existing code please let me know and I will
173+
add your comment on the pull request for this file.
172174
review_file_diff:
173175
required: false
174176
description: 'The prompt for each file diff'

dist/index.js

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

src/commenter.ts

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,40 @@ export class Commenter {
3030
* @param mode Can be "create", "replace", "append" and "prepend". Default is "replace".
3131
*/
3232
async comment(message: string, tag: string, mode: string) {
33-
await this.post_comment(message, tag, mode)
33+
let target: number
34+
if (context.payload.pull_request) {
35+
target = context.payload.pull_request.number
36+
} else if (context.payload.issue) {
37+
target = context.payload.issue.number
38+
} else {
39+
core.warning(
40+
`Skipped: context.payload.pull_request and context.payload.issue are both null`
41+
)
42+
return
43+
}
44+
45+
if (!tag) {
46+
tag = COMMENT_TAG
47+
}
48+
49+
const body = `${COMMENT_GREETING}
50+
51+
${message}
52+
53+
${tag}`
54+
55+
if (mode === 'create') {
56+
await this.create(body, target)
57+
} else if (mode === 'replace') {
58+
await this.replace(body, tag, target)
59+
} else if (mode === 'append') {
60+
await this.append(body, tag, target)
61+
} else if (mode === 'prepend') {
62+
await this.prepend(body, tag, target)
63+
} else {
64+
core.warning(`Unknown mode: ${mode}, use "replace" instead`)
65+
await this.replace(body, tag, target)
66+
}
3467
}
3568

3669
get_description(description: string) {
@@ -100,19 +133,20 @@ export class Commenter {
100133
commit_id: string,
101134
path: string,
102135
line: number,
103-
message: string
136+
message: string,
137+
tag: string = COMMENT_TAG
104138
) {
105139
message = `${COMMENT_GREETING}
106140
107141
${message}
108142
109-
${COMMENT_TAG}`
143+
${tag}`
110144
// replace comment made by this action
111145
try {
112146
let found = false
113147
const comments = await this.get_comments_at_line(pull_number, path, line)
114148
for (const comment of comments) {
115-
if (comment.body.includes(COMMENT_TAG)) {
149+
if (comment.body.includes(tag)) {
116150
await octokit.pulls.updateReviewComment({
117151
owner: repo.owner,
118152
repo: repo.repo,
@@ -319,43 +353,6 @@ ${chain}
319353
}
320354
}
321355

322-
async post_comment(message: string, tag: string, mode: string) {
323-
let target: number
324-
if (context.payload.pull_request) {
325-
target = context.payload.pull_request.number
326-
} else if (context.payload.issue) {
327-
target = context.payload.issue.number
328-
} else {
329-
core.warning(
330-
`Skipped: context.payload.pull_request and context.payload.issue are both null`
331-
)
332-
return
333-
}
334-
335-
if (!tag) {
336-
tag = COMMENT_TAG
337-
}
338-
339-
const body = `${COMMENT_GREETING}
340-
341-
${message}
342-
343-
${tag}`
344-
345-
if (mode === 'create') {
346-
await this.create(body, target)
347-
} else if (mode === 'replace') {
348-
await this.replace(body, tag, target)
349-
} else if (mode === 'append') {
350-
await this.append(body, tag, target)
351-
} else if (mode === 'prepend') {
352-
await this.prepend(body, tag, target)
353-
} else {
354-
core.warning(`Unknown mode: ${mode}, use "replace" instead`)
355-
await this.replace(body, tag, target)
356-
}
357-
}
358-
359356
async create(body: string, target: number) {
360357
try {
361358
await octokit.issues.createComment({

src/options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ export class Options {
228228
this.openai_concurrency_limit = parseInt(openai_concurrency_limit)
229229

230230
if (this.openai_model === 'gpt-4') {
231-
this.max_tokens_for_extra_content = 5000
231+
this.max_tokens_for_extra_content = 4000
232232
} else if (this.openai_model === 'gpt-3.5-turbo') {
233-
this.max_tokens_for_extra_content = 2500
233+
this.max_tokens_for_extra_content = 2000
234234
} else {
235235
this.max_tokens_for_extra_content = 1000
236236
}

src/review.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ Tips:
280280
core.info('review: nothing obtained from openai')
281281
} else {
282282
next_review_ids = review_file_ids
283+
if (!resp.includes('LGTM')) {
284+
// TODO: add file level comments via API once it's available
285+
// See: https://github.blog/changelog/2023-03-14-comment-on-files-in-a-pull-request-public-beta/
286+
// For now comment on the PR itself
287+
const tag = `<!-- openai-review-file-${filename} -->`
288+
const comment = `${tag}\nReviewing existing code in: ${filename}\n\n${resp}`
289+
await commenter.comment(comment, tag, 'replace')
290+
}
283291
}
284292
} catch (error) {
285293
core.warning(`review: error from openai: ${error}`)

0 commit comments

Comments
 (0)