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
2 changes: 1 addition & 1 deletion .github/workflows/test-claude-add-issue-comment.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-claude-add-issue-labels.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-claude-command.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-claude-mcp.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-claude-update-issue.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-codex-add-issue-comment.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-codex-add-issue-labels.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-codex-command.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-codex-mcp.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/test-codex-update-issue.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion pkg/workflow/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,18 @@ func buildReactionCondition() ConditionNode {
var terms []ConditionNode

terms = append(terms, BuildEventTypeEquals("issues"))
terms = append(terms, BuildEventTypeEquals("pull_request"))
terms = append(terms, BuildEventTypeEquals("issue_comment"))
terms = append(terms, BuildEventTypeEquals("pull_request_comment"))
terms = append(terms, BuildEventTypeEquals("pull_request_review_comment"))

// For pull_request events, we need to ensure it's not from a forked repository
// since forked repositories have read-only permissions and cannot add reactions
pullRequestCondition := &AndNode{
Left: BuildEventTypeEquals("pull_request"),
Right: BuildNotFromFork(),
}
terms = append(terms, pullRequestCondition)

// Use DisjunctionNode to avoid deep nesting
return &DisjunctionNode{Terms: terms}
}
Expand Down Expand Up @@ -285,6 +292,15 @@ func BuildActionEquals(action string) *ComparisonNode {
)
}

// BuildNotFromFork creates a condition to check that a pull request is not from a forked repository
// This prevents the job from running on forked PRs where write permissions are not available
func BuildNotFromFork() *ComparisonNode {
return BuildEquals(
BuildPropertyAccess("github.event.pull_request.head.repo.full_name"),
BuildPropertyAccess("github.repository"),
)
}

// BuildEventTypeEquals creates a condition to check if the event type equals a specific value
func BuildEventTypeEquals(eventType string) *ComparisonNode {
return BuildEquals(
Expand Down
22 changes: 17 additions & 5 deletions pkg/workflow/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ func TestBuildReactionCondition(t *testing.T) {
// The result should be a flat OR chain without deep nesting
expectedSubstrings := []string{
"github.event_name == 'issues'",
"github.event_name == 'pull_request'",
"github.event_name == 'issue_comment'",
"github.event_name == 'pull_request_comment'",
"github.event_name == 'pull_request_review_comment'",
"github.event_name == 'pull_request'",
"github.event.pull_request.head.repo.full_name == github.repository",
"&&",
"||",
}

Expand All @@ -159,10 +161,10 @@ func TestBuildReactionCondition(t *testing.T) {
}
}

// With DisjunctionNode, the output should be flat without extra parentheses at the start/end
expectedOutput := "github.event_name == 'issues' || github.event_name == 'pull_request' || github.event_name == 'issue_comment' || github.event_name == 'pull_request_comment' || github.event_name == 'pull_request_review_comment'"
if rendered != expectedOutput {
t.Errorf("Expected exact output '%s', but got: %s", expectedOutput, rendered)
// With the fork check, the pull_request condition should be more complex
// It should contain both the event name check and the not-from-fork check
if !strings.Contains(rendered, "(github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name == github.repository)") {
t.Errorf("Expected pull_request condition to include fork check, but got: %s", rendered)
}
}

Expand Down Expand Up @@ -949,3 +951,13 @@ func TestHelperFunctionsForMultiline(t *testing.T) {
}
})
}

func TestBuildNotFromFork(t *testing.T) {
result := BuildNotFromFork()
rendered := result.Render()

expected := "github.event.pull_request.head.repo.full_name == github.repository"
if rendered != expected {
t.Errorf("Expected '%s', got '%s'", expected, rendered)
}
}