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

Function buildCheckoutsPromptContent

pkg/workflow/checkout_config_parser.go:269–350  ·  view source on GitHub ↗

buildCheckoutsPromptContent returns a markdown bullet list describing all user-configured checkouts for inclusion in the GitHub context prompt. Returns an empty string when no checkouts are configured. Each checkout is shown with its full absolute path relative to $GITHUB_WORKSPACE. The root checko

(checkouts []*CheckoutConfig)

Source from the content-addressed store, hash-verified

267// configured; callers must ensure these expressions are processed by an ExpressionExtractor
268// so the placeholder substitution step can resolve them at runtime.
269func buildCheckoutsPromptContent(checkouts []*CheckoutConfig) string {
270 if len(checkouts) == 0 {
271 checkoutManagerLog.Print("buildCheckoutsPromptContent: no checkouts configured, returning empty content")
272 return ""
273 }
274 checkoutManagerLog.Printf("Building checkouts prompt content for %d checkout(s)", len(checkouts))
275
276 var sb strings.Builder
277 sb.WriteString("- **checkouts**: The following repositories have been checked out and are available in the workspace:\n")
278
279 for _, cfg := range checkouts {
280 if cfg == nil {
281 continue
282 }
283
284 // Build the full absolute path using $GITHUB_WORKSPACE as root.
285 // Normalize the path: strip "./" prefix; bare "." and "" both mean root.
286 relPath := strings.TrimPrefix(cfg.Path, "./")
287 if relPath == "." {
288 relPath = ""
289 }
290 isRoot := relPath == ""
291 absPath := "$GITHUB_WORKSPACE"
292 if !isRoot {
293 absPath += "/" + relPath
294 }
295
296 // Determine repo: use configured value or fall back to the triggering repository expression.
297 // For wiki checkouts, append the ".wiki" suffix so the prompt accurately reflects what was checked out.
298 repo := cfg.Repository
299 if repo == "" {
300 repo = "${{ github.repository }}"
301 }
302 if cfg.Wiki {
303 if !strings.HasSuffix(repo, ".wiki") {
304 repo += ".wiki"
305 }
306 }
307
308 line := fmt.Sprintf(" - repo `%s` → `%s`", repo, absPath)
309 if isRoot {
310 line += " (cwd)"
311 }
312 if cfg.Wiki {
313 line += " (wiki)"
314 }
315 if cfg.Current {
316 line += " (**current** - this is the repository you are working on; use this as the target for all GitHub operations unless otherwise specified)"
317 }
318
319 // Annotate fetch-depth so the agent knows how much history is available
320 if cfg.FetchDepth != nil && *cfg.FetchDepth == 0 {
321 line += " [full history, all branches available as remote-tracking refs]"
322 } else if cfg.FetchDepth != nil {
323 line += fmt.Sprintf(" [shallow clone, fetch-depth=%d]", *cfg.FetchDepth)
324 } else {
325 line += " [shallow clone, fetch-depth=1 (default)]"
326 }

Callers 3

collectPromptSectionsMethod · 0.85
TestWikiCheckoutFunction · 0.85

Calls 3

PrintMethod · 0.80
PrintfMethod · 0.45
StringMethod · 0.45

Tested by 2

TestWikiCheckoutFunction · 0.68