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
This commit is contained in:
Vibhor Agrawal
2025-09-22 21:50:27 +05:30
committed by GitHub
parent f4954b5256
commit bd70a3ef2b
6 changed files with 520 additions and 6 deletions

View File

@@ -384,6 +384,7 @@ export function getEventTypeAndContext(envVars: PreparedContext): {
};
case "pull_request":
case "pull_request_target":
return {
eventType: "PULL_REQUEST",
triggerContext: eventData.eventAction

View File

@@ -78,8 +78,7 @@ type IssueLabeledEvent = {
labelTrigger: string;
};
type PullRequestEvent = {
eventName: "pull_request";
type PullRequestBaseEvent = {
eventAction?: string; // opened, synchronize, etc.
isPR: true;
prNumber: string;
@@ -87,6 +86,14 @@ type PullRequestEvent = {
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
@@ -96,7 +103,8 @@ export type EventData =
| IssueOpenedEvent
| IssueAssignedEvent
| IssueLabeledEvent
| PullRequestEvent;
| PullRequestEvent
| PullRequestTargetEvent;
// Combined type with separate eventData field
export type PreparedContext = CommonFields & {

View File

@@ -174,7 +174,8 @@ export function parseGitHubContext(): GitHubContext {
isPR: Boolean(payload.issue.pull_request),
};
}
case "pull_request": {
case "pull_request":
case "pull_request_target": {
const payload = context.payload as PullRequestEvent;
return {
...commonFields,