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

Commit c725d0c

Browse files
authored
refactor raw summary tags (#240)
1 parent 285cb56 commit c725d0c

File tree

3 files changed

+64
-87
lines changed

3 files changed

+64
-87
lines changed

dist/index.js

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

src/commenter.ts

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ export const COMMENT_REPLY_TAG =
1818
export const SUMMARIZE_TAG =
1919
'<!-- This is an auto-generated comment: summarize by openai -->'
2020

21-
export const EXTRA_CONTENT_TAG = '<!-- Extra content -->'
22-
23-
export const DESCRIPTION_TAG =
21+
export const DESCRIPTION_START_TAG =
2422
'<!-- This is an auto-generated comment: release notes by openai -->'
25-
export const DESCRIPTION_TAG_END =
23+
export const DESCRIPTION_END_TAG =
2624
'<!-- end of auto-generated comment: release notes by openai -->'
2725

28-
export const RAW_SUMMARY_TAG =
29-
'<!-- This is an auto-generated comment: raw summary by openai -->'
30-
export const RAW_SUMMARY_TAG_END =
31-
'<!-- end of auto-generated comment: raw summary by openai -->'
26+
export const RAW_SUMMARY_START_TAG = `<!-- This is an auto-generated comment: raw summary by openai -->
27+
<!--
28+
`
29+
export const RAW_SUMMARY_END_TAG = `-->
30+
<!-- end of auto-generated comment: raw summary by openai -->`
3231

33-
export const COMMIT_ID_TAG = '<!-- commit_ids_reviewed_start -->'
34-
export const COMMIT_ID_TAG_END = '<!-- commit_ids_reviewed_end -->'
32+
export const COMMIT_ID_START_TAG = '<!-- commit_ids_reviewed_start -->'
33+
export const COMMIT_ID_END_TAG = '<!-- commit_ids_reviewed_end -->'
3534

3635
export class Commenter {
3736
/**
@@ -89,34 +88,26 @@ ${tag}`
8988
}
9089

9190
getRawSummary(summary: string) {
92-
const content = this.getContentWithinTags(
91+
return this.getContentWithinTags(
9392
summary,
94-
RAW_SUMMARY_TAG,
95-
RAW_SUMMARY_TAG_END
93+
RAW_SUMMARY_START_TAG,
94+
RAW_SUMMARY_END_TAG
9695
)
97-
// remove the first and last line
98-
const lines = content.split('\n')
99-
if (lines.length < 3) {
100-
return ''
101-
}
102-
lines.shift()
103-
lines.pop()
104-
return lines.join('\n')
10596
}
10697

10798
getDescription(description: string) {
10899
return this.removeContentWithinTags(
109100
description,
110-
DESCRIPTION_TAG,
111-
DESCRIPTION_TAG_END
101+
DESCRIPTION_START_TAG,
102+
DESCRIPTION_END_TAG
112103
)
113104
}
114105

115106
getReleaseNotes(description: string) {
116107
const releaseNotes = this.getContentWithinTags(
117108
description,
118-
DESCRIPTION_TAG,
119-
DESCRIPTION_TAG_END
109+
DESCRIPTION_START_TAG,
110+
DESCRIPTION_END_TAG
120111
)
121112
return releaseNotes.replace(/(^|\n)> .*/g, '')
122113
}
@@ -140,10 +131,10 @@ ${tag}`
140131

141132
const messageClean = this.removeContentWithinTags(
142133
message,
143-
DESCRIPTION_TAG,
144-
DESCRIPTION_TAG_END
134+
DESCRIPTION_START_TAG,
135+
DESCRIPTION_END_TAG
145136
)
146-
const newDescription = `${description}\n${DESCRIPTION_TAG}\n${messageClean}\n${DESCRIPTION_TAG_END}`
137+
const newDescription = `${description}\n${DESCRIPTION_START_TAG}\n${messageClean}\n${DESCRIPTION_END_TAG}`
147138
await octokit.pulls.update({
148139
owner: repo.owner,
149140
repo: repo.repo,
@@ -562,12 +553,12 @@ ${chain}
562553
// commit ids are comments between the commit_ids_reviewed_start and commit_ids_reviewed_end markers
563554
// <!-- [commit_id] -->
564555
getReviewedCommitIds(commentBody: string): string[] {
565-
const start = commentBody.indexOf(COMMIT_ID_TAG)
566-
const end = commentBody.indexOf(COMMIT_ID_TAG_END)
556+
const start = commentBody.indexOf(COMMIT_ID_START_TAG)
557+
const end = commentBody.indexOf(COMMIT_ID_END_TAG)
567558
if (start === -1 || end === -1) {
568559
return []
569560
}
570-
const ids = commentBody.substring(start + COMMIT_ID_TAG.length, end)
561+
const ids = commentBody.substring(start + COMMIT_ID_START_TAG.length, end)
571562
// remove the <!-- and --> markers from each id and extract the id and remove empty strings
572563
return ids
573564
.split('<!--')
@@ -578,26 +569,26 @@ ${chain}
578569
// get review commit ids comment block from the body as a string
579570
// including markers
580571
getReviewedCommitIdsBlock(commentBody: string): string {
581-
const start = commentBody.indexOf(COMMIT_ID_TAG)
582-
const end = commentBody.indexOf(COMMIT_ID_TAG_END)
572+
const start = commentBody.indexOf(COMMIT_ID_START_TAG)
573+
const end = commentBody.indexOf(COMMIT_ID_END_TAG)
583574
if (start === -1 || end === -1) {
584575
return ''
585576
}
586-
return commentBody.substring(start, end + COMMIT_ID_TAG_END.length)
577+
return commentBody.substring(start, end + COMMIT_ID_END_TAG.length)
587578
}
588579

589580
// add a commit id to the list of reviewed commit ids
590581
// if the marker doesn't exist, add it
591582
addReviewedCommitId(commentBody: string, commitId: string): string {
592-
const start = commentBody.indexOf(COMMIT_ID_TAG)
593-
const end = commentBody.indexOf(COMMIT_ID_TAG_END)
583+
const start = commentBody.indexOf(COMMIT_ID_START_TAG)
584+
const end = commentBody.indexOf(COMMIT_ID_END_TAG)
594585
if (start === -1 || end === -1) {
595-
return `${commentBody}\n${COMMIT_ID_TAG}\n<!-- ${commitId} -->\n${COMMIT_ID_TAG_END}`
586+
return `${commentBody}\n${COMMIT_ID_START_TAG}\n<!-- ${commitId} -->\n${COMMIT_ID_END_TAG}`
596587
}
597-
const ids = commentBody.substring(start + COMMIT_ID_TAG.length, end)
588+
const ids = commentBody.substring(start + COMMIT_ID_START_TAG.length, end)
598589
return `${commentBody.substring(
599590
0,
600-
start + COMMIT_ID_TAG.length
591+
start + COMMIT_ID_START_TAG.length
601592
)}${ids}<!-- ${commitId} -->\n${commentBody.substring(end)}`
602593
}
603594

src/review.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import {type Bot} from './bot'
66
import {
77
Commenter,
88
COMMENT_REPLY_TAG,
9-
EXTRA_CONTENT_TAG,
10-
RAW_SUMMARY_TAG,
11-
RAW_SUMMARY_TAG_END,
9+
RAW_SUMMARY_END_TAG,
10+
RAW_SUMMARY_START_TAG,
1211
SUMMARIZE_TAG
1312
} from './commenter'
1413
import {Inputs} from './inputs'
@@ -402,12 +401,9 @@ ${filename}: ${summary}
402401
}
403402

404403
let summarizeComment = `${summarizeFinalResponse}
405-
${RAW_SUMMARY_TAG}
406-
<!--
404+
${RAW_SUMMARY_START_TAG}
407405
${inputs.rawSummary}
408-
-->
409-
${RAW_SUMMARY_TAG_END}
410-
${EXTRA_CONTENT_TAG}
406+
${RAW_SUMMARY_END_TAG}
411407
---
412408
413409
### Chat with 🤖 OpenAI Bot (\`@openai\`)

0 commit comments

Comments
 (0)