@@ -64,10 +64,10 @@ export const handleReviewComment = async (bot: Bot, prompts: Prompts) => {
64
64
! comment . body . includes ( COMMENT_REPLY_TAG )
65
65
) {
66
66
const pull_number = context . payload . pull_request . number
67
- const diff = comment . diff_hunk
68
67
69
68
inputs . comment = `${ comment . user . login } : ${ comment . body } `
70
- inputs . diff = diff
69
+ inputs . diff = comment . diff_hunk
70
+ inputs . filename = comment . path
71
71
72
72
const { chain : comment_chain , topLevelComment} =
73
73
await commenter . get_conversation_chain ( pull_number , comment )
@@ -79,8 +79,6 @@ export const handleReviewComment = async (bot: Bot, prompts: Prompts) => {
79
79
comment_chain . includes ( COMMENT_REPLY_TAG ) ||
80
80
comment . body . startsWith ( ASK_BOT )
81
81
) {
82
- let file_content = ''
83
- let file_diff = ''
84
82
try {
85
83
const contents = await octokit . repos . getContent ( {
86
84
owner : repo . owner ,
@@ -91,13 +89,17 @@ export const handleReviewComment = async (bot: Bot, prompts: Prompts) => {
91
89
if ( contents . data ) {
92
90
if ( ! Array . isArray ( contents . data ) ) {
93
91
if ( contents . data . type === 'file' && contents . data . content ) {
94
- file_content = Buffer . from (
92
+ inputs . file_content = Buffer . from (
95
93
contents . data . content ,
96
94
'base64'
97
95
) . toString ( )
98
96
}
99
97
}
100
98
}
99
+ } catch ( error ) {
100
+ core . warning ( `Failed to get file contents: ${ error } , skipping.` )
101
+ }
102
+ try {
101
103
// get diff for this file by comparing the base and head commits
102
104
const diffAll = await octokit . repos . compareCommits ( {
103
105
owner : repo . owner ,
@@ -110,12 +112,12 @@ export const handleReviewComment = async (bot: Bot, prompts: Prompts) => {
110
112
if ( files ) {
111
113
const file = files . find ( f => f . filename === comment . path )
112
114
if ( file && file . patch ) {
113
- file_diff = file . patch
115
+ inputs . file_diff = file . patch
114
116
}
115
117
}
116
118
}
117
119
} catch ( error ) {
118
- core . warning ( `Failed to get file contents : ${ error } , skipping.` )
120
+ core . warning ( `Failed to get file diff : ${ error } , skipping.` )
119
121
}
120
122
121
123
// get summary of the PR
@@ -127,18 +129,16 @@ export const handleReviewComment = async (bot: Bot, prompts: Prompts) => {
127
129
inputs . summary = summary . body
128
130
}
129
131
130
- inputs . filename = comment . path
131
- inputs . file_content = file_content
132
- inputs . file_diff = file_diff
133
-
134
132
// begin comment generation
135
133
const [ , comment_begin_ids ] = await bot . chat (
136
134
prompts . render_comment_beginning ( inputs ) ,
137
135
{ }
138
136
)
139
137
let next_comment_ids = comment_begin_ids
140
- if ( file_content . length > 0 ) {
141
- const file_content_tokens = tokenizer . get_token_count ( file_content )
138
+ if ( inputs . file_content . length > 0 ) {
139
+ const file_content_tokens = tokenizer . get_token_count (
140
+ inputs . file_content
141
+ )
142
142
if ( file_content_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT ) {
143
143
const [ file_content_resp , file_content_ids ] = await bot . chat (
144
144
prompts . render_comment_file ( inputs ) ,
@@ -150,8 +150,8 @@ export const handleReviewComment = async (bot: Bot, prompts: Prompts) => {
150
150
}
151
151
}
152
152
153
- if ( file_diff . length > 0 ) {
154
- const file_diff_tokens = tokenizer . get_token_count ( file_diff )
153
+ if ( inputs . file_diff . length > 0 ) {
154
+ const file_diff_tokens = tokenizer . get_token_count ( inputs . file_diff )
155
155
if ( file_diff_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT ) {
156
156
const [ file_diff_resp , file_diff_ids ] = await bot . chat (
157
157
prompts . render_comment_file_diff ( inputs ) ,
0 commit comments