@@ -12,10 +12,6 @@ const token = core.getInput('token')
12
12
const octokit = new Octokit ( { auth : `token ${ token } ` } )
13
13
const context = github . context
14
14
const repo = context . repo
15
- const description_tag =
16
- '<!-- This is an auto-generated comment: release notes by chatgpt -->'
17
- const description_tag_end =
18
- '<!-- end of auto-generated comment: release notes by chatgpt -->'
19
15
20
16
const MAX_TOKENS_FOR_EXTRA_CONTENT = 2500
21
17
@@ -39,18 +35,14 @@ export const codeReview = async (
39
35
return
40
36
}
41
37
38
+ const commenter : Commenter = new Commenter ( )
39
+
42
40
const inputs : Inputs = new Inputs ( )
43
41
inputs . title = context . payload . pull_request . title
44
42
if ( context . payload . pull_request . body ) {
45
- inputs . description = context . payload . pull_request . body
46
- // remove our summary from description by looking for description_tag and description_tag_end
47
- const start = inputs . description . indexOf ( description_tag )
48
- const end = inputs . description . indexOf ( description_tag_end )
49
- if ( start >= 0 && end >= 0 ) {
50
- inputs . description =
51
- inputs . description . slice ( 0 , start ) +
52
- inputs . description . slice ( end + description_tag_end . length )
53
- }
43
+ inputs . description = commenter . get_description (
44
+ context . payload . pull_request . body
45
+ )
54
46
}
55
47
// as gpt-3.5-turbo isn't paying attention to system message, add to inputs for now
56
48
inputs . system_message = options . system_message
@@ -115,8 +107,6 @@ export const codeReview = async (
115
107
}
116
108
117
109
if ( files_to_review . length > 0 ) {
118
- const commenter : Commenter = new Commenter ( )
119
-
120
110
// Summary Stage
121
111
const [ , summarize_begin_ids ] = await bot . chat (
122
112
prompts . render_summarize_beginning ( inputs ) ,
@@ -128,15 +118,18 @@ export const codeReview = async (
128
118
inputs . file_content = file_content
129
119
inputs . file_diff = file_diff
130
120
if ( file_diff . length > 0 ) {
131
- // summarize diff
132
- const [ summarize_resp , summarize_diff_ids ] = await bot . chat (
133
- prompts . render_summarize_file_diff ( inputs ) ,
134
- next_summarize_ids
135
- )
136
- if ( ! summarize_resp ) {
137
- core . info ( 'summarize: nothing obtained from chatgpt' )
138
- } else {
139
- next_summarize_ids = summarize_diff_ids
121
+ const file_diff_tokens = tokenizer . get_token_count ( file_diff )
122
+ if ( file_diff_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT ) {
123
+ // summarize diff
124
+ const [ summarize_resp , summarize_diff_ids ] = await bot . chat (
125
+ prompts . render_summarize_file_diff ( inputs ) ,
126
+ next_summarize_ids
127
+ )
128
+ if ( ! summarize_resp ) {
129
+ core . info ( 'summarize: nothing obtained from chatgpt' )
130
+ } else {
131
+ next_summarize_ids = summarize_diff_ids
132
+ }
140
133
}
141
134
}
142
135
}
@@ -163,50 +156,14 @@ export const codeReview = async (
163
156
core . info ( 'release notes: nothing obtained from chatgpt' )
164
157
} else {
165
158
next_summarize_ids = release_notes_ids
166
- // add this response to the description field of the PR as release notes by looking
167
- // for the tag (marker)
168
- try {
169
- const description = inputs . description
170
-
171
- // find the tag in the description and replace the content between the tag and the tag_end
172
- // if not found, add the tag and the content to the end of the description
173
- const tag_index = description . indexOf ( description_tag )
174
- const tag_end_index = description . indexOf ( description_tag_end )
175
- if ( tag_index === - 1 || tag_end_index === - 1 ) {
176
- let new_description = description
177
- new_description += description_tag
178
- new_description += '\n### Summary by ChatGPT\n'
179
- new_description += release_notes_response
180
- new_description += '\n'
181
- new_description += description_tag_end
182
- await octokit . pulls . update ( {
183
- owner : repo . owner ,
184
- repo : repo . repo ,
185
- pull_number : context . payload . pull_request . number ,
186
- body : new_description
187
- } )
188
- } else {
189
- let new_description = description . substring ( 0 , tag_index )
190
- new_description += description_tag
191
- new_description += '\n### Summary by ChatGPT\n'
192
- new_description += release_notes_response
193
- new_description += '\n'
194
- new_description += description_tag_end
195
- new_description += description . substring (
196
- tag_end_index + description_tag_end . length
197
- )
198
- await octokit . pulls . update ( {
199
- owner : repo . owner ,
200
- repo : repo . repo ,
201
- pull_number : context . payload . pull_request . number ,
202
- body : new_description
203
- } )
204
- }
205
- } catch ( e : any ) {
206
- core . warning (
207
- `Failed to get PR: ${ e } , skipping adding release notes to description.`
208
- )
209
- }
159
+ const description = inputs . description
160
+ let message = '### Summary by ChatGPT\n\n'
161
+ message += release_notes_response
162
+ commenter . update_description (
163
+ context . payload . pull_request . number ,
164
+ description ,
165
+ message
166
+ )
210
167
}
211
168
212
169
// Review Stage
0 commit comments