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

Commit bd9fc77

Browse files
committed
reuse description from github context
1 parent 3718380 commit bd9fc77

File tree

2 files changed

+78
-87
lines changed

2 files changed

+78
-87
lines changed

dist/index.js

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

src/review.ts

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export const codeReview = async (
3636
inputs.title = context.payload.pull_request.title
3737
if (context.payload.pull_request.body) {
3838
inputs.description = context.payload.pull_request.body
39-
} else {
40-
inputs.description = context.payload.pull_request.title
4139
}
4240

4341
// collect diff chunks
@@ -231,47 +229,47 @@ export const codeReview = async (
231229
'<!-- This is an auto-generated comment: release notes by chatgpt -->'
232230
const tag_end =
233231
'<!-- end of auto-generated comment: release notes by chatgpt -->'
234-
// get the description of the PR
235-
const {data: pr} = await octokit.pulls.get({
236-
owner: repo.owner,
237-
repo: repo.repo,
238-
pull_number: context.payload.pull_request.number
239-
})
240-
let description = ''
241-
if (pr.body) {
242-
description = pr.body
243-
}
244-
// find the tag in the description and replace the content between the tag and the tag_end
245-
// if not found, add the tag and the content to the end of the description
246-
const tag_index = description.indexOf(tag)
247-
const tag_end_index = description.indexOf(tag_end)
248-
if (tag_index === -1 || tag_end_index === -1) {
249-
let new_description = description
250-
new_description += tag
251-
new_description += '\n### Summary by ChatGPT\n'
252-
new_description += release_notes_response
253-
new_description += '\n'
254-
new_description += tag_end
255-
await octokit.pulls.update({
256-
owner: repo.owner,
257-
repo: repo.repo,
258-
pull_number: context.payload.pull_request.number,
259-
body: new_description
260-
})
261-
} else {
262-
let new_description = description.substring(0, tag_index)
263-
new_description += tag
264-
new_description += '\n### Summary by ChatGPT\n'
265-
new_description += release_notes_response
266-
new_description += '\n'
267-
new_description += tag_end
268-
new_description += description.substring(tag_end_index + tag_end.length)
269-
await octokit.pulls.update({
270-
owner: repo.owner,
271-
repo: repo.repo,
272-
pull_number: context.payload.pull_request.number,
273-
body: new_description
274-
})
232+
try {
233+
const description = inputs.description
234+
235+
// find the tag in the description and replace the content between the tag and the tag_end
236+
// if not found, add the tag and the content to the end of the description
237+
const tag_index = description.indexOf(tag)
238+
const tag_end_index = description.indexOf(tag_end)
239+
if (tag_index === -1 || tag_end_index === -1) {
240+
let new_description = description
241+
new_description += tag
242+
new_description += '\n### Summary by ChatGPT\n'
243+
new_description += release_notes_response
244+
new_description += '\n'
245+
new_description += tag_end
246+
await octokit.pulls.update({
247+
owner: repo.owner,
248+
repo: repo.repo,
249+
pull_number: context.payload.pull_request.number,
250+
body: new_description
251+
})
252+
} else {
253+
let new_description = description.substring(0, tag_index)
254+
new_description += tag
255+
new_description += '\n### Summary by ChatGPT\n'
256+
new_description += release_notes_response
257+
new_description += '\n'
258+
new_description += tag_end
259+
new_description += description.substring(
260+
tag_end_index + tag_end.length
261+
)
262+
await octokit.pulls.update({
263+
owner: repo.owner,
264+
repo: repo.repo,
265+
pull_number: context.payload.pull_request.number,
266+
body: new_description
267+
})
268+
}
269+
} catch (e: any) {
270+
core.warning(
271+
`Failed to get PR: ${e}, skipping adding release notes to description.`
272+
)
275273
}
276274
}
277275
}

0 commit comments

Comments
 (0)