Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/formatters/webhook-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
IssueCommentPayload,
IssuesPayload,
PullRequestPayload,
PullRequestReviewCommentPayload,
PullRequestReviewPayload,
PushPayload,
ReleasePayload,
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 18 additions & 0 deletions src/github-app/event-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
formatIssueComment,
formatPullRequest,
formatPullRequestReview,
formatPullRequestReviewComment,
formatPush,
formatRelease,
formatWatch,
Expand All @@ -26,6 +27,7 @@ import type {
IssueCommentPayload,
IssuesPayload,
PullRequestPayload,
PullRequestReviewCommentPayload,
PullRequestReviewPayload,
PushPayload,
ReleasePayload,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down
2 changes: 2 additions & 0 deletions src/types/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down