checkGitRepository verifies we're in a git repo and gets org/repo info This version has special interactive handling to prompt user for repo if not found
()
| 19 | // checkGitRepository verifies we're in a git repo and gets org/repo info |
| 20 | // This version has special interactive handling to prompt user for repo if not found |
| 21 | func (c *AddInteractiveConfig) checkGitRepository() error { |
| 22 | addInteractiveLog.Print("Checking git repository status") |
| 23 | |
| 24 | // Check if we're in a git repository |
| 25 | if !isGitRepo() { |
| 26 | fmt.Fprintln(os.Stderr, console.FormatErrorMessage("Not in a git repository.")) |
| 27 | fmt.Fprintln(os.Stderr, "") |
| 28 | fmt.Fprintln(os.Stderr, "Please navigate to a git repository or initialize one with:") |
| 29 | fmt.Fprintln(os.Stderr, "") |
| 30 | fmt.Fprintln(os.Stderr, console.FormatCommandMessage(" git init")) |
| 31 | fmt.Fprintln(os.Stderr, "") |
| 32 | return errors.New("not in a git repository") |
| 33 | } |
| 34 | |
| 35 | // Try to get the repository slug |
| 36 | repoSlug, err := GetCurrentRepoSlug() |
| 37 | if err != nil { |
| 38 | addInteractiveLog.Printf("Could not determine repository automatically: %v", err) |
| 39 | |
| 40 | // Ask the user for the repository (interactive-only feature) |
| 41 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Could not determine the repository automatically.")) |
| 42 | fmt.Fprintln(os.Stderr, "") |
| 43 | |
| 44 | var userRepo string |
| 45 | form := huh.NewForm( |
| 46 | huh.NewGroup( |
| 47 | huh.NewInput(). |
| 48 | Title("Enter the target repository (owner/repo):"). |
| 49 | Description("For example: myorg/myrepo"). |
| 50 | Value(&userRepo). |
| 51 | Validate(func(s string) error { |
| 52 | parts := strings.Split(s, "/") |
| 53 | if len(parts) != 2 || parts[0] == "" || parts[1] == "" { |
| 54 | return errors.New("please enter in format 'owner/repo'") |
| 55 | } |
| 56 | return nil |
| 57 | }), |
| 58 | ), |
| 59 | ).WithTheme(styles.HuhTheme).WithAccessible(console.IsAccessibleMode()) |
| 60 | |
| 61 | if err := form.RunWithContext(c.Ctx); err != nil { |
| 62 | return fmt.Errorf("failed to get repository info: %w", err) |
| 63 | } |
| 64 | |
| 65 | c.RepoOverride = userRepo |
| 66 | repoSlug = userRepo |
| 67 | } else { |
| 68 | c.RepoOverride = repoSlug |
| 69 | } |
| 70 | |
| 71 | fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Target repository: "+repoSlug)) |
| 72 | addInteractiveLog.Printf("Target repository: %s", repoSlug) |
| 73 | |
| 74 | // Check if repository is public or private |
| 75 | c.isPublicRepo = checkRepoVisibilityShared(c.RepoOverride) |
| 76 | |
| 77 | return nil |
| 78 | } |
no test coverage detected