feat: optional -R when in a git repo

This commit is contained in:
Romain Bertrand 2025-12-08 10:24:49 +01:00
parent a2d3858462
commit aa2be8587a
4 changed files with 258 additions and 16 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"
"codeberg.org/romaintb/fgj/internal/api"
"codeberg.org/romaintb/fgj/internal/config"
"codeberg.org/romaintb/fgj/internal/git"
)
var prCmd = &cobra.Command{
@ -264,14 +265,20 @@ func runPRMerge(cmd *cobra.Command, args []string) error {
}
func parseRepo(repo string) (string, string, error) {
if repo == "" {
return "", "", fmt.Errorf("repository flag is required (use -R owner/name)")
// If repo flag is provided, use it
if repo != "" {
parts := strings.Split(repo, "/")
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid repository format: %s (expected: owner/name)", repo)
}
return parts[0], parts[1], nil
}
parts := strings.Split(repo, "/")
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid repository format: %s (expected: owner/name)", repo)
// Try to auto-detect from git
owner, name, err := git.DetectRepo()
if err != nil {
return "", "", fmt.Errorf("repository flag is required (use -R owner/name) or run from a git repository: %w", err)
}
return parts[0], parts[1], nil
return owner, name, nil
}