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

Function extractDispatchWorkflowNames

pkg/cli/dispatch.go:21–59  ·  view source on GitHub ↗

extractDispatchWorkflowNames extracts workflow names from the safe-outputs.dispatch-workflow frontmatter field. It handles both array and map forms of the configuration. Workflow names that contain GitHub Actions expression syntax (e.g. "${{") are skipped.

(content string)

Source from the content-addressed store, hash-verified

19// frontmatter field. It handles both array and map forms of the configuration.
20// Workflow names that contain GitHub Actions expression syntax (e.g. "${{") are skipped.
21func extractDispatchWorkflowNames(content string) []string {
22 result, err := parser.ExtractFrontmatterFromContent(content)
23 if err != nil || result.Frontmatter == nil {
24 return nil
25 }
26
27 safeOutputsMap, ok := result.Frontmatter["safe-outputs"].(map[string]any)
28 if !ok {
29 return nil
30 }
31
32 dispatchWorkflow, exists := safeOutputsMap["dispatch-workflow"]
33 if !exists {
34 return nil
35 }
36
37 var workflowNames []string
38
39 switch v := dispatchWorkflow.(type) {
40 case []any:
41 // Array format: dispatch-workflow: [name1, name2]
42 for _, item := range v {
43 if name, ok := item.(string); ok && !strings.Contains(name, "${{") {
44 workflowNames = append(workflowNames, name)
45 }
46 }
47 case map[string]any:
48 // Map format: dispatch-workflow: {workflows: [name1, name2]}
49 if workflowsArray, ok := v["workflows"].([]any); ok {
50 for _, item := range workflowsArray {
51 if name, ok := item.(string); ok && !strings.Contains(name, "${{") {
52 workflowNames = append(workflowNames, name)
53 }
54 }
55 }
56 }
57
58 return workflowNames
59}
60
61// fileDownloadFn is the type for a function that downloads a file from a GitHub repository.
62// It is used for dependency injection in fetchAndSaveRemoteDispatchWorkflows to allow tests

Calls 1