buildCommentAuthorAssociationCondition returns a ConditionNode that passes for non-comment events and for comment events whose author is an OWNER, MEMBER, or COLLABORATOR. Actors listed in bots (from on.bots) are also exempted so that bot/app-triggered workflows continue to work even though bots rar
(bots []string)
| 177 | // workflows) while remaining transparent to non-comment events such as push or schedule, |
| 178 | // and preserves existing on.bots allow-list behaviour. |
| 179 | func buildCommentAuthorAssociationCondition(bots []string) ConditionNode { |
| 180 | notIssueComment := BuildNotEquals( |
| 181 | BuildPropertyAccess("github.event_name"), |
| 182 | BuildStringLiteral("issue_comment"), |
| 183 | ) |
| 184 | notPRReviewComment := BuildNotEquals( |
| 185 | BuildPropertyAccess("github.event_name"), |
| 186 | BuildStringLiteral("pull_request_review_comment"), |
| 187 | ) |
| 188 | notCommentEvent := BuildAnd(notIssueComment, notPRReviewComment) |
| 189 | |
| 190 | authorizedAssoc := BuildFunctionCall( |
| 191 | "contains", |
| 192 | BuildFunctionCall("fromJSON", BuildStringLiteral(`["OWNER","MEMBER","COLLABORATOR"]`)), |
| 193 | BuildPropertyAccess("github.event.comment.author_association"), |
| 194 | ) |
| 195 | |
| 196 | result := BuildOr(notCommentEvent, authorizedAssoc) |
| 197 | if len(bots) > 0 { |
| 198 | botTerms := make([]ConditionNode, len(bots)) |
| 199 | for i, bot := range bots { |
| 200 | botTerms[i] = BuildEquals( |
| 201 | BuildPropertyAccess("github.actor"), |
| 202 | BuildStringLiteral(bot), |
| 203 | ) |
| 204 | } |
| 205 | result = BuildOr(result, BuildDisjunction(false, botTerms...)) |
| 206 | } |
| 207 | |
| 208 | return result |
| 209 | } |
| 210 | |
| 211 | func buildAuthorAssociationNodeForEvent(eventName string) ConditionNode { |
| 212 | switch eventName { |
no test coverage detected