feat: optional -R when in a git repo
This commit is contained in:
parent
a2d3858462
commit
aa2be8587a
4 changed files with 258 additions and 16 deletions
19
cmd/pr.go
19
cmd/pr.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue