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

Function transferPR

pkg/cli/pr_command.go:533–757  ·  view source on GitHub ↗

transferPR is the main function that orchestrates the PR transfer

(prURL, targetRepo string, verbose bool)

Source from the content-addressed store, hash-verified

531
532// transferPR is the main function that orchestrates the PR transfer
533func transferPR(prURL, targetRepo string, verbose bool) error {
534 prLog.Printf("Starting PR transfer: url=%s, targetRepo=%s", prURL, targetRepo)
535
536 if verbose {
537 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Starting PR transfer..."))
538 }
539
540 // Parse PR URL
541 sourceOwner, sourceRepoName, prNumber, err := parser.ParsePRURL(prURL)
542 if err != nil {
543 prLog.Printf("Failed to parse PR URL: %s", err)
544 return err
545 }
546 prLog.Printf("Parsed source: %s/%s#%d", sourceOwner, sourceRepoName, prNumber)
547
548 if verbose {
549 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Source: %s/%s PR #%d", sourceOwner, sourceRepoName, prNumber)))
550 }
551
552 // Determine target repository
553 var targetOwner, targetRepoName string
554 if targetRepo != "" {
555 repoSpec, err := parseRepoSpec(targetRepo)
556 if err != nil {
557 return fmt.Errorf("invalid target repository format: %w", err)
558 }
559 parts := strings.SplitN(repoSpec.RepoSlug, "/", 2)
560 if len(parts) != 2 {
561 return errors.New("invalid target repository format, expected: owner/repo")
562 }
563 targetOwner, targetRepoName = parts[0], parts[1]
564 } else {
565 // Use current repository as target
566 slug, err := GetCurrentRepoSlug()
567 if err != nil {
568 return fmt.Errorf("failed to determine target repository: %w", err)
569 }
570 targetOwner, targetRepoName, err = repoutil.SplitRepoSlug(slug)
571 if err != nil {
572 return fmt.Errorf("failed to parse target repository: %w", err)
573 }
574 }
575
576 prLog.Printf("Determined target repository: %s/%s", targetOwner, targetRepoName)
577
578 if verbose {
579 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Target: %s/%s", targetOwner, targetRepoName)))
580 }
581
582 // Check if source and target are the same
583 if sourceOwner == targetOwner && sourceRepoName == targetRepoName {
584 prLog.Print("Source and target repositories are the same - aborting")
585 return errors.New("source and target repositories cannot be the same")
586 }
587
588 // Ensure we're in the correct git repository
589 var workingDir string
590 var needsCleanup bool

Callers 1

NewPRTransferSubcommandFunction · 0.85

Calls 15

FormatInfoMessageFunction · 0.92
ParsePRURLFunction · 0.92
SplitRepoSlugFunction · 0.92
ExecGHFunction · 0.92
FormatWarningMessageFunction · 0.92
parseRepoSpecFunction · 0.85
GetCurrentRepoSlugFunction · 0.85
isGitRepoFunction · 0.85
fetchPRInfoFunction · 0.85
createPatchFromPRFunction · 0.85
applyPatchToRepoFunction · 0.85
createTransferPRFunction · 0.85

Tested by

no test coverage detected