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

Function createForkIfNeeded

pkg/cli/pr_command.go:142–171  ·  view source on GitHub ↗

createForkIfNeeded creates a fork of the target repository and returns the fork repo name

(targetOwner, targetRepo string, verbose bool)

Source from the content-addressed store, hash-verified

140
141// createForkIfNeeded creates a fork of the target repository and returns the fork repo name
142func createForkIfNeeded(targetOwner, targetRepo string, verbose bool) (forkOwner, forkRepo string, err error) {
143 // Get current user
144 output, err := workflow.RunGH("Fetching user info...", "api", "/user", "--jq", ".login")
145 if err != nil {
146 return "", "", fmt.Errorf("failed to get current user: %w", err)
147 }
148 currentUser := strings.TrimSpace(string(output))
149
150 // Check if fork already exists
151 forkRepoSpec := fmt.Sprintf("%s/%s", currentUser, targetRepo)
152 checkCmd := workflow.ExecGH("repo", "view", forkRepoSpec, "--json", "name")
153 if checkCmd.Run() == nil {
154 if verbose {
155 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Fork already exists: "+forkRepoSpec))
156 }
157 return currentUser, targetRepo, nil
158 }
159
160 // Create fork
161 _, err = workflow.RunGH(fmt.Sprintf("Creating fork of %s/%s...", targetOwner, targetRepo), "repo", "fork", fmt.Sprintf("%s/%s", targetOwner, targetRepo), "--clone=false")
162 if err != nil {
163 return "", "", fmt.Errorf("failed to create fork: %w", err)
164 }
165
166 if verbose {
167 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Successfully created fork: "+forkRepoSpec))
168 }
169
170 return currentUser, targetRepo, nil
171}
172
173// fetchPRInfo fetches detailed information about a pull request
174func fetchPRInfo(owner, repo string, prNumber int) (*PRInfo, error) {

Callers 1

createTransferPRFunction · 0.85

Calls 6

RunGHFunction · 0.92
ExecGHFunction · 0.92
FormatInfoMessageFunction · 0.92
FormatSuccessMessageFunction · 0.92
ErrorfMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected