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

Function BuildFromAllowedForks

pkg/workflow/expression_builder.go:383–421  ·  view source on GitHub ↗

BuildFromAllowedForks creates a condition to check if a pull request is from an allowed fork Supports glob patterns like "org/*" and exact matches like "org/repo"

(allowedForks []string)

Source from the content-addressed store, hash-verified

381// BuildFromAllowedForks creates a condition to check if a pull request is from an allowed fork
382// Supports glob patterns like "org/*" and exact matches like "org/repo"
383func BuildFromAllowedForks(allowedForks []string) ConditionNode {
384 if len(allowedForks) == 0 {
385 return BuildNotFromFork()
386 }
387
388 var conditions []ConditionNode
389
390 // Always allow PRs from the same repository
391 conditions = append(conditions, BuildNotFromFork())
392
393 for _, pattern := range allowedForks {
394 if strings.HasSuffix(pattern, "/*") {
395 // Glob pattern: org/* matches org/anything
396 prefix := strings.TrimSuffix(pattern, "*")
397 condition := &FunctionCallNode{
398 FunctionName: "startsWith",
399 Arguments: []ConditionNode{
400 BuildPropertyAccess("github.event.pull_request.head.repo.full_name"),
401 BuildStringLiteral(prefix),
402 },
403 }
404 conditions = append(conditions, condition)
405 } else {
406 // Exact match: org/repo
407 condition := BuildEquals(
408 BuildPropertyAccess("github.event.pull_request.head.repo.full_name"),
409 BuildStringLiteral(pattern),
410 )
411 conditions = append(conditions, condition)
412 }
413 }
414
415 if len(conditions) == 1 {
416 return conditions[0]
417 }
418
419 // Use DisjunctionNode to combine all conditions with OR
420 return &DisjunctionNode{Terms: conditions}
421}
422
423// BuildEventTypeEquals creates a condition to check if the event type equals a specific value
424func BuildEventTypeEquals(eventType string) *ComparisonNode {

Calls 4

BuildNotFromForkFunction · 0.85
BuildPropertyAccessFunction · 0.85
BuildStringLiteralFunction · 0.85
BuildEqualsFunction · 0.85