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

Function injectCheckoutMapping

pkg/workflow/safe_outputs_patch_workspace.go:78–117  ·  view source on GitHub ↗

injectCheckoutMapping adds a checkout_mapping to handler config for create_pull_request and push_to_pull_request_branch when target-repo is "*" (wildcard). The mapping tells the JS handler where each repository is checked out on disk, enabling it to operate on multiple repositories without dynamic g

(handlerName string, handlerCfg map[string]any, data *WorkflowData)

Source from the content-addressed store, hash-verified

76// The mapping is keyed by lowercase repo slug and values are relative paths within
77// GITHUB_WORKSPACE for cross-repo checkouts (entries with repository + path).
78func injectCheckoutMapping(handlerName string, handlerCfg map[string]any, data *WorkflowData) {
79 if handlerCfg == nil || data == nil {
80 return
81 }
82 if handlerName != "create_pull_request" && handlerName != "push_to_pull_request_branch" {
83 return
84 }
85
86 // Only inject when target-repo is wildcard
87 targetRepo := ""
88 if value, ok := handlerCfg["target-repo"].(string); ok {
89 targetRepo = strings.TrimSpace(value)
90 }
91 if targetRepo != "*" {
92 return
93 }
94
95 // Build the checkout mapping from checkout: configs
96 mapping := make(map[string]string)
97 for _, cfg := range data.CheckoutConfigs {
98 if cfg == nil || cfg.Repository == "" || cfg.Path == "" || cfg.Wiki {
99 continue
100 }
101 // Normalize repo slug to lowercase for consistent lookup
102 repoKey := strings.ToLower(strings.TrimSpace(cfg.Repository))
103 normalizedPath := normalizeCurrentCheckoutPatchPath(cfg.Path)
104 if normalizedPath != "" {
105 mapping[repoKey] = normalizedPath
106 }
107 }
108
109 // Only inject if there are actual cross-repo checkouts configured
110 if len(mapping) == 0 {
111 patchWorkspaceLog.Printf("No checkout mapping entries for handler=%s (wildcard target-repo but no cross-repo checkout: configs)", handlerName)
112 return
113 }
114
115 handlerCfg["checkout_mapping"] = mapping
116 patchWorkspaceLog.Printf("Injected checkout_mapping for handler=%s: %d entries", handlerName, len(mapping))
117}

Calls 3

ToLowerMethod · 0.80
PrintfMethod · 0.45