Files
claude-code-action/src/create-prompt/types.ts
Philippe Laflamme 2acd1f7011 fix: commentBody may be null (#706)
* fix: `commentBody` may be `null`

This handles the cases where `pull_request_review` events have no
comments (`commentBody` field is `null`). In those cases, the `null`
value is converted to the empty string.

The issue was testing `!commentBody` which was triggerring on empty
strings as well. This guard was removed (which is the fix), but for
clarity, the `commentBody` field was also made optional to make it clear
that the comment may be missing.

* fix: bun run format
2025-12-03 17:34:31 -08:00

114 lines
2.5 KiB
TypeScript

import type { GitHubContext } from "../github/context";
export type CommonFields = {
repository: string;
claudeCommentId: string;
triggerPhrase: string;
triggerUsername?: string;
prompt?: string;
claudeBranch?: string;
};
type PullRequestReviewCommentEvent = {
eventName: "pull_request_review_comment";
isPR: true;
prNumber: string;
commentId?: string; // May be present for review comments
commentBody: string;
claudeBranch?: string;
baseBranch?: string;
};
type PullRequestReviewEvent = {
eventName: "pull_request_review";
isPR: true;
prNumber: string;
commentBody?: string; // May be absent for approvals without comments
claudeBranch?: string;
baseBranch?: string;
};
type IssueCommentEvent = {
eventName: "issue_comment";
commentId: string;
issueNumber: string;
isPR: false;
baseBranch: string;
claudeBranch: string;
commentBody: string;
};
// Not actually a real github event, since issue comments and PR coments are both sent as issue_comment
type PullRequestCommentEvent = {
eventName: "issue_comment";
commentId: string;
prNumber: string;
isPR: true;
commentBody: string;
claudeBranch?: string;
baseBranch?: string;
};
type IssueOpenedEvent = {
eventName: "issues";
eventAction: "opened";
isPR: false;
issueNumber: string;
baseBranch: string;
claudeBranch: string;
};
type IssueAssignedEvent = {
eventName: "issues";
eventAction: "assigned";
isPR: false;
issueNumber: string;
baseBranch: string;
claudeBranch: string;
assigneeTrigger?: string;
};
type IssueLabeledEvent = {
eventName: "issues";
eventAction: "labeled";
isPR: false;
issueNumber: string;
baseBranch: string;
claudeBranch: string;
labelTrigger: string;
};
type PullRequestBaseEvent = {
eventAction?: string; // opened, synchronize, etc.
isPR: true;
prNumber: string;
claudeBranch?: string;
baseBranch?: string;
};
type PullRequestEvent = PullRequestBaseEvent & {
eventName: "pull_request";
};
type PullRequestTargetEvent = PullRequestBaseEvent & {
eventName: "pull_request_target";
};
// Union type for all possible event types
export type EventData =
| PullRequestReviewCommentEvent
| PullRequestReviewEvent
| PullRequestCommentEvent
| IssueCommentEvent
| IssueOpenedEvent
| IssueAssignedEvent
| IssueLabeledEvent
| PullRequestEvent
| PullRequestTargetEvent;
// Combined type with separate eventData field
export type PreparedContext = CommonFields & {
eventData: EventData;
githubContext?: GitHubContext;
};