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

Commit 680cdba

Browse files
authored
hard code the format instructions (#150)
1 parent bce4deb commit 680cdba

File tree

3 files changed

+140
-63
lines changed

3 files changed

+140
-63
lines changed

action.yml

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ inputs:
172172
required: false
173173
description: 'The prompt for each file'
174174
default: |
175-
You will review a code change.
175+
You will review a pull request.
176176
177177
GitHub pull request title -
178178
`$title`
@@ -192,70 +192,9 @@ inputs:
192192
$file_content
193193
```
194194
195-
Format for changes and review comments (if any) -
196-
```new_hunk_for_review
197-
<new code with line numbers>
198-
```
199-
```old_hunk_for_context
200-
<old code>
201-
```
202-
```comment_chains_for_context
203-
<comment chains>
204-
```
205-
---
206-
...
207-
208-
Changes for review -
195+
Here are changes for review -
209196
$patches
210197
211-
Response format -
212-
<start_line_number>-<end_line_number>:
213-
<review>
214-
```suggestion
215-
<code that replaces everything between start_line_number and end_line_number>
216-
```
217-
---
218-
<start_line_number>-<end_line_number>:
219-
<review>
220-
---
221-
<start_line_number>-<end_line_number>:
222-
<review>
223-
```<language>
224-
<new code suggestion>
225-
```
226-
...
227-
228-
Example response -
229-
1-5:
230-
LGTM!
231-
---
232-
6-6:
233-
```suggestion
234-
print("Hello!")
235-
```
236-
```go
237-
log.Info().Msgf("Example")
238-
```
239-
---
240-
241-
Instructions -
242-
- Your response must be in the above format. Each review section must
243-
consist of a line number range and a comment for that line number
244-
range. There's a separator between review sections. Any text not in
245-
this format will be ignored as it will not be read by the parser.
246-
- It's important that line number ranges for each review section must
247-
be within the line number range of a specific new hunk. i.e.
248-
<start_line_number> must be part of the same hunk as the
249-
<end_line_number>, otherwise comment can't be posted.
250-
- Don't repeat the code, the line number range is enough to connect your
251-
comment to the code in GitHub.
252-
- Markdown format is preferred for text.
253-
- Fenced code blocks must be used for new code and replacement
254-
code suggestions. Code replacement suggestions must be complete,
255-
correctly formatted and most importantly, map exactly to the line
256-
number ranges that need to be replaced inside the hunks.
257-
- If there are no issues or suggestions and the hunk is acceptable as-is,
258-
your comment on the line ranges must include the word 'LGTM!'.
259198
comment:
260199
required: false
261200
description: 'Prompt for comment'

dist/index.js

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

src/review.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,76 @@ ${
365365
// make a copy of inputs
366366
const ins: Inputs = inputs.clone()
367367
ins.filename = filename
368+
369+
// Pack instructions
370+
ins.patches += `
371+
Format for changes and review comments (if any) -
372+
\`\`\`new_hunk_for_review
373+
<new content with line numbers>
374+
\`\`\`
375+
\`\`\`old_hunk_for_context
376+
<old content>
377+
\`\`\`
378+
\`\`\`comment_chains_for_context
379+
<comment chains>
380+
\`\`\`
381+
---
382+
...
383+
384+
Response format expected -
385+
<start_line_number>-<end_line_number>:
386+
<review>
387+
\`\`\`suggestion
388+
<content that replaces everything between start_line_number and end_line_number>
389+
\`\`\`
390+
---
391+
<start_line_number>-<end_line_number>:
392+
<review>
393+
---
394+
<start_line_number>-<end_line_number>:
395+
<review>
396+
\`\`\`<language>
397+
<new content suggestion>
398+
\`\`\`
399+
...
400+
401+
Example response -
402+
1-5:
403+
LGTM!
404+
---
405+
6-6:
406+
\`\`\`suggestion
407+
print("Hello!")
408+
\`\`\`
409+
\`\`\`go
410+
log.Info().Msgf("Example")
411+
\`\`\`
412+
---
413+
414+
Instructions -
415+
- Your response must be in the above format. Each review section must
416+
consist of a line number range and a comment for that line number
417+
range. There's a separator between review sections. Any text not in
418+
this format will be ignored as it will not be read by the parser.
419+
- It's important that line number ranges for each review section must
420+
be within the line number range of a specific new hunk. i.e.
421+
<start_line_number> must be part of the same hunk as the
422+
<end_line_number>, otherwise comment can't be posted.
423+
- Don't repeat the content, the line number range is enough to connect your
424+
comment to the sections in GitHub.
425+
- Markdown format is preferred for text.
426+
- Fenced code blocks must be used for new content and replacement
427+
content suggestions. Replacement suggestions must be complete,
428+
correctly formatted and most importantly, map exactly to the line
429+
number ranges that need to be replaced inside the hunks.
430+
fenced code blocks. Do not include line numbers inside the suggestion
431+
code blocks as they are already provided in the line number range.
432+
- If there are no issues or suggestions and the hunk is acceptable as-is,
433+
your comment on the line ranges must include the word 'LGTM!'.
434+
435+
Hunks for review -
436+
`
437+
368438
// calculate tokens based on inputs so far
369439
let tokens = tokenizer.get_token_count(prompts.render_review_file_diff(ins))
370440
// loop to calculate total patch tokens

0 commit comments

Comments
 (0)