createForkIfNeeded creates a fork of the target repository and returns the fork repo name
(targetOwner, targetRepo string, verbose bool)
| 140 | |
| 141 | // createForkIfNeeded creates a fork of the target repository and returns the fork repo name |
| 142 | func 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 |
| 174 | func fetchPRInfo(owner, repo string, prNumber int) (*PRInfo, error) { |
no test coverage detected