applyPullRequestDraftFilter applies draft filter conditions for pull_request triggers
(data *WorkflowData, frontmatter map[string]any)
| 10 | |
| 11 | // applyPullRequestDraftFilter applies draft filter conditions for pull_request triggers |
| 12 | func (c *Compiler) applyPullRequestDraftFilter(data *WorkflowData, frontmatter map[string]any) { |
| 13 | filtersLog.Print("Applying pull request draft filter") |
| 14 | |
| 15 | // Use cached On field from ParsedFrontmatter if available, otherwise fall back to map access |
| 16 | var onValue any |
| 17 | var hasOn bool |
| 18 | if data.ParsedFrontmatter != nil && data.ParsedFrontmatter.On != nil { |
| 19 | onValue = data.ParsedFrontmatter.On |
| 20 | hasOn = true |
| 21 | } else { |
| 22 | onValue, hasOn = frontmatter["on"] |
| 23 | } |
| 24 | |
| 25 | // Check if there's an "on" section in the frontmatter |
| 26 | if !hasOn { |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | // Check if "on" is an object (not a string) |
| 31 | onMap, isOnMap := onValue.(map[string]any) |
| 32 | if !isOnMap { |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | // Check if there's a pull_request section |
| 37 | prValue, hasPR := onMap["pull_request"] |
| 38 | if !hasPR { |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | // Check if pull_request is an object with draft settings |
| 43 | prMap, isPRMap := prValue.(map[string]any) |
| 44 | if !isPRMap { |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | // Check if draft is specified |
| 49 | draftValue, hasDraft := prMap["draft"] |
| 50 | if !hasDraft { |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | // Check if draft is a boolean |
| 55 | draftBool, isDraftBool := draftValue.(bool) |
| 56 | if !isDraftBool { |
| 57 | // If draft is not a boolean, don't add filter |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | filtersLog.Printf("Found draft filter configuration: draft=%v", draftBool) |
| 62 | |
| 63 | // Generate conditional logic based on draft value using expression nodes |
| 64 | var draftCondition ConditionNode |
| 65 | if draftBool { |
| 66 | // draft: true - include only draft PRs |
| 67 | // The condition should be true for non-pull_request events or for draft pull_requests |
| 68 | notPullRequestEvent := BuildNotEquals( |
| 69 | BuildPropertyAccess("github.event_name"), |
no test coverage detected