IsWorkflowSpec checks if a path looks like a workflowspec (owner/repo/path[@ref]).
(path string)
| 122 | |
| 123 | // IsWorkflowSpec checks if a path looks like a workflowspec (owner/repo/path[@ref]). |
| 124 | func IsWorkflowSpec(path string) bool { |
| 125 | cleanPath := path |
| 126 | if idx := strings.Index(path, "#"); idx != -1 { |
| 127 | cleanPath = path[:idx] |
| 128 | } |
| 129 | if idx := strings.Index(cleanPath, "@"); idx != -1 { |
| 130 | cleanPath = cleanPath[:idx] |
| 131 | } |
| 132 | parts := strings.Split(cleanPath, "/") |
| 133 | if len(parts) < 3 { |
| 134 | return false |
| 135 | } |
| 136 | // Preserve legacy behavior expected by parser tests: URL-like paths are |
| 137 | // currently treated as workflowspecs because downstream parsing supports |
| 138 | // repository/path extraction from slash-delimited remote references. |
| 139 | if strings.Contains(cleanPath, "://") { |
| 140 | return true |
| 141 | } |
| 142 | if strings.HasPrefix(cleanPath, ".") { |
| 143 | return false |
| 144 | } |
| 145 | if strings.HasPrefix(cleanPath, "shared/") { |
| 146 | return false |
| 147 | } |
| 148 | if strings.HasPrefix(cleanPath, "/") { |
| 149 | return false |
| 150 | } |
| 151 | // Safe indexing: len(parts) >= 3 is guaranteed above. |
| 152 | owner := parts[0] |
| 153 | repo := parts[1] |
| 154 | if owner == "" || repo == "" { |
| 155 | return false |
| 156 | } |
| 157 | return true |
| 158 | } |
| 159 | |
| 160 | func isWorkflowSpec(path string) bool { |
| 161 | return IsWorkflowSpec(path) |