Skip to content

Commit b9d51bd

Browse files
committed
fix: suppress handled PR review action offers
1 parent a222f09 commit b9d51bd

9 files changed

Lines changed: 761 additions & 63 deletions

File tree

apps/api/src/handlers/github/__tests__/index.test.ts

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/api/src/handlers/github/__tests__/notifyPrReviewActivity.test.ts

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/api/src/handlers/github/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ github.post('/', async (c) => {
216216

217217
webhooks.on('issue_comment.edited', async ({ id, name, payload }) => {
218218
if (payload.issue.pull_request) {
219-
// Roomote review summaries are posted as "review in progress" and
220-
// patched with the results, so the terminal content arrives here.
221-
await queuePrReviewSummaryNotification(payload);
219+
// Roomote summaries and external top-level review comments can both
220+
// be edited from placeholder content into their final result.
221+
await Promise.all([
222+
queuePrReviewActivityNotification(payload),
223+
queuePrReviewSummaryNotification(payload),
224+
]);
222225
}
223226

224227
return recordWebhook(

apps/api/src/handlers/github/notifyPrReviewActivity.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323

2424
type PrReviewActivityWebhookPayload =
2525
| WebhookIssueCommentCreated
26+
| WebhookIssueCommentEdited
2627
| WebhookPullRequestReviewSubmitted
2728
| WebhookPullRequestCommentCreated;
2829

@@ -31,6 +32,12 @@ type PrReviewSummaryWebhookPayload =
3132
| WebhookIssueCommentEdited;
3233

3334
const MAX_SUMMARY_LENGTH = 300;
35+
const MAX_REVIEW_BODY_LENGTH = 10_000;
36+
37+
function getReviewBody(value: string | null | undefined): string | undefined {
38+
const body = value?.trim();
39+
return body ? body.slice(0, MAX_REVIEW_BODY_LENGTH) : undefined;
40+
}
3441

3542
function getAutomatedAuthorMetadata(
3643
user: { id?: number; type?: string } | null | undefined,
@@ -72,6 +79,7 @@ export function buildPrReviewActivityNotificationInput(
7279

7380
const comment = eventPayload.comment;
7481
const authorLogin = comment.user?.login;
82+
const body = getReviewBody(comment.body);
7583

7684
if (
7785
!authorLogin ||
@@ -89,11 +97,12 @@ export function buildPrReviewActivityNotificationInput(
8997
sourceControlProvider: 'github',
9098
event: {
9199
kind: 'issue_comment',
92-
providerEventId: `github-issue-comment:${comment.id}`,
100+
providerEventId: `github-issue-comment:${comment.id}:${comment.updated_at ?? comment.created_at}`,
93101
authorLogin,
94102
...getAutomatedAuthorMetadata(comment.user),
103+
...(body ? { body } : {}),
95104
...(comment.html_url ? { url: comment.html_url } : {}),
96-
observedAt: getObservedAt(comment.created_at),
105+
observedAt: getObservedAt(comment.updated_at ?? comment.created_at),
97106
},
98107
};
99108
}
@@ -108,6 +117,7 @@ export function buildPrReviewActivityNotificationInput(
108117
if ('review' in eventPayload) {
109118
const review = eventPayload.review;
110119
const authorLogin = review.user?.login;
120+
const body = getReviewBody(review.body);
111121

112122
if (!authorLogin) {
113123
return null;
@@ -128,6 +138,7 @@ export function buildPrReviewActivityNotificationInput(
128138
providerEventId: `github-review:${review.id}`,
129139
authorLogin,
130140
...getAutomatedAuthorMetadata(review.user),
141+
...(body ? { body } : {}),
131142
...(review.commit_id ? { reviewHeadSha: review.commit_id } : {}),
132143
batchId: `github-review:${review.id}`,
133144
reviewState: review.state,
@@ -144,6 +155,7 @@ export function buildPrReviewActivityNotificationInput(
144155

145156
const comment = eventPayload.comment;
146157
const authorLogin = comment.user?.login;
158+
const body = getReviewBody(comment.body);
147159

148160
if (!authorLogin) {
149161
return null;
@@ -167,6 +179,10 @@ export function buildPrReviewActivityNotificationInput(
167179
providerEventId: `github-review-comment:${comment.id}`,
168180
authorLogin,
169181
...getAutomatedAuthorMetadata(comment.user),
182+
...(comment.in_reply_to_id
183+
? { inReplyToId: String(comment.in_reply_to_id) }
184+
: {}),
185+
...(body ? { body } : {}),
170186
...(comment.commit_id ? { reviewHeadSha: comment.commit_id } : {}),
171187
...(comment.pull_request_review_id
172188
? { batchId: `github-review:${comment.pull_request_review_id}` }

packages/sdk/src/server/lib/pull-requests/__tests__/source-control-pull-request-reads.test.ts

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

0 commit comments

Comments
 (0)