diff --git a/src/formatters/webhook-events.ts b/src/formatters/webhook-events.ts index 1be525e..ffce9e8 100644 --- a/src/formatters/webhook-events.ts +++ b/src/formatters/webhook-events.ts @@ -10,6 +10,7 @@ import type { IssueCommentPayload, IssuesPayload, PullRequestPayload, + PullRequestReviewCommentPayload, PullRequestReviewPayload, PushPayload, ReleasePayload, @@ -179,6 +180,26 @@ export function formatPullRequestReview( return ""; } +export function formatPullRequestReviewComment( + payload: PullRequestReviewCommentPayload +): string { + const { action, comment, pull_request, repository } = payload; + + if (action === "created") { + const shortComment = comment.body.split("\n")[0].substring(0, 100); + + return ( + `💬 **Review Comment on PR #${pull_request.number}**\n` + + `**${repository.full_name}**\n\n` + + `"${shortComment}${comment.body.length > 100 ? "..." : ""}"\n` + + `👤 ${comment.user?.login || "unknown"}\n` + + `🔗 ${comment.html_url}` + ); + } + + return ""; +} + export function formatFork(payload: ForkPayload): string { const { forkee, repository, sender } = payload; diff --git a/src/github-app/event-processor.ts b/src/github-app/event-processor.ts index 05c82c0..73ca18c 100644 --- a/src/github-app/event-processor.ts +++ b/src/github-app/event-processor.ts @@ -9,6 +9,7 @@ import { formatIssueComment, formatPullRequest, formatPullRequestReview, + formatPullRequestReviewComment, formatPush, formatRelease, formatWatch, @@ -26,6 +27,7 @@ import type { IssueCommentPayload, IssuesPayload, PullRequestPayload, + PullRequestReviewCommentPayload, PullRequestReviewPayload, PushPayload, ReleasePayload, @@ -232,6 +234,22 @@ export class EventProcessor { ); } + /** + * Process a pull request review comment webhook event + * Branch filter applies to the PR's base branch (merge target) + */ + async onPullRequestReviewComment(event: PullRequestReviewCommentPayload) { + const { pull_request, repository } = event; + const baseBranch = pull_request.base.ref; + await this.processEvent( + event, + "review_comments", + formatPullRequestReviewComment, + `PR review comment event: ${event.action} - ${repository.full_name}#${pull_request.number}`, + { branch: baseBranch } + ); + } + /** * Process branch create/delete events * Branch filter applies to the branch being created/deleted diff --git a/src/index.ts b/src/index.ts index 1dfb9e1..01c9200 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,6 +103,10 @@ githubApp.webhooks.on("pull_request_review", async ({ payload }) => { await eventProcessor.onPullRequestReview(payload); }); +githubApp.webhooks.on("pull_request_review_comment", async ({ payload }) => { + await eventProcessor.onPullRequestReviewComment(payload); +}); + githubApp.webhooks.on("create", async ({ payload }) => { await eventProcessor.onBranchEvent(payload, "create"); }); diff --git a/src/types/webhooks.ts b/src/types/webhooks.ts index d6b3968..01a994c 100644 --- a/src/types/webhooks.ts +++ b/src/types/webhooks.ts @@ -18,6 +18,8 @@ export type ReleasePayload = WebhookPayload<"release">; export type WorkflowRunPayload = WebhookPayload<"workflow_run">; export type IssueCommentPayload = WebhookPayload<"issue_comment">; export type PullRequestReviewPayload = WebhookPayload<"pull_request_review">; +export type PullRequestReviewCommentPayload = + WebhookPayload<"pull_request_review_comment">; export type InstallationPayload = WebhookPayload<"installation">; export type InstallationRepositoriesPayload = WebhookPayload<"installation_repositories">;