MCPcopy Create free account
hub / github.com/github/gh-aw / buildReactionLikeCondition

Function buildReactionLikeCondition

pkg/workflow/expression_builder.go:94–138  ·  view source on GitHub ↗
(includeIssues bool, includePullRequests bool, includeDiscussions bool, includeWorkflowDispatch bool)

Source from the content-addressed store, hash-verified

92}
93
94func buildReactionLikeCondition(includeIssues bool, includePullRequests bool, includeDiscussions bool, includeWorkflowDispatch bool) ConditionNode {
95 if !includeIssues && !includePullRequests && !includeDiscussions {
96 return BuildBooleanLiteral(false)
97 }
98
99 // Build a list of event types that should trigger reactions/status-comments using expression nodes.
100 var terms []ConditionNode
101
102 if includeIssues {
103 terms = append(terms, BuildEventTypeEquals("issues"))
104 terms = append(terms, BuildEventTypeEquals("issue_comment"))
105 }
106 if includePullRequests {
107 terms = append(terms, BuildEventTypeEquals("pull_request_review_comment"))
108 }
109 if includeDiscussions {
110 terms = append(terms, BuildEventTypeEquals("discussion"))
111 terms = append(terms, BuildEventTypeEquals("discussion_comment"))
112 }
113
114 // For pull_request events, we need to ensure it's not from a forked repository since
115 // forked pull requests have read-only permissions and cannot perform write operations
116 // like adding reactions or workflow run status-comments.
117 if includePullRequests {
118 pullRequestCondition := &AndNode{
119 Left: BuildEventTypeEquals("pull_request"),
120 Right: BuildNotFromFork(),
121 }
122 terms = append(terms, pullRequestCondition)
123 }
124
125 expressionBuilderLog.Printf("Created native disjunction with %d event type terms", len(terms))
126 nativeCondition := BuildDisjunction(false, terms...)
127
128 if !includeWorkflowDispatch {
129 return nativeCondition
130 }
131
132 dispatchSourceCondition := buildDispatchSourceEventCondition(includeIssues, includePullRequests, includeDiscussions)
133 dispatchCondition := BuildAnd(
134 BuildEventTypeEquals("workflow_dispatch"),
135 dispatchSourceCondition,
136 )
137 return BuildOr(nativeCondition, dispatchCondition)
138}
139
140func buildDispatchSourceEventCondition(includeIssues bool, includePullRequests bool, includeDiscussions bool) ConditionNode {
141 eventExpr := BuildPropertyAccess("fromJSON(github.event.inputs.aw_context || '{}').event_type")

Callers 2

Calls 8

BuildBooleanLiteralFunction · 0.85
BuildEventTypeEqualsFunction · 0.85
BuildNotFromForkFunction · 0.85
BuildDisjunctionFunction · 0.85
BuildAndFunction · 0.85
BuildOrFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected