Files
claude-code-action/src/create-prompt/types.ts
Vibhor Agrawal bd70a3ef2b fix: add support for pull_request_target event in GitHub Actions workflows (#579)
Add pull_request_target event support to enable Claude Code usage with forked
repositories while maintaining proper security boundaries. This resolves issues
with dependabot PRs and external contributions that require write permissions.

Changes:
- Add pull_request_target to supported GitHub events in context parsing
- Update type definitions to include PullRequestTargetEvent
- Modify IS_PR calculation to detect pull_request_target as PR context
- Add comprehensive test coverage for pull_request_target workflows
- Update documentation to reflect pull_request_target support

The pull_request_target event provides the same payload structure as
pull_request but runs with write permissions from the base repository,
making it ideal for secure automation of external contributions.

Fixes #347
2025-09-22 09:20:27 -07:00

114 lines
2.4 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;
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;
};