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

Function buildCheckoutRepository

pkg/workflow/push_to_pull_request_branch.go:48–84  ·  view source on GitHub ↗

buildCheckoutRepository generates a checkout step with optional target repository and custom token Parameters: - steps: existing steps to append to - c: compiler instance for trialMode checks - targetRepoSlug: optional target repository (e.g., "org/repo") for cross-repo operations If empty, checks o

(steps []string, c *Compiler, targetRepoSlug string, customToken string)

Source from the content-addressed store, hash-verified

46// - customToken: optional custom GitHub token for authentication
47// If empty, uses default GH_AW_GITHUB_TOKEN || GITHUB_TOKEN fallback
48func buildCheckoutRepository(steps []string, c *Compiler, targetRepoSlug string, customToken string) []string {
49 pushToPullRequestBranchLog.Printf("Building checkout repository step: targetRepo=%s, trialMode=%t", targetRepoSlug, c.trialMode)
50
51 steps = append(steps, " - name: Checkout repository\n")
52 steps = append(steps, fmt.Sprintf(" uses: %s\n", getActionPin("actions/checkout")))
53 steps = append(steps, " with:\n")
54
55 // Determine which repository to check out
56 // Priority: targetRepoSlug > trialLogicalRepoSlug > default (source repo)
57 effectiveTargetRepo := targetRepoSlug
58 if c.trialMode && c.trialLogicalRepoSlug != "" {
59 effectiveTargetRepo = c.trialLogicalRepoSlug
60 pushToPullRequestBranchLog.Printf("Trial mode: using logical repo slug: %s", effectiveTargetRepo)
61 }
62
63 // Set repository parameter if we're checking out a different repo
64 if effectiveTargetRepo != "" {
65 pushToPullRequestBranchLog.Printf("Checking out non-default repository: %s", effectiveTargetRepo)
66 steps = append(steps, fmt.Sprintf(" repository: %s\n", effectiveTargetRepo))
67 }
68
69 steps = append(steps, " persist-credentials: false\n")
70 steps = append(steps, " fetch-depth: 0\n")
71
72 // Add token for trial mode or when checking out a different repository
73 if c.trialMode || targetRepoSlug != "" {
74 // Use custom token if provided, otherwise use default fallback
75 token := customToken
76 if token == "" {
77 token = "${{ secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}"
78 }
79 pushToPullRequestBranchLog.Printf("Adding authentication token to checkout step (customToken=%t)", customToken != "")
80 steps = append(steps, fmt.Sprintf(" token: %s\n", token))
81 }
82
83 return steps
84}
85
86// parsePushToPullRequestBranchConfig handles push-to-pull-request-branch configuration
87func (c *Compiler) parsePushToPullRequestBranchConfig(outputMap map[string]any) *PushToPullRequestBranchConfig {

Callers 1

buildUploadAssetsJobMethod · 0.85

Calls 2

getActionPinFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected