extractSafeOutputLabels collects all unique labels referenced by workflow configuration that should exist in the repository for the workflow to function correctly. Scans: safe-outputs labels (create-issue/create-discussion/create-pull-request/add-labels) and on.label_command trigger labels.
(data *workflow.WorkflowData)
| 194 | // Scans: safe-outputs labels (create-issue/create-discussion/create-pull-request/add-labels) |
| 195 | // and on.label_command trigger labels. |
| 196 | func extractSafeOutputLabels(data *workflow.WorkflowData) []string { |
| 197 | if data == nil { |
| 198 | return nil |
| 199 | } |
| 200 | |
| 201 | seen := make(map[string]struct { |
| 202 | }) |
| 203 | var labels []string |
| 204 | |
| 205 | addLabel := func(label string) { |
| 206 | if label != "" && !setutil.Contains(seen, label) { |
| 207 | seen[label] = struct { |
| 208 | }{} |
| 209 | labels = append(labels, label) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | so := data.SafeOutputs |
| 214 | if so != nil { |
| 215 | if so.CreateIssues != nil { |
| 216 | for _, l := range so.CreateIssues.Labels { |
| 217 | addLabel(l) |
| 218 | } |
| 219 | for _, l := range so.CreateIssues.AllowedLabels { |
| 220 | addLabel(l) |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if so.CreateDiscussions != nil { |
| 225 | for _, l := range so.CreateDiscussions.Labels { |
| 226 | addLabel(l) |
| 227 | } |
| 228 | for _, l := range so.CreateDiscussions.AllowedLabels { |
| 229 | addLabel(l) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if so.CreatePullRequests != nil { |
| 234 | for _, l := range so.CreatePullRequests.Labels { |
| 235 | addLabel(l) |
| 236 | } |
| 237 | for _, l := range so.CreatePullRequests.AllowedLabels { |
| 238 | addLabel(l) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if so.AddLabels != nil { |
| 243 | for _, l := range so.AddLabels.Allowed { |
| 244 | addLabel(l) |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | for _, l := range data.LabelCommand { |
| 250 | addLabel(l) |
| 251 | } |
| 252 | |
| 253 | return labels |